|
|
|
@ -4,8 +4,9 @@ from trezor import loop, res, ui, utils, wire, workflow
|
|
|
|
|
from trezor.enums import ButtonRequestType
|
|
|
|
|
from trezor.messages import ButtonAck, ButtonRequest
|
|
|
|
|
|
|
|
|
|
from ..common.confirm import CANCELLED, CONFIRMED, GO_BACK, SHOW_PAGINATED
|
|
|
|
|
from .button import Button, ButtonCancel, ButtonConfirm, ButtonDefault
|
|
|
|
|
from .confirm import CANCELLED, CONFIRMED, Confirm
|
|
|
|
|
from .confirm import Confirm
|
|
|
|
|
from .swipe import SWIPE_DOWN, SWIPE_UP, SWIPE_VERTICAL, Swipe
|
|
|
|
|
from .text import (
|
|
|
|
|
LINE_WIDTH_PAGINATED,
|
|
|
|
@ -47,7 +48,7 @@ def render_scrollbar(pages: int, page: int) -> None:
|
|
|
|
|
ui.display.bar_radius(X, Y + i * padding, SIZE, SIZE, fg, ui.BG, 4)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def render_swipe_icon() -> None:
|
|
|
|
|
def render_swipe_icon(x_offset: int = 0) -> None:
|
|
|
|
|
if utils.DISABLE_ANIMATION:
|
|
|
|
|
c = ui.GREY
|
|
|
|
|
else:
|
|
|
|
@ -56,32 +57,46 @@ def render_swipe_icon() -> None:
|
|
|
|
|
c = ui.blend(ui.GREY, ui.DARK_GREY, t)
|
|
|
|
|
|
|
|
|
|
icon = res.load(ui.ICON_SWIPE)
|
|
|
|
|
ui.display.icon(70, 205, icon, c, ui.BG)
|
|
|
|
|
ui.display.icon(70 + x_offset, 205, icon, c, ui.BG)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def render_swipe_text() -> None:
|
|
|
|
|
ui.display.text_center(130, 220, "Swipe", ui.BOLD, ui.GREY, ui.BG)
|
|
|
|
|
def render_swipe_text(x_offset: int = 0) -> None:
|
|
|
|
|
ui.display.text_center(130 + x_offset, 220, "Swipe", ui.BOLD, ui.GREY, ui.BG)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Paginated(ui.Layout):
|
|
|
|
|
def __init__(self, pages: list[ui.Component], page: int = 0):
|
|
|
|
|
def __init__(
|
|
|
|
|
self, pages: list[ui.Component], page: int = 0, back_button: bool = False
|
|
|
|
|
):
|
|
|
|
|
super().__init__()
|
|
|
|
|
self.pages = pages
|
|
|
|
|
self.page = page
|
|
|
|
|
self.back_button = None
|
|
|
|
|
if back_button:
|
|
|
|
|
area = ui.grid(16, n_x=4)
|
|
|
|
|
icon = res.load(ui.ICON_BACK)
|
|
|
|
|
self.back_button = Button(area, icon, ButtonDefault)
|
|
|
|
|
self.back_button.on_click = self.on_back_click # type: ignore
|
|
|
|
|
|
|
|
|
|
def dispatch(self, event: int, x: int, y: int) -> None:
|
|
|
|
|
pages = self.pages
|
|
|
|
|
page = self.page
|
|
|
|
|
length = len(pages)
|
|
|
|
|
last_page = page >= length - 1
|
|
|
|
|
x_offset = 0
|
|
|
|
|
|
|
|
|
|
pages[page].dispatch(event, x, y)
|
|
|
|
|
if self.back_button is not None and not last_page:
|
|
|
|
|
self.back_button.dispatch(event, x, y)
|
|
|
|
|
x_offset = 30
|
|
|
|
|
|
|
|
|
|
if event is ui.REPAINT:
|
|
|
|
|
self.repaint = True
|
|
|
|
|
elif event is ui.RENDER:
|
|
|
|
|
length = len(pages)
|
|
|
|
|
if page < length - 1:
|
|
|
|
|
render_swipe_icon()
|
|
|
|
|
if not last_page:
|
|
|
|
|
render_swipe_icon(x_offset=x_offset)
|
|
|
|
|
if self.repaint:
|
|
|
|
|
render_swipe_text()
|
|
|
|
|
render_swipe_text(x_offset=x_offset)
|
|
|
|
|
if self.repaint:
|
|
|
|
|
render_scrollbar(length, page)
|
|
|
|
|
self.repaint = False
|
|
|
|
@ -143,12 +158,35 @@ class Paginated(ui.Layout):
|
|
|
|
|
def on_change(self) -> None:
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def on_back_click(self) -> None:
|
|
|
|
|
raise ui.Result(GO_BACK)
|
|
|
|
|
|
|
|
|
|
if __debug__:
|
|
|
|
|
|
|
|
|
|
def read_content(self) -> list[str]:
|
|
|
|
|
return self.pages[self.page].read_content()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class AskPaginated(ui.Component):
|
|
|
|
|
def __init__(self, content: ui.Component) -> None:
|
|
|
|
|
super().__init__()
|
|
|
|
|
self.content = content
|
|
|
|
|
self.button = Button(ui.grid(3, n_x=1), "Show all", ButtonDefault)
|
|
|
|
|
self.button.on_click = self.on_show_paginated_click # type: ignore
|
|
|
|
|
|
|
|
|
|
def dispatch(self, event: int, x: int, y: int) -> None:
|
|
|
|
|
self.content.dispatch(event, x, y)
|
|
|
|
|
self.button.dispatch(event, x, y)
|
|
|
|
|
|
|
|
|
|
def on_show_paginated_click(self) -> None:
|
|
|
|
|
raise ui.Result(SHOW_PAGINATED)
|
|
|
|
|
|
|
|
|
|
if __debug__:
|
|
|
|
|
|
|
|
|
|
def read_content(self) -> list[str]:
|
|
|
|
|
return self.content.read_content()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PageWithButtons(ui.Component):
|
|
|
|
|
def __init__(
|
|
|
|
|
self,
|
|
|
|
@ -321,6 +359,7 @@ def paginate_paragraphs(
|
|
|
|
|
icon_color: int = ui.ORANGE_ICON,
|
|
|
|
|
break_words: bool = False,
|
|
|
|
|
confirm: Callable[[ui.Component], ui.Layout] = Confirm,
|
|
|
|
|
back_button: bool = False,
|
|
|
|
|
) -> ui.Layout:
|
|
|
|
|
span = Span("", 0, ui.NORMAL, break_words=break_words)
|
|
|
|
|
lines = 0
|
|
|
|
@ -391,4 +430,4 @@ def paginate_paragraphs(
|
|
|
|
|
content_ctr += 1
|
|
|
|
|
|
|
|
|
|
pages[-1] = confirm(pages[-1])
|
|
|
|
|
return Paginated(pages)
|
|
|
|
|
return Paginated(pages, back_button=back_button)
|
|
|
|
|