mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-22 06:18:07 +00:00
feat(core/ui): allow text without header
This commit is contained in:
parent
13c4fb97df
commit
8eb4bcff29
@ -9,6 +9,7 @@ from ...constants import (
|
||||
TEXT_LINE_HEIGHT_HALF,
|
||||
TEXT_MARGIN_LEFT,
|
||||
TEXT_MAX_LINES,
|
||||
TEXT_MAX_LINES_NO_HEADER,
|
||||
)
|
||||
|
||||
LINE_WIDTH = ui.WIDTH - TEXT_MARGIN_LEFT
|
||||
@ -232,7 +233,7 @@ def render_text(
|
||||
"""
|
||||
# initial rendering state
|
||||
INITIAL_OFFSET_X = offset_x
|
||||
offset_y_max = TEXT_HEADER_HEIGHT + (TEXT_LINE_HEIGHT * max_lines)
|
||||
offset_y_max = offset_y + (TEXT_LINE_HEIGHT * (max_lines - 1))
|
||||
span = _WORKING_SPAN
|
||||
|
||||
# scan through up to item_offset so that the current font & color is up to date
|
||||
@ -364,10 +365,10 @@ if __debug__:
|
||||
class TextBase(ui.Component):
|
||||
def __init__(
|
||||
self,
|
||||
header_text: str,
|
||||
header_text: str | None,
|
||||
header_icon: str = ui.ICON_DEFAULT,
|
||||
icon_color: int = ui.ORANGE_ICON,
|
||||
max_lines: int = TEXT_MAX_LINES,
|
||||
max_lines: int | None = None,
|
||||
new_lines: bool = True,
|
||||
break_words: bool = False,
|
||||
render_page_overflow: bool = True,
|
||||
@ -379,7 +380,14 @@ class TextBase(ui.Component):
|
||||
self.header_text = header_text
|
||||
self.header_icon = header_icon
|
||||
self.icon_color = icon_color
|
||||
|
||||
if max_lines is None:
|
||||
self.max_lines = (
|
||||
TEXT_MAX_LINES_NO_HEADER if self.header_text is None else TEXT_MAX_LINES
|
||||
)
|
||||
else:
|
||||
self.max_lines = max_lines
|
||||
|
||||
self.new_lines = new_lines
|
||||
self.break_words = break_words
|
||||
self.render_page_overflow = render_page_overflow
|
||||
@ -436,7 +444,7 @@ class TextBase(ui.Component):
|
||||
self.on_render()
|
||||
finally:
|
||||
self.repaint = should_repaint
|
||||
return [self.header_text] + display_mock.screen_contents
|
||||
return [self.header_text or ""] + display_mock.screen_contents
|
||||
|
||||
|
||||
LABEL_LEFT = const(0)
|
||||
|
@ -7,7 +7,13 @@ from trezor.messages import ButtonAck, ButtonRequest
|
||||
from .button import Button, ButtonCancel, ButtonConfirm, ButtonDefault
|
||||
from .confirm import CANCELLED, CONFIRMED, Confirm
|
||||
from .swipe import SWIPE_DOWN, SWIPE_UP, SWIPE_VERTICAL, Swipe
|
||||
from .text import LINE_WIDTH_PAGINATED, TEXT_MAX_LINES, Span, Text
|
||||
from .text import (
|
||||
LINE_WIDTH_PAGINATED,
|
||||
TEXT_MAX_LINES,
|
||||
TEXT_MAX_LINES_NO_HEADER,
|
||||
Span,
|
||||
Text,
|
||||
)
|
||||
|
||||
if False:
|
||||
from typing import Callable, Iterable
|
||||
@ -310,7 +316,7 @@ PAGEBREAK = 0, ""
|
||||
|
||||
def paginate_paragraphs(
|
||||
para: Iterable[tuple[int, str]],
|
||||
header: str,
|
||||
header: str | None,
|
||||
header_icon: str = ui.ICON_DEFAULT,
|
||||
icon_color: int = ui.ORANGE_ICON,
|
||||
break_words: bool = False,
|
||||
@ -319,6 +325,7 @@ def paginate_paragraphs(
|
||||
span = Span("", 0, ui.NORMAL, break_words=break_words)
|
||||
lines = 0
|
||||
content: list[TextContent] = []
|
||||
max_lines = TEXT_MAX_LINES_NO_HEADER if header is None else TEXT_MAX_LINES
|
||||
for item in para:
|
||||
if item is PAGEBREAK:
|
||||
continue
|
||||
@ -330,7 +337,7 @@ def paginate_paragraphs(
|
||||
content.append("\n")
|
||||
content.extend(item)
|
||||
|
||||
if lines <= TEXT_MAX_LINES:
|
||||
if lines <= max_lines:
|
||||
result = Text(
|
||||
header,
|
||||
header_icon=header_icon,
|
||||
@ -377,7 +384,7 @@ def paginate_paragraphs(
|
||||
)
|
||||
page.content = content
|
||||
pages.append(page)
|
||||
lines_left = TEXT_MAX_LINES - 1
|
||||
lines_left = max_lines - 1
|
||||
else:
|
||||
lines_left -= 1
|
||||
|
||||
|
@ -8,7 +8,10 @@ from ..common.text import ( # noqa: F401
|
||||
BR_HALF,
|
||||
LINE_WIDTH,
|
||||
LINE_WIDTH_PAGINATED,
|
||||
TEXT_HEADER_HEIGHT,
|
||||
TEXT_LINE_HEIGHT,
|
||||
TEXT_MAX_LINES,
|
||||
TEXT_MAX_LINES_NO_HEADER,
|
||||
Span,
|
||||
TextBase,
|
||||
render_text,
|
||||
@ -30,6 +33,8 @@ def header(
|
||||
class Text(TextBase):
|
||||
def on_render(self) -> None:
|
||||
if self.repaint:
|
||||
offset_y = TEXT_LINE_HEIGHT
|
||||
if self.header_text is not None:
|
||||
header(
|
||||
self.header_text,
|
||||
self.header_icon,
|
||||
@ -37,6 +42,7 @@ class Text(TextBase):
|
||||
ui.BG,
|
||||
self.icon_color,
|
||||
)
|
||||
offset_y = TEXT_HEADER_HEIGHT + TEXT_LINE_HEIGHT
|
||||
render_text(
|
||||
self.content,
|
||||
self.new_lines,
|
||||
@ -46,6 +52,7 @@ class Text(TextBase):
|
||||
break_words=self.break_words,
|
||||
line_width=self.line_width,
|
||||
render_page_overflow=self.render_page_overflow,
|
||||
offset_y=offset_y,
|
||||
)
|
||||
self.repaint = False
|
||||
|
||||
|
@ -5,3 +5,4 @@ TEXT_LINE_HEIGHT = const(9)
|
||||
TEXT_LINE_HEIGHT_HALF = const(4)
|
||||
TEXT_MARGIN_LEFT = const(0)
|
||||
TEXT_MAX_LINES = const(4)
|
||||
TEXT_MAX_LINES_NO_HEADER = const(5)
|
||||
|
@ -5,6 +5,7 @@ TEXT_LINE_HEIGHT = const(26)
|
||||
TEXT_LINE_HEIGHT_HALF = const(13)
|
||||
TEXT_MARGIN_LEFT = const(14)
|
||||
TEXT_MAX_LINES = const(5)
|
||||
TEXT_MAX_LINES_NO_HEADER = const(7)
|
||||
PAGINATION_MARGIN_RIGHT = const(22)
|
||||
|
||||
MONO_ADDR_PER_LINE = const(17)
|
||||
|
Loading…
Reference in New Issue
Block a user