mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-22 07:28:10 +00:00
trezor.ui.loader: make target parametric
This commit is contained in:
parent
0290a13427
commit
4127655584
@ -17,12 +17,11 @@ DEFAULT_LOADER_ACTIVE = {
|
||||
'icon-fg-color': None,
|
||||
}
|
||||
|
||||
_LOADER_MSEC = const(1000)
|
||||
|
||||
|
||||
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.normal_style = normal_style or DEFAULT_LOADER
|
||||
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)
|
||||
ticks_diff = utime.ticks_ms() - self.start_ticks_ms
|
||||
self.start_ticks_ms = None
|
||||
return ticks_diff >= _LOADER_MSEC
|
||||
return ticks_diff >= self.target_ms
|
||||
|
||||
def is_active(self):
|
||||
return self.start_ticks_ms is not None
|
||||
|
||||
def render(self):
|
||||
progress = min(utime.ticks_ms() - self.start_ticks_ms, _LOADER_MSEC)
|
||||
if progress == _LOADER_MSEC:
|
||||
progress = min(utime.ticks_ms() - self.start_ticks_ms, self.target_ms)
|
||||
if progress == self.target_ms:
|
||||
style = self.active_style
|
||||
else:
|
||||
style = self.normal_style
|
||||
|
Loading…
Reference in New Issue
Block a user