1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-22 22:38:08 +00:00

refactor(core/ui): reorganize line width constants

This commit is contained in:
matejcik 2021-07-16 11:47:34 +02:00 committed by matejcik
parent 9ffbd34400
commit 6d15e90ed3
5 changed files with 17 additions and 13 deletions

View File

@ -3,6 +3,7 @@ from micropython import const
from trezor import ui from trezor import ui
from ...constants import ( from ...constants import (
PAGINATION_MARGIN_RIGHT,
TEXT_HEADER_HEIGHT, TEXT_HEADER_HEIGHT,
TEXT_LINE_HEIGHT, TEXT_LINE_HEIGHT,
TEXT_LINE_HEIGHT_HALF, TEXT_LINE_HEIGHT_HALF,
@ -10,6 +11,9 @@ from ...constants import (
TEXT_MAX_LINES, TEXT_MAX_LINES,
) )
LINE_WIDTH = ui.WIDTH - TEXT_MARGIN_LEFT
LINE_WIDTH_PAGINATED = LINE_WIDTH - PAGINATION_MARGIN_RIGHT
if False: if False:
from typing import Any, Union from typing import Any, Union
@ -30,7 +34,7 @@ class Span:
string: str = "", string: str = "",
start: int = 0, start: int = 0,
font: int = ui.NORMAL, font: int = ui.NORMAL,
line_width: int = ui.WIDTH - TEXT_MARGIN_LEFT, line_width: int = LINE_WIDTH,
offset_x: int = 0, offset_x: int = 0,
break_words: bool = False, break_words: bool = False,
) -> None: ) -> None:
@ -41,7 +45,7 @@ class Span:
string: str, string: str,
start: int, start: int,
font: int, font: int,
line_width: int = ui.WIDTH - TEXT_MARGIN_LEFT, line_width: int = LINE_WIDTH,
offset_x: int = 0, offset_x: int = 0,
break_words: bool = False, break_words: bool = False,
) -> None: ) -> None:

View File

@ -7,7 +7,7 @@ from trezor.messages import ButtonAck, ButtonRequest
from .button import Button, ButtonCancel, ButtonConfirm, ButtonDefault from .button import Button, ButtonCancel, ButtonConfirm, ButtonDefault
from .confirm import CANCELLED, CONFIRMED, Confirm from .confirm import CANCELLED, CONFIRMED, Confirm
from .swipe import SWIPE_DOWN, SWIPE_UP, SWIPE_VERTICAL, Swipe from .swipe import SWIPE_DOWN, SWIPE_UP, SWIPE_VERTICAL, Swipe
from .text import TEXT_MAX_LINES, Span, Text from .text import LINE_WIDTH_PAGINATED, TEXT_MAX_LINES, Span, Text
if False: if False:
from typing import Callable, Iterable from typing import Callable, Iterable
@ -15,8 +15,6 @@ if False:
from ..common.text import TextContent from ..common.text import TextContent
PAGINATED_LINE_WIDTH = const(204)
WAS_PAGED = object() WAS_PAGED = object()
@ -280,7 +278,7 @@ def paginate_text(
else: else:
pages: list[ui.Component] = [] pages: list[ui.Component] = []
span.reset( span.reset(
text, 0, font, break_words=break_words, line_width=PAGINATED_LINE_WIDTH text, 0, font, break_words=break_words, line_width=LINE_WIDTH_PAGINATED
) )
while span.has_more_content(): while span.has_more_content():
# advance to first line of the page # advance to first line of the page
@ -292,7 +290,7 @@ def paginate_text(
new_lines=False, new_lines=False,
content_offset=0, content_offset=0,
char_offset=span.start, char_offset=span.start,
line_width=PAGINATED_LINE_WIDTH, line_width=LINE_WIDTH_PAGINATED,
break_words=break_words, break_words=break_words,
render_page_overflow=False, render_page_overflow=False,
) )
@ -360,7 +358,7 @@ def paginate_paragraphs(
0, 0,
item[0], item[0],
break_words=break_words, break_words=break_words,
line_width=PAGINATED_LINE_WIDTH, line_width=LINE_WIDTH_PAGINATED,
) )
while span.has_more_content(): while span.has_more_content():
@ -373,7 +371,7 @@ def paginate_paragraphs(
new_lines=False, new_lines=False,
content_offset=content_ctr * 3 + 1, # font, _text_, newline content_offset=content_ctr * 3 + 1, # font, _text_, newline
char_offset=span.start, char_offset=span.start,
line_width=PAGINATED_LINE_WIDTH, line_width=LINE_WIDTH_PAGINATED,
render_page_overflow=False, render_page_overflow=False,
break_words=break_words, break_words=break_words,
) )

View File

@ -6,6 +6,8 @@ from trezor.ui import display, style
from ..common.text import ( # noqa: F401 from ..common.text import ( # noqa: F401
BR, BR,
BR_HALF, BR_HALF,
LINE_WIDTH,
LINE_WIDTH_PAGINATED,
TEXT_MAX_LINES, TEXT_MAX_LINES,
Span, Span,
TextBase, TextBase,

View File

@ -5,6 +5,7 @@ TEXT_LINE_HEIGHT = const(26)
TEXT_LINE_HEIGHT_HALF = const(13) TEXT_LINE_HEIGHT_HALF = const(13)
TEXT_MARGIN_LEFT = const(14) TEXT_MARGIN_LEFT = const(14)
TEXT_MAX_LINES = const(5) TEXT_MAX_LINES = const(5)
PAGINATION_MARGIN_RIGHT = const(22)
MONO_ADDR_PER_LINE = const(17) MONO_ADDR_PER_LINE = const(17)
MONO_HEX_PER_LINE = const(18) MONO_HEX_PER_LINE = const(18)

View File

@ -14,12 +14,11 @@ from ..components.tt.button import ButtonCancel, ButtonDefault
from ..components.tt.confirm import Confirm, HoldToConfirm from ..components.tt.confirm import Confirm, HoldToConfirm
from ..components.tt.scroll import ( from ..components.tt.scroll import (
PAGEBREAK, PAGEBREAK,
PAGINATED_LINE_WIDTH,
Paginated, Paginated,
paginate_paragraphs, paginate_paragraphs,
paginate_text, paginate_text,
) )
from ..components.tt.text import Span, Text from ..components.tt.text import LINE_WIDTH_PAGINATED, Span, Text
from ..constants.tt import ( from ..constants.tt import (
MONO_ADDR_PER_LINE, MONO_ADDR_PER_LINE,
MONO_HEX_PER_LINE, MONO_HEX_PER_LINE,
@ -598,11 +597,11 @@ async def confirm_properties(
para = [] para = []
used_lines = 0 used_lines = 0
for key, val in props: for key, val in props:
span.reset(key or "", 0, ui.NORMAL, line_width=PAGINATED_LINE_WIDTH) span.reset(key or "", 0, ui.NORMAL, line_width=LINE_WIDTH_PAGINATED)
key_lines = span.count_lines() key_lines = span.count_lines()
if isinstance(val, str): if isinstance(val, str):
span.reset(val, 0, ui.BOLD, line_width=PAGINATED_LINE_WIDTH) span.reset(val, 0, ui.BOLD, line_width=LINE_WIDTH_PAGINATED)
val_lines = span.count_lines() val_lines = span.count_lines()
elif isinstance(val, bytes): elif isinstance(val, bytes):
val_lines = (len(val) * 2 + MONO_HEX_PER_LINE - 1) // MONO_HEX_PER_LINE val_lines = (len(val) * 2 + MONO_HEX_PER_LINE - 1) // MONO_HEX_PER_LINE