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

trezor.ui.loader: make target parametric

This commit is contained in:
Jan Pochyla 2017-06-20 13:07:29 +02:00
parent 0290a13427
commit 4127655584

View File

@ -17,12 +17,11 @@ DEFAULT_LOADER_ACTIVE = {
'icon-fg-color': None, 'icon-fg-color': None,
} }
_LOADER_MSEC = const(1000)
class Loader(ui.Widget): class Loader(ui.Widget):
def __init__(self, normal_style=None, active_style=None): def __init__(self, target_ms=1000, normal_style=None, active_style=None):
self.target_ms = target_ms
self.start_ticks_ms = None self.start_ticks_ms = None
self.normal_style = normal_style or DEFAULT_LOADER self.normal_style = normal_style or DEFAULT_LOADER
self.active_style = active_style or DEFAULT_LOADER_ACTIVE self.active_style = active_style or DEFAULT_LOADER_ACTIVE
@ -35,14 +34,14 @@ class Loader(ui.Widget):
ui.display.bar(0, 32, 240, 240 - 80, ui.BLACK) ui.display.bar(0, 32, 240, 240 - 80, ui.BLACK)
ticks_diff = utime.ticks_ms() - self.start_ticks_ms ticks_diff = utime.ticks_ms() - self.start_ticks_ms
self.start_ticks_ms = None self.start_ticks_ms = None
return ticks_diff >= _LOADER_MSEC return ticks_diff >= self.target_ms
def is_active(self): def is_active(self):
return self.start_ticks_ms is not None return self.start_ticks_ms is not None
def render(self): def render(self):
progress = min(utime.ticks_ms() - self.start_ticks_ms, _LOADER_MSEC) progress = min(utime.ticks_ms() - self.start_ticks_ms, self.target_ms)
if progress == _LOADER_MSEC: if progress == self.target_ms:
style = self.active_style style = self.active_style
else: else:
style = self.normal_style style = self.normal_style