mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-22 14:28:07 +00:00
refactor(core/ui): reorganize line width constants
This commit is contained in:
parent
9ffbd34400
commit
6d15e90ed3
@ -3,6 +3,7 @@ from micropython import const
|
||||
from trezor import ui
|
||||
|
||||
from ...constants import (
|
||||
PAGINATION_MARGIN_RIGHT,
|
||||
TEXT_HEADER_HEIGHT,
|
||||
TEXT_LINE_HEIGHT,
|
||||
TEXT_LINE_HEIGHT_HALF,
|
||||
@ -10,6 +11,9 @@ from ...constants import (
|
||||
TEXT_MAX_LINES,
|
||||
)
|
||||
|
||||
LINE_WIDTH = ui.WIDTH - TEXT_MARGIN_LEFT
|
||||
LINE_WIDTH_PAGINATED = LINE_WIDTH - PAGINATION_MARGIN_RIGHT
|
||||
|
||||
if False:
|
||||
from typing import Any, Union
|
||||
|
||||
@ -30,7 +34,7 @@ class Span:
|
||||
string: str = "",
|
||||
start: int = 0,
|
||||
font: int = ui.NORMAL,
|
||||
line_width: int = ui.WIDTH - TEXT_MARGIN_LEFT,
|
||||
line_width: int = LINE_WIDTH,
|
||||
offset_x: int = 0,
|
||||
break_words: bool = False,
|
||||
) -> None:
|
||||
@ -41,7 +45,7 @@ class Span:
|
||||
string: str,
|
||||
start: int,
|
||||
font: int,
|
||||
line_width: int = ui.WIDTH - TEXT_MARGIN_LEFT,
|
||||
line_width: int = LINE_WIDTH,
|
||||
offset_x: int = 0,
|
||||
break_words: bool = False,
|
||||
) -> None:
|
||||
|
@ -7,7 +7,7 @@ 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 TEXT_MAX_LINES, Span, Text
|
||||
from .text import LINE_WIDTH_PAGINATED, TEXT_MAX_LINES, Span, Text
|
||||
|
||||
if False:
|
||||
from typing import Callable, Iterable
|
||||
@ -15,8 +15,6 @@ if False:
|
||||
from ..common.text import TextContent
|
||||
|
||||
|
||||
PAGINATED_LINE_WIDTH = const(204)
|
||||
|
||||
WAS_PAGED = object()
|
||||
|
||||
|
||||
@ -280,7 +278,7 @@ def paginate_text(
|
||||
else:
|
||||
pages: list[ui.Component] = []
|
||||
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():
|
||||
# advance to first line of the page
|
||||
@ -292,7 +290,7 @@ def paginate_text(
|
||||
new_lines=False,
|
||||
content_offset=0,
|
||||
char_offset=span.start,
|
||||
line_width=PAGINATED_LINE_WIDTH,
|
||||
line_width=LINE_WIDTH_PAGINATED,
|
||||
break_words=break_words,
|
||||
render_page_overflow=False,
|
||||
)
|
||||
@ -360,7 +358,7 @@ def paginate_paragraphs(
|
||||
0,
|
||||
item[0],
|
||||
break_words=break_words,
|
||||
line_width=PAGINATED_LINE_WIDTH,
|
||||
line_width=LINE_WIDTH_PAGINATED,
|
||||
)
|
||||
|
||||
while span.has_more_content():
|
||||
@ -373,7 +371,7 @@ def paginate_paragraphs(
|
||||
new_lines=False,
|
||||
content_offset=content_ctr * 3 + 1, # font, _text_, newline
|
||||
char_offset=span.start,
|
||||
line_width=PAGINATED_LINE_WIDTH,
|
||||
line_width=LINE_WIDTH_PAGINATED,
|
||||
render_page_overflow=False,
|
||||
break_words=break_words,
|
||||
)
|
||||
|
@ -6,6 +6,8 @@ from trezor.ui import display, style
|
||||
from ..common.text import ( # noqa: F401
|
||||
BR,
|
||||
BR_HALF,
|
||||
LINE_WIDTH,
|
||||
LINE_WIDTH_PAGINATED,
|
||||
TEXT_MAX_LINES,
|
||||
Span,
|
||||
TextBase,
|
||||
|
@ -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)
|
||||
PAGINATION_MARGIN_RIGHT = const(22)
|
||||
|
||||
MONO_ADDR_PER_LINE = const(17)
|
||||
MONO_HEX_PER_LINE = const(18)
|
||||
|
@ -14,12 +14,11 @@ from ..components.tt.button import ButtonCancel, ButtonDefault
|
||||
from ..components.tt.confirm import Confirm, HoldToConfirm
|
||||
from ..components.tt.scroll import (
|
||||
PAGEBREAK,
|
||||
PAGINATED_LINE_WIDTH,
|
||||
Paginated,
|
||||
paginate_paragraphs,
|
||||
paginate_text,
|
||||
)
|
||||
from ..components.tt.text import Span, Text
|
||||
from ..components.tt.text import LINE_WIDTH_PAGINATED, Span, Text
|
||||
from ..constants.tt import (
|
||||
MONO_ADDR_PER_LINE,
|
||||
MONO_HEX_PER_LINE,
|
||||
@ -598,11 +597,11 @@ async def confirm_properties(
|
||||
para = []
|
||||
used_lines = 0
|
||||
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()
|
||||
|
||||
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()
|
||||
elif isinstance(val, bytes):
|
||||
val_lines = (len(val) * 2 + MONO_HEX_PER_LINE - 1) // MONO_HEX_PER_LINE
|
||||
|
Loading…
Reference in New Issue
Block a user