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

src/apps/wallet: use max_lines in Text component

This commit is contained in:
Pavol Rusnak 2018-02-27 15:04:03 +01:00
parent 865070d083
commit 91dc487dcd
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
4 changed files with 12 additions and 5 deletions

View File

@ -23,7 +23,7 @@ async def cipher_key_value(ctx, msg):
else:
title = 'Decrypt value'
lines = split_words(msg.key, ui.WIDTH - 2 * TEXT_MARGIN_LEFT, metric=lambda x: ui.display.text_width(x, ui.NORMAL))
await require_confirm(ctx, Text(title, ui.ICON_DEFAULT, *lines))
await require_confirm(ctx, Text(title, ui.ICON_DEFAULT, max_lines=5, *lines))
node = await seed.derive_node(ctx, msg.address_n)
value = compute_cipher_key_value(msg, node.private_key())

View File

@ -34,5 +34,5 @@ async def sign_message(ctx, msg):
async def confirm_sign_message(ctx, message):
message = split_message(message)
content = Text('Sign message', ui.ICON_CONFIRM, *message)
content = Text('Sign message', ui.ICON_DEFAULT, max_lines=5, *message)
await require_confirm(ctx, content)

View File

@ -37,5 +37,5 @@ async def verify_message(ctx, msg):
async def confirm_verify_message(ctx, message):
message = split_message(message)
content = Text('Verify message', ui.ICON_CONFIRM, ui.MONO, *message)
content = Text('Verify message', ui.ICON_DEFAULT, max_lines=5, *message)
await require_confirm(ctx, content)

View File

@ -8,11 +8,12 @@ TEXT_MARGIN_LEFT = const(14)
class Text(ui.Widget):
def __init__(self, header_text, header_icon, *content, icon_color=ui.ORANGE_ICON):
def __init__(self, header_text, header_icon, *content, icon_color=ui.ORANGE_ICON, max_lines=None):
self.header_text = header_text
self.header_icon = header_icon
self.icon_color = icon_color
self.content = content
self.max_lines = max_lines
def render(self):
offset_x = TEXT_MARGIN_LEFT
@ -22,10 +23,16 @@ class Text(ui.Widget):
bg = ui.BG
ui.header(self.header_text, self.header_icon, ui.TITLE_GREY, ui.BG, self.icon_color)
line = 1
for item in self.content:
if isinstance(item, str):
ui.display.text(offset_x, offset_y, item, style, fg, bg)
if self.max_lines is not None and line >= self.max_lines:
ui.display.text(offset_x, offset_y, item + '...', style, fg, bg)
break
else:
ui.display.text(offset_x, offset_y, item, style, fg, bg)
offset_y += TEXT_LINE_HEIGHT
line += 1
elif item == ui.MONO or item == ui.NORMAL or item == ui.BOLD:
style = item
else: