ui.loader: add is_active method

pull/25/head
Jan Pochyla 8 years ago
parent d94dd32816
commit 4e290cc6df

@ -52,9 +52,10 @@ class HoldToConfirmDialog():
self.loader = Loader(*args, **kwargs)
def render(self):
if not self.loader.render():
if self.content is not None:
self.content.render()
if self.loader.is_active():
self.loader.render()
elif self.content is not None:
self.content.render()
self.button.render()
def send(self, event, pos):

@ -16,7 +16,7 @@ DEFAULT_LOADER_ACTIVE = {
'icon-fg-color': None,
}
LOADER_MSEC = const(1000)
_LOADER_MSEC = const(1000)
class Loader():
@ -34,25 +34,23 @@ class Loader():
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 >= _LOADER_MSEC
def render(self):
if self.start_ticks_ms is None:
return False
def is_active(self):
return self.start_ticks_ms is not None
progress = min(utime.ticks_ms() - self.start_ticks_ms, LOADER_MSEC)
if progress == LOADER_MSEC:
def render(self):
progress = min(utime.ticks_ms() - self.start_ticks_ms, _LOADER_MSEC)
if progress == _LOADER_MSEC:
style = self.active_style
else:
style = self.normal_style
if style['icon'] is None:
ui.display.loader(progress, -8, style['fg-color'], style['bg-color'])
ui.display.loader(
progress, -8, style['fg-color'], style['bg-color'])
elif style['icon-fg-color'] is None:
ui.display.loader(
progress, -8, style['fg-color'], style['bg-color'], style['icon'])
else:
ui.display.loader(
progress, -8, style['fg-color'], style['bg-color'], style['icon'], style['icon-fg-color'])
return True

Loading…
Cancel
Save