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:
parent
c94e02b0eb
commit
bcd94ecbc1
@ -44,20 +44,20 @@ class ConfirmDialog(Widget):
|
|||||||
return await loop.Wait((super().__iter__(), self.content))
|
return await loop.Wait((super().__iter__(), self.content))
|
||||||
|
|
||||||
|
|
||||||
|
_STARTED = const(-1)
|
||||||
|
_STOPPED = const(-2)
|
||||||
|
|
||||||
|
|
||||||
class HoldToConfirmDialog(Widget):
|
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,
|
self.button = Button((0, 240 - 48, 240, 48), hold,
|
||||||
normal_style=CONFIRM_BUTTON,
|
normal_style=CONFIRM_BUTTON,
|
||||||
active_style=CONFIRM_BUTTON_ACTIVE)
|
active_style=CONFIRM_BUTTON_ACTIVE)
|
||||||
self.content = content
|
|
||||||
self.loader = Loader(*args, **kwargs)
|
self.loader = Loader(*args, **kwargs)
|
||||||
|
|
||||||
def render(self):
|
def render(self):
|
||||||
if self.loader.is_active():
|
|
||||||
self.loader.render()
|
|
||||||
elif self.content is not None:
|
|
||||||
self.content.render()
|
|
||||||
self.button.render()
|
self.button.render()
|
||||||
|
|
||||||
def touch(self, event, pos):
|
def touch(self, event, pos):
|
||||||
@ -65,28 +65,22 @@ class HoldToConfirmDialog(Widget):
|
|||||||
was_started = button.state & BTN_STARTED
|
was_started = button.state & BTN_STARTED
|
||||||
button.touch(event, pos)
|
button.touch(event, pos)
|
||||||
is_started = button.state & BTN_STARTED
|
is_started = button.state & BTN_STARTED
|
||||||
if is_started:
|
if is_started and not was_started:
|
||||||
if not was_started:
|
self.loader.start()
|
||||||
self.loader.start()
|
return _STARTED
|
||||||
else:
|
if was_started and not is_started:
|
||||||
if was_started:
|
if self.loader.stop():
|
||||||
if self.loader.stop():
|
return CONFIRMED
|
||||||
return CONFIRMED
|
else:
|
||||||
if self.content is not None:
|
return _STOPPED
|
||||||
return self.content.touch(event, pos)
|
|
||||||
|
|
||||||
async def __iter__(self):
|
async def __iter__(self):
|
||||||
return await loop.Wait((self._render_loop(), self._event_loop()))
|
result = None
|
||||||
|
while result is None or result < 0: # _STARTED or _STOPPED
|
||||||
def _render_loop(self):
|
if self.loader.is_active():
|
||||||
RENDER_DELAY = const(1000000 // 60)
|
content_loop = self.loader
|
||||||
while True:
|
else:
|
||||||
self.render()
|
content_loop = self.content
|
||||||
yield loop.Sleep(RENDER_DELAY)
|
confirm_loop = super().__iter__() # default loop (render on touch)
|
||||||
|
result = await loop.wait((content_loop, confirm_loop))
|
||||||
def _event_loop(self):
|
return result
|
||||||
while True:
|
|
||||||
event, *pos = yield loop.Select(loop.TOUCH)
|
|
||||||
result = self.touch(event, pos)
|
|
||||||
if result is not None:
|
|
||||||
return result
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import utime
|
import utime
|
||||||
from micropython import const
|
from micropython import const
|
||||||
|
from trezor import loop
|
||||||
from trezor import ui
|
from trezor import ui
|
||||||
|
|
||||||
|
|
||||||
@ -54,3 +55,9 @@ class Loader(ui.Widget):
|
|||||||
else:
|
else:
|
||||||
ui.display.loader(
|
ui.display.loader(
|
||||||
progress, -8, style['fg-color'], style['bg-color'], style['icon'], style['icon-fg-color'])
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user