You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
1.9 KiB
67 lines
1.9 KiB
5 years ago
|
from micropython import const
|
||
|
|
||
5 years ago
|
from trezor import res, ui
|
||
4 years ago
|
|
||
|
from ...constants import TEXT_HEADER_HEIGHT, TEXT_LINE_HEIGHT
|
||
5 years ago
|
|
||
5 years ago
|
if False:
|
||
|
from typing import Iterable, List, Union
|
||
|
|
||
|
ChecklistItem = Union[str, Iterable[str]]
|
||
|
|
||
5 years ago
|
_CHECKLIST_MAX_LINES = const(5)
|
||
|
_CHECKLIST_OFFSET_X = const(24)
|
||
5 years ago
|
_CHECKLIST_OFFSET_X_ICON = const(0)
|
||
5 years ago
|
|
||
|
|
||
5 years ago
|
class Checklist(ui.Component):
|
||
5 years ago
|
def __init__(self, title: str, icon: str) -> None:
|
||
4 years ago
|
super().__init__()
|
||
5 years ago
|
self.title = title
|
||
|
self.icon = icon
|
||
4 years ago
|
self.items: List[ChecklistItem] = []
|
||
5 years ago
|
self.active = 0
|
||
|
|
||
5 years ago
|
def add(self, item: ChecklistItem) -> None:
|
||
|
self.items.append(item)
|
||
5 years ago
|
|
||
5 years ago
|
def select(self, active: int) -> None:
|
||
5 years ago
|
self.active = active
|
||
|
|
||
5 years ago
|
def on_render(self) -> None:
|
||
5 years ago
|
if self.repaint:
|
||
|
ui.header(self.title, self.icon)
|
||
5 years ago
|
self.render_items()
|
||
5 years ago
|
self.repaint = False
|
||
5 years ago
|
|
||
5 years ago
|
def render_items(self) -> None:
|
||
5 years ago
|
offset_x = _CHECKLIST_OFFSET_X
|
||
|
offset_y = TEXT_HEADER_HEIGHT + TEXT_LINE_HEIGHT
|
||
|
bg = ui.BG
|
||
|
|
||
|
for index, item in enumerate(self.items):
|
||
|
# compute font and color
|
||
|
if index < self.active:
|
||
|
font = ui.BOLD
|
||
|
fg = ui.GREEN
|
||
|
elif index == self.active:
|
||
|
font = ui.BOLD
|
||
|
fg = ui.FG
|
||
|
else: # index > self.active
|
||
|
font = ui.NORMAL
|
||
|
fg = ui.GREY
|
||
|
|
||
5 years ago
|
# render item icon in past items
|
||
|
if index < self.active:
|
||
|
icon = res.load(ui.ICON_CONFIRM)
|
||
|
ui.display.icon(0, offset_y - 14, icon, fg, bg)
|
||
5 years ago
|
|
||
|
# render item text
|
||
|
if isinstance(item, str):
|
||
|
ui.display.text(offset_x, offset_y, item, font, fg, bg)
|
||
|
offset_y += TEXT_LINE_HEIGHT
|
||
|
else:
|
||
|
for line in item:
|
||
|
ui.display.text(offset_x, offset_y, line, font, fg, bg)
|
||
|
offset_y += TEXT_LINE_HEIGHT
|