1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-22 15:38:11 +00:00

trezor.ui: rework HoldToConfirmDialog

Fixes flickering while idle.
This commit is contained in:
Jan Pochyla 2017-06-20 12:02:38 +02:00
parent c94e02b0eb
commit bcd94ecbc1
2 changed files with 30 additions and 29 deletions

View File

@ -44,20 +44,20 @@ class ConfirmDialog(Widget):
return await loop.Wait((super().__iter__(), self.content))
_STARTED = const(-1)
_STOPPED = const(-2)
class HoldToConfirmDialog(Widget):
def __init__(self, content=None, hold='Hold to confirm', *args, **kwargs):
def __init__(self, content, hold='Hold to confirm', *args, **kwargs):
self.content = content
self.button = Button((0, 240 - 48, 240, 48), hold,
normal_style=CONFIRM_BUTTON,
active_style=CONFIRM_BUTTON_ACTIVE)
self.content = content
self.loader = Loader(*args, **kwargs)
def render(self):
if self.loader.is_active():
self.loader.render()
elif self.content is not None:
self.content.render()
self.button.render()
def touch(self, event, pos):
@ -65,28 +65,22 @@ class HoldToConfirmDialog(Widget):
was_started = button.state & BTN_STARTED
button.touch(event, pos)
is_started = button.state & BTN_STARTED
if is_started:
if not was_started:
if is_started and not was_started:
self.loader.start()
else:
if was_started:
return _STARTED
if was_started and not is_started:
if self.loader.stop():
return CONFIRMED
if self.content is not None:
return self.content.touch(event, pos)
else:
return _STOPPED
async def __iter__(self):
return await loop.Wait((self._render_loop(), self._event_loop()))
def _render_loop(self):
RENDER_DELAY = const(1000000 // 60)
while True:
self.render()
yield loop.Sleep(RENDER_DELAY)
def _event_loop(self):
while True:
event, *pos = yield loop.Select(loop.TOUCH)
result = self.touch(event, pos)
if result is not None:
result = None
while result is None or result < 0: # _STARTED or _STOPPED
if self.loader.is_active():
content_loop = self.loader
else:
content_loop = self.content
confirm_loop = super().__iter__() # default loop (render on touch)
result = await loop.wait((content_loop, confirm_loop))
return result

View File

@ -1,5 +1,6 @@
import utime
from micropython import const
from trezor import loop
from trezor import ui
@ -54,3 +55,9 @@ class Loader(ui.Widget):
else:
ui.display.loader(
progress, -8, style['fg-color'], style['bg-color'], style['icon'], style['icon-fg-color'])
def __iter__(self):
sleep = loop.sleep(1000000 // 60) # 60 fps
while self.is_active():
self.render()
yield sleep