diff --git a/core/SConscript.firmware b/core/SConscript.firmware index 98eddde382..53b541261f 100644 --- a/core/SConscript.firmware +++ b/core/SConscript.firmware @@ -492,6 +492,18 @@ if FROZEN: SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/crypto/*.py')) SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/res/*.py')) SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/ui/*.py')) + SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/ui/components/*.py')) + SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/ui/components/common/*.py')) + SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/ui/constants/__init__.py')) + if TREZOR_MODEL == 'T': + SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/ui/components/tt/*.py')) + SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/ui/constants/tt.py')) + elif TREZOR_MODEL == '1': + SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/ui/components/t1/*.py')) + SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/ui/constants/t1.py')) + else: + raise ValueError('Unknown Trezor model') + SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/wire/*.py')) SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'storage/*.py')) diff --git a/core/SConscript.unix b/core/SConscript.unix index 71b609f6ab..57661f8c00 100644 --- a/core/SConscript.unix +++ b/core/SConscript.unix @@ -443,6 +443,18 @@ if FROZEN: SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/crypto/*.py')) SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/res/*.py')) SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/ui/*.py')) + SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/ui/components/*.py')) + SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/ui/components/common/*.py')) + SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/ui/constants/__init__.py')) + if TREZOR_MODEL == 'T': + SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/ui/components/tt/*.py')) + SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/ui/constants/tt.py')) + elif TREZOR_MODEL == '1': + SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/ui/components/t1/*.py')) + SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/ui/constants/t1.py')) + else: + raise ValueError('Unknown Trezor model') + SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/wire/*.py')) SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'storage/*.py')) diff --git a/core/src/apps/base.py b/core/src/apps/base.py index a89f753926..0ad55830e5 100644 --- a/core/src/apps/base.py +++ b/core/src/apps/base.py @@ -131,7 +131,7 @@ async def handle_Ping(ctx: wire.Context, msg: Ping) -> Success: if msg.button_protection: from apps.common.confirm import require_confirm from trezor.messages.ButtonRequestType import ProtectCall - from trezor.ui.text import Text + from trezor.ui.components.tt.text import Text await require_confirm(ctx, Text("Confirm"), ProtectCall) return Success(message=msg.message) diff --git a/core/src/apps/binance/layout.py b/core/src/apps/binance/layout.py index 0285e2313b..4fd5c7c636 100644 --- a/core/src/apps/binance/layout.py +++ b/core/src/apps/binance/layout.py @@ -8,8 +8,8 @@ from trezor.messages import ( ButtonRequestType, ) from trezor.strings import format_amount -from trezor.ui.scroll import Paginated -from trezor.ui.text import Text +from trezor.ui.components.tt.scroll import Paginated +from trezor.ui.components.tt.text import Text from apps.common.confirm import require_hold_to_confirm from apps.common.layout import split_address diff --git a/core/src/apps/bitcoin/authorize_coinjoin.py b/core/src/apps/bitcoin/authorize_coinjoin.py index de212dc6b0..2a78b2c7f5 100644 --- a/core/src/apps/bitcoin/authorize_coinjoin.py +++ b/core/src/apps/bitcoin/authorize_coinjoin.py @@ -4,7 +4,7 @@ from trezor import ui from trezor.messages.AuthorizeCoinJoin import AuthorizeCoinJoin from trezor.messages.Success import Success from trezor.strings import format_amount -from trezor.ui.text import Text +from trezor.ui.components.tt.text import Text from apps.base import set_authorization from apps.common.confirm import require_confirm, require_hold_to_confirm diff --git a/core/src/apps/bitcoin/get_ownership_proof.py b/core/src/apps/bitcoin/get_ownership_proof.py index 694a8c7023..9bd4470dac 100644 --- a/core/src/apps/bitcoin/get_ownership_proof.py +++ b/core/src/apps/bitcoin/get_ownership_proof.py @@ -3,7 +3,7 @@ from ubinascii import hexlify from trezor import ui, wire from trezor.messages.GetOwnershipProof import GetOwnershipProof from trezor.messages.OwnershipProof import OwnershipProof -from trezor.ui.text import Text +from trezor.ui.components.tt.text import Text from apps.common.confirm import require_confirm from apps.common.paths import validate_path diff --git a/core/src/apps/bitcoin/sign_tx/layout.py b/core/src/apps/bitcoin/sign_tx/layout.py index e7c098b8a3..a3c11ec4c5 100644 --- a/core/src/apps/bitcoin/sign_tx/layout.py +++ b/core/src/apps/bitcoin/sign_tx/layout.py @@ -4,7 +4,7 @@ from ubinascii import hexlify from trezor import ui from trezor.messages import AmountUnit, ButtonRequestType, OutputScriptType from trezor.strings import format_amount -from trezor.ui.text import Text +from trezor.ui.components.tt.text import Text from trezor.utils import chunks from apps.common.confirm import require_confirm, require_hold_to_confirm diff --git a/core/src/apps/cardano/layout.py b/core/src/apps/cardano/layout.py index 3c01b74ba4..aacfc45521 100644 --- a/core/src/apps/cardano/layout.py +++ b/core/src/apps/cardano/layout.py @@ -8,9 +8,9 @@ from trezor.messages import ( CardanoCertificateType, ) from trezor.strings import format_amount -from trezor.ui.button import ButtonDefault -from trezor.ui.scroll import Paginated -from trezor.ui.text import Text +from trezor.ui.components.tt.button import ButtonDefault +from trezor.ui.components.tt.scroll import Paginated +from trezor.ui.components.tt.text import Text from trezor.utils import chunks from apps.common.confirm import confirm, require_confirm, require_hold_to_confirm diff --git a/core/src/apps/common/confirm.py b/core/src/apps/common/confirm.py index faad6d722a..1135dfd41f 100644 --- a/core/src/apps/common/confirm.py +++ b/core/src/apps/common/confirm.py @@ -1,17 +1,23 @@ from trezor import wire from trezor.messages import ButtonRequestType -from trezor.ui.confirm import CONFIRMED, INFO, Confirm, HoldToConfirm, InfoConfirm +from trezor.ui.components.tt.confirm import ( + CONFIRMED, + INFO, + Confirm, + HoldToConfirm, + InfoConfirm, +) from . import button_request if __debug__: - from trezor.ui.scroll import Paginated + from trezor.ui.components.tt.scroll import Paginated if False: from typing import Any, Callable, Optional from trezor import ui - from trezor.ui.confirm import ButtonContent, ButtonStyleType + from trezor.ui.components.tt.confirm import ButtonContent, ButtonStyleType from trezor.ui.loader import LoaderStyleType from trezor.messages.ButtonRequest import EnumTypeButtonRequestType diff --git a/core/src/apps/common/layout.py b/core/src/apps/common/layout.py index 1fb13c42e9..02ddfe2ac4 100644 --- a/core/src/apps/common/layout.py +++ b/core/src/apps/common/layout.py @@ -3,11 +3,11 @@ from ubinascii import hexlify from trezor import ui from trezor.messages import ButtonRequestType -from trezor.ui.button import ButtonDefault +from trezor.ui.components.tt.button import ButtonDefault +from trezor.ui.components.tt.scroll import Paginated +from trezor.ui.components.tt.text import TEXT_MAX_LINES, Span, Text from trezor.ui.container import Container from trezor.ui.qr import Qr -from trezor.ui.scroll import Paginated -from trezor.ui.text import TEXT_MAX_LINES, Span, Text from trezor.utils import chunks from apps.common import HARDENED diff --git a/core/src/apps/common/mnemonic.py b/core/src/apps/common/mnemonic.py index 11f2fdcfd1..c1f4cb479b 100644 --- a/core/src/apps/common/mnemonic.py +++ b/core/src/apps/common/mnemonic.py @@ -2,7 +2,7 @@ import storage.device from trezor import ui, utils, workflow from trezor.crypto import bip39, slip39 from trezor.messages import BackupType -from trezor.ui.text import Text +from trezor.ui.components.tt.text import Text if False: from typing import Optional, Tuple diff --git a/core/src/apps/common/passphrase.py b/core/src/apps/common/passphrase.py index 46b19885ab..9f596c0e58 100644 --- a/core/src/apps/common/passphrase.py +++ b/core/src/apps/common/passphrase.py @@ -6,8 +6,8 @@ from trezor.messages import ButtonRequestType from trezor.messages.PassphraseAck import PassphraseAck from trezor.messages.PassphraseRequest import PassphraseRequest from trezor.ui import ICON_CONFIG, draw_simple -from trezor.ui.passphrase import CANCELLED, PassphraseKeyboard -from trezor.ui.text import Text +from trezor.ui.components.tt.passphrase import CANCELLED, PassphraseKeyboard +from trezor.ui.components.tt.text import Text from . import button_request from .confirm import require_confirm diff --git a/core/src/apps/common/paths.py b/core/src/apps/common/paths.py index cd6a42df0f..7b539623eb 100644 --- a/core/src/apps/common/paths.py +++ b/core/src/apps/common/paths.py @@ -2,7 +2,7 @@ from micropython import const from trezor import ui from trezor.messages import ButtonRequestType -from trezor.ui.text import Text +from trezor.ui.components.tt.text import Text from . import HARDENED from .confirm import require_confirm diff --git a/core/src/apps/common/request_pin.py b/core/src/apps/common/request_pin.py index 89c287795c..bb734eab14 100644 --- a/core/src/apps/common/request_pin.py +++ b/core/src/apps/common/request_pin.py @@ -4,9 +4,9 @@ import storage.sd_salt from trezor import config, ui, wire from trezor.messages import ButtonRequestType from trezor.pin import pin_to_int -from trezor.ui.pin import CANCELLED, PinDialog +from trezor.ui.components.tt.pin import CANCELLED, PinDialog +from trezor.ui.components.tt.text import Text from trezor.ui.popup import Popup -from trezor.ui.text import Text from . import button_request from .sdcard import SdCardUnavailable, request_sd_salt diff --git a/core/src/apps/common/sdcard.py b/core/src/apps/common/sdcard.py index 5bf0d93a3a..569c24b951 100644 --- a/core/src/apps/common/sdcard.py +++ b/core/src/apps/common/sdcard.py @@ -1,7 +1,7 @@ import storage.sd_salt from storage.sd_salt import SD_CARD_HOT_SWAPPABLE from trezor import fatfs, sdcard, ui, wire -from trezor.ui.text import Text +from trezor.ui.components.tt.text import Text from apps.common.confirm import confirm, hold_to_confirm diff --git a/core/src/apps/common/signverify.py b/core/src/apps/common/signverify.py index 3fa5b07889..88f22dc7e2 100644 --- a/core/src/apps/common/signverify.py +++ b/core/src/apps/common/signverify.py @@ -2,7 +2,7 @@ from ubinascii import hexlify from trezor import ui, utils, wire from trezor.crypto.hashlib import blake256, sha256 -from trezor.ui.text import Text +from trezor.ui.components.tt.text import Text from apps.common.confirm import require_confirm from apps.common.layout import paginate_text, split_address diff --git a/core/src/apps/debug/__init__.py b/core/src/apps/debug/__init__.py index 0d7720bca3..3277207184 100644 --- a/core/src/apps/debug/__init__.py +++ b/core/src/apps/debug/__init__.py @@ -53,7 +53,7 @@ if __debug__: layout_change_chan.publish(current_content) async def debuglink_decision_dispatcher() -> None: - from trezor.ui import confirm, swipe + from trezor.ui.components.tt import confirm, swipe while True: msg = await debuglink_decision_chan.take() diff --git a/core/src/apps/debug/load_device.py b/core/src/apps/debug/load_device.py index 5471142d17..446b23adc7 100644 --- a/core/src/apps/debug/load_device.py +++ b/core/src/apps/debug/load_device.py @@ -5,7 +5,7 @@ from trezor.crypto import bip39, slip39 from trezor.messages import BackupType from trezor.messages.Success import Success from trezor.pin import pin_to_int -from trezor.ui.text import Text +from trezor.ui.components.tt.text import Text from apps.common.confirm import require_confirm from apps.management import backup_types diff --git a/core/src/apps/debug/show_text.py b/core/src/apps/debug/show_text.py index 8e32475bd3..c7092dbee9 100644 --- a/core/src/apps/debug/show_text.py +++ b/core/src/apps/debug/show_text.py @@ -3,7 +3,7 @@ from trezor import ui, wire from trezor.messages.DebugLinkShowText import DebugLinkShowText from trezor.messages.Success import Success from trezor.ui import style, text -from trezor.ui.text import Text +from trezor.ui.components.tt.text import Text from apps.common.confirm import confirm diff --git a/core/src/apps/eos/actions/layout.py b/core/src/apps/eos/actions/layout.py index eee591155c..8eddbb5523 100644 --- a/core/src/apps/eos/actions/layout.py +++ b/core/src/apps/eos/actions/layout.py @@ -3,8 +3,8 @@ from ubinascii import hexlify from trezor import ui from trezor.messages import ButtonRequestType -from trezor.ui.scroll import Paginated -from trezor.ui.text import Text +from trezor.ui.components.tt.scroll import Paginated +from trezor.ui.components.tt.text import Text from trezor.utils import chunks from .. import helpers diff --git a/core/src/apps/eos/layout.py b/core/src/apps/eos/layout.py index 41f0b17fa1..686d54efe7 100644 --- a/core/src/apps/eos/layout.py +++ b/core/src/apps/eos/layout.py @@ -1,6 +1,6 @@ from trezor import ui, wire from trezor.messages import ButtonRequestType -from trezor.ui.text import Text +from trezor.ui.components.tt.text import Text from apps.common.confirm import require_confirm diff --git a/core/src/apps/ethereum/layout.py b/core/src/apps/ethereum/layout.py index b1c5b7a1fb..11dc5555da 100644 --- a/core/src/apps/ethereum/layout.py +++ b/core/src/apps/ethereum/layout.py @@ -3,7 +3,7 @@ from ubinascii import hexlify from trezor import ui from trezor.messages import ButtonRequestType from trezor.strings import format_amount -from trezor.ui.text import Text +from trezor.ui.components.tt.text import Text from trezor.utils import chunks from apps.common.confirm import require_confirm, require_hold_to_confirm diff --git a/core/src/apps/lisk/layout.py b/core/src/apps/lisk/layout.py index 78121e351a..6b71e99cc6 100644 --- a/core/src/apps/lisk/layout.py +++ b/core/src/apps/lisk/layout.py @@ -1,7 +1,7 @@ from trezor import ui from trezor.messages import ButtonRequestType from trezor.strings import format_amount -from trezor.ui.text import Text +from trezor.ui.components.tt.text import Text from trezor.utils import chunks from apps.common.confirm import require_confirm, require_hold_to_confirm diff --git a/core/src/apps/management/apply_settings.py b/core/src/apps/management/apply_settings.py index dc5b5a0069..cddf5cfc80 100644 --- a/core/src/apps/management/apply_settings.py +++ b/core/src/apps/management/apply_settings.py @@ -3,7 +3,7 @@ from trezor import ui, wire, workflow from trezor.messages import ButtonRequestType, SafetyCheckLevel from trezor.messages.Success import Success from trezor.strings import format_duration_ms -from trezor.ui.text import Text +from trezor.ui.components.tt.text import Text from apps.base import lock_device from apps.common import safety_checks diff --git a/core/src/apps/management/change_pin.py b/core/src/apps/management/change_pin.py index 1b47f2cdc3..40e8ebc0ec 100644 --- a/core/src/apps/management/change_pin.py +++ b/core/src/apps/management/change_pin.py @@ -2,7 +2,7 @@ from storage.device import is_initialized from trezor import config, ui, wire from trezor.messages.Success import Success from trezor.pin import pin_to_int -from trezor.ui.text import Text +from trezor.ui.components.tt.text import Text from apps.common.confirm import require_confirm from apps.common.layout import show_success diff --git a/core/src/apps/management/change_wipe_code.py b/core/src/apps/management/change_wipe_code.py index 4c48778129..02ba478b44 100644 --- a/core/src/apps/management/change_wipe_code.py +++ b/core/src/apps/management/change_wipe_code.py @@ -2,8 +2,8 @@ from storage.device import is_initialized from trezor import config, ui, wire from trezor.messages.Success import Success from trezor.pin import pin_to_int +from trezor.ui.components.tt.text import Text from trezor.ui.popup import Popup -from trezor.ui.text import Text from apps.common.confirm import require_confirm from apps.common.layout import show_success diff --git a/core/src/apps/management/get_next_u2f_counter.py b/core/src/apps/management/get_next_u2f_counter.py index 86384e0be4..ba366b50bb 100644 --- a/core/src/apps/management/get_next_u2f_counter.py +++ b/core/src/apps/management/get_next_u2f_counter.py @@ -3,7 +3,7 @@ from trezor import ui, wire from trezor.messages import ButtonRequestType from trezor.messages.GetNextU2FCounter import GetNextU2FCounter from trezor.messages.NextU2FCounter import NextU2FCounter -from trezor.ui.text import Text +from trezor.ui.components.tt.text import Text from apps.common.confirm import require_confirm diff --git a/core/src/apps/management/recovery_device/__init__.py b/core/src/apps/management/recovery_device/__init__.py index 97f41b8a46..25274a6b70 100644 --- a/core/src/apps/management/recovery_device/__init__.py +++ b/core/src/apps/management/recovery_device/__init__.py @@ -5,7 +5,7 @@ from trezor import config, ui, wire, workflow from trezor.messages import ButtonRequestType from trezor.messages.Success import Success from trezor.pin import pin_to_int -from trezor.ui.text import Text +from trezor.ui.components.tt.text import Text from apps.common.confirm import require_confirm from apps.common.request_pin import ( diff --git a/core/src/apps/management/recovery_device/keyboard_bip39.py b/core/src/apps/management/recovery_device/keyboard_bip39.py index 1b2e02ebe8..e866b6da62 100644 --- a/core/src/apps/management/recovery_device/keyboard_bip39.py +++ b/core/src/apps/management/recovery_device/keyboard_bip39.py @@ -1,11 +1,16 @@ from trezor import io, loop, res, ui, workflow from trezor.crypto import bip39 from trezor.ui import display -from trezor.ui.button import Button, ButtonClear, ButtonMono, ButtonMonoConfirm +from trezor.ui.components.tt.button import ( + Button, + ButtonClear, + ButtonMono, + ButtonMonoConfirm, +) if False: from typing import Optional, Tuple - from trezor.ui.button import ButtonContent, ButtonStyleStateType + from trezor.ui.components.tt.button import ButtonContent, ButtonStyleStateType def compute_mask(text: str) -> int: diff --git a/core/src/apps/management/recovery_device/keyboard_slip39.py b/core/src/apps/management/recovery_device/keyboard_slip39.py index 9753cdbcb1..cafa1e7b4b 100644 --- a/core/src/apps/management/recovery_device/keyboard_slip39.py +++ b/core/src/apps/management/recovery_device/keyboard_slip39.py @@ -1,11 +1,16 @@ from trezor import io, loop, res, ui, workflow from trezor.crypto import slip39 from trezor.ui import display -from trezor.ui.button import Button, ButtonClear, ButtonMono, ButtonMonoConfirm +from trezor.ui.components.tt.button import ( + Button, + ButtonClear, + ButtonMono, + ButtonMonoConfirm, +) if False: from typing import Optional, Tuple - from trezor.ui.button import ButtonContent, ButtonStyleStateType + from trezor.ui.components.tt.button import ButtonContent, ButtonStyleStateType class KeyButton(Button): diff --git a/core/src/apps/management/recovery_device/layout.py b/core/src/apps/management/recovery_device/layout.py index 278c611ec5..676cb4fac3 100644 --- a/core/src/apps/management/recovery_device/layout.py +++ b/core/src/apps/management/recovery_device/layout.py @@ -2,9 +2,9 @@ import storage.recovery from trezor import strings, ui, wire from trezor.crypto.slip39 import MAX_SHARE_COUNT from trezor.messages import ButtonRequestType -from trezor.ui.scroll import Paginated -from trezor.ui.text import Text -from trezor.ui.word_select import WordSelector +from trezor.ui.components.tt.scroll import Paginated +from trezor.ui.components.tt.text import Text +from trezor.ui.components.tt.word_select import WordSelector from apps.common import button_request from apps.common.confirm import confirm, info_confirm, require_confirm diff --git a/core/src/apps/management/reset_device/layout.py b/core/src/apps/management/reset_device/layout.py index e30ae01211..15da9d5c57 100644 --- a/core/src/apps/management/reset_device/layout.py +++ b/core/src/apps/management/reset_device/layout.py @@ -3,13 +3,13 @@ import ubinascii from trezor import ui, utils from trezor.crypto import random from trezor.messages import BackupType, ButtonRequestType -from trezor.ui.button import Button, ButtonDefault -from trezor.ui.checklist import Checklist -from trezor.ui.info import InfoConfirm +from trezor.ui.components.tt.button import Button, ButtonDefault +from trezor.ui.components.tt.checklist import Checklist +from trezor.ui.components.tt.info import InfoConfirm +from trezor.ui.components.tt.num_input import NumInput +from trezor.ui.components.tt.scroll import Paginated +from trezor.ui.components.tt.text import Text from trezor.ui.loader import LoadingAnimation -from trezor.ui.num_input import NumInput -from trezor.ui.scroll import Paginated -from trezor.ui.text import Text from apps.common.confirm import confirm, require_confirm, require_hold_to_confirm from apps.common.layout import show_success diff --git a/core/src/apps/management/sd_protect.py b/core/src/apps/management/sd_protect.py index 8da0deab92..a7fb1f2445 100644 --- a/core/src/apps/management/sd_protect.py +++ b/core/src/apps/management/sd_protect.py @@ -5,7 +5,7 @@ from trezor.crypto import random from trezor.messages import SdProtectOperationType from trezor.messages.Success import Success from trezor.pin import pin_to_int -from trezor.ui.text import Text +from trezor.ui.components.tt.text import Text from apps.common.confirm import require_confirm from apps.common.layout import show_success diff --git a/core/src/apps/management/set_u2f_counter.py b/core/src/apps/management/set_u2f_counter.py index 2e43a14099..ad1437a1e4 100644 --- a/core/src/apps/management/set_u2f_counter.py +++ b/core/src/apps/management/set_u2f_counter.py @@ -3,7 +3,7 @@ from trezor import ui, wire from trezor.messages import ButtonRequestType from trezor.messages.SetU2FCounter import SetU2FCounter from trezor.messages.Success import Success -from trezor.ui.text import Text +from trezor.ui.components.tt.text import Text from apps.common.confirm import require_confirm diff --git a/core/src/apps/management/wipe_device.py b/core/src/apps/management/wipe_device.py index 498ffb5c19..f01fd07fda 100644 --- a/core/src/apps/management/wipe_device.py +++ b/core/src/apps/management/wipe_device.py @@ -2,9 +2,9 @@ import storage from trezor import ui from trezor.messages import ButtonRequestType from trezor.messages.Success import Success -from trezor.ui.button import ButtonCancel +from trezor.ui.components.tt.button import ButtonCancel +from trezor.ui.components.tt.text import Text from trezor.ui.loader import LoaderDanger -from trezor.ui.text import Text from apps.common.confirm import require_hold_to_confirm diff --git a/core/src/apps/misc/cipher_key_value.py b/core/src/apps/misc/cipher_key_value.py index cc18609658..5177de151b 100644 --- a/core/src/apps/misc/cipher_key_value.py +++ b/core/src/apps/misc/cipher_key_value.py @@ -1,7 +1,7 @@ from trezor import wire from trezor.crypto import aes, hmac from trezor.messages.CipheredKeyValue import CipheredKeyValue -from trezor.ui.text import Text +from trezor.ui.components.tt.text import Text from apps.common.confirm import require_confirm from apps.common.keychain import get_keychain diff --git a/core/src/apps/misc/get_ecdh_session_key.py b/core/src/apps/misc/get_ecdh_session_key.py index d6a86c3d3c..f9d51390e3 100644 --- a/core/src/apps/misc/get_ecdh_session_key.py +++ b/core/src/apps/misc/get_ecdh_session_key.py @@ -3,7 +3,7 @@ from ustruct import pack, unpack from trezor import wire from trezor.crypto.hashlib import sha256 from trezor.messages.ECDHSessionKey import ECDHSessionKey -from trezor.ui.text import Text +from trezor.ui.components.tt.text import Text from trezor.utils import chunks from apps.common import HARDENED diff --git a/core/src/apps/misc/get_entropy.py b/core/src/apps/misc/get_entropy.py index ce3457bb5b..11d1b6346f 100644 --- a/core/src/apps/misc/get_entropy.py +++ b/core/src/apps/misc/get_entropy.py @@ -1,7 +1,7 @@ from trezor.crypto import random from trezor.messages import ButtonRequestType from trezor.messages.Entropy import Entropy -from trezor.ui.text import Text +from trezor.ui.components.tt.text import Text from apps.common.confirm import require_confirm diff --git a/core/src/apps/misc/sign_identity.py b/core/src/apps/misc/sign_identity.py index 0c1741b954..dffa59cab3 100644 --- a/core/src/apps/misc/sign_identity.py +++ b/core/src/apps/misc/sign_identity.py @@ -3,7 +3,7 @@ from ustruct import pack, unpack from trezor import ui, wire from trezor.crypto.hashlib import sha256 from trezor.messages.SignedIdentity import SignedIdentity -from trezor.ui.text import Text +from trezor.ui.components.tt.text import Text from trezor.utils import chunks from apps.common import HARDENED, coininfo @@ -16,7 +16,7 @@ if False: from trezor.messages.IdentityType import IdentityType from trezor.messages.SignIdentity import SignIdentity - from trezor.ui.text import TextContent + from trezor.ui.components.common.text import TextContent from apps.common.paths import Bip32Path diff --git a/core/src/apps/monero/layout/common.py b/core/src/apps/monero/layout/common.py index b5818a555e..f155374bd9 100644 --- a/core/src/apps/monero/layout/common.py +++ b/core/src/apps/monero/layout/common.py @@ -1,6 +1,6 @@ from trezor import strings, ui, utils from trezor.messages import ButtonRequestType -from trezor.ui.text import Text +from trezor.ui.components.tt.text import Text from apps.common import button_request @@ -8,7 +8,11 @@ from apps.common import button_request async def naive_pagination( ctx, lines, title, icon=ui.ICON_RESET, icon_color=ui.ORANGE, per_page=5 ): - from trezor.ui.scroll import CANCELLED, CONFIRMED, PaginatedWithButtons + from trezor.ui.components.tt.scroll import ( + CANCELLED, + CONFIRMED, + PaginatedWithButtons, + ) pages = [] page_lines = paginate_lines(lines, per_page) diff --git a/core/src/apps/monero/layout/confirms.py b/core/src/apps/monero/layout/confirms.py index f81eb64c7a..d72be6f055 100644 --- a/core/src/apps/monero/layout/confirms.py +++ b/core/src/apps/monero/layout/confirms.py @@ -2,8 +2,8 @@ from ubinascii import hexlify from trezor import ui, wire from trezor.messages import ButtonRequestType +from trezor.ui.components.tt.text import Text from trezor.ui.popup import Popup -from trezor.ui.text import Text from trezor.utils import chunks from apps.common.confirm import require_confirm, require_hold_to_confirm @@ -228,8 +228,8 @@ async def show_address( ): from apps.common.confirm import confirm from trezor.messages import ButtonRequestType - from trezor.ui.button import ButtonDefault - from trezor.ui.scroll import Paginated + from trezor.ui.components.tt.button import ButtonDefault + from trezor.ui.components.tt.scroll import Paginated pages = [] for lines in common.paginate_lines(common.split_address(address), 5): diff --git a/core/src/apps/nem/layout.py b/core/src/apps/nem/layout.py index 41e8a9a875..932b9e7496 100644 --- a/core/src/apps/nem/layout.py +++ b/core/src/apps/nem/layout.py @@ -1,7 +1,7 @@ from trezor import ui from trezor.messages import ButtonRequestType from trezor.strings import format_amount -from trezor.ui.text import Text +from trezor.ui.components.tt.text import Text from apps.common.confirm import require_confirm, require_hold_to_confirm diff --git a/core/src/apps/nem/mosaic/layout.py b/core/src/apps/nem/mosaic/layout.py index 9fe181181e..126ff5b319 100644 --- a/core/src/apps/nem/mosaic/layout.py +++ b/core/src/apps/nem/mosaic/layout.py @@ -8,8 +8,8 @@ from trezor.messages import ( NEMSupplyChangeType, NEMTransactionCommon, ) -from trezor.ui.scroll import Paginated -from trezor.ui.text import Text +from trezor.ui.components.tt.scroll import Paginated +from trezor.ui.components.tt.text import Text from apps.common.layout import require_confirm, split_address diff --git a/core/src/apps/nem/multisig/layout.py b/core/src/apps/nem/multisig/layout.py index 3171ccde7a..4757dece1a 100644 --- a/core/src/apps/nem/multisig/layout.py +++ b/core/src/apps/nem/multisig/layout.py @@ -7,7 +7,7 @@ from trezor.messages import ( NEMSignTx, NEMTransactionCommon, ) -from trezor.ui.text import Text +from trezor.ui.components.tt.text import Text from apps.common.layout import split_address diff --git a/core/src/apps/nem/transfer/layout.py b/core/src/apps/nem/transfer/layout.py index 5103103ca4..cdc2dc568c 100644 --- a/core/src/apps/nem/transfer/layout.py +++ b/core/src/apps/nem/transfer/layout.py @@ -9,7 +9,7 @@ from trezor.messages import ( NEMTransfer, ) from trezor.strings import format_amount -from trezor.ui.text import Text +from trezor.ui.components.tt.text import Text from apps.common.confirm import require_confirm from apps.common.layout import split_address diff --git a/core/src/apps/ripple/layout.py b/core/src/apps/ripple/layout.py index cdb78dac9f..46ba7a1fc3 100644 --- a/core/src/apps/ripple/layout.py +++ b/core/src/apps/ripple/layout.py @@ -1,7 +1,7 @@ from trezor import ui from trezor.messages import ButtonRequestType from trezor.strings import format_amount -from trezor.ui.text import Text +from trezor.ui.components.tt.text import Text from apps.common.confirm import require_confirm, require_hold_to_confirm from apps.common.layout import split_address diff --git a/core/src/apps/stellar/layout.py b/core/src/apps/stellar/layout.py index 6261245712..bd4f12834b 100644 --- a/core/src/apps/stellar/layout.py +++ b/core/src/apps/stellar/layout.py @@ -1,6 +1,6 @@ from trezor import strings, ui, utils from trezor.messages import ButtonRequestType -from trezor.ui.text import Text +from trezor.ui.components.tt.text import Text from apps.common.confirm import require_confirm, require_hold_to_confirm diff --git a/core/src/apps/stellar/operations/layout.py b/core/src/apps/stellar/operations/layout.py index f528376563..13c36b9ea1 100644 --- a/core/src/apps/stellar/operations/layout.py +++ b/core/src/apps/stellar/operations/layout.py @@ -13,7 +13,7 @@ from trezor.messages.StellarManageOfferOp import StellarManageOfferOp from trezor.messages.StellarPathPaymentOp import StellarPathPaymentOp from trezor.messages.StellarPaymentOp import StellarPaymentOp from trezor.messages.StellarSetOptionsOp import StellarSetOptionsOp -from trezor.ui.text import Text +from trezor.ui.components.tt.text import Text from trezor.wire import ProcessError from .. import consts, helpers diff --git a/core/src/apps/tezos/get_public_key.py b/core/src/apps/tezos/get_public_key.py index 7b40b47a5c..f7ebe4f481 100644 --- a/core/src/apps/tezos/get_public_key.py +++ b/core/src/apps/tezos/get_public_key.py @@ -1,7 +1,7 @@ from trezor import ui from trezor.messages import ButtonRequestType from trezor.messages.TezosPublicKey import TezosPublicKey -from trezor.ui.text import Text +from trezor.ui.components.tt.text import Text from trezor.utils import chunks from apps.common import paths, seed diff --git a/core/src/apps/tezos/layout.py b/core/src/apps/tezos/layout.py index 460efa3021..41f1be629c 100644 --- a/core/src/apps/tezos/layout.py +++ b/core/src/apps/tezos/layout.py @@ -1,8 +1,8 @@ from trezor import ui from trezor.messages import ButtonRequestType from trezor.strings import format_amount -from trezor.ui.scroll import Paginated -from trezor.ui.text import Text +from trezor.ui.components.tt.scroll import Paginated +from trezor.ui.components.tt.text import Text from trezor.utils import chunks from apps.common.confirm import require_confirm, require_hold_to_confirm diff --git a/core/src/apps/webauthn/add_resident_credential.py b/core/src/apps/webauthn/add_resident_credential.py index c00c64665d..08135cbe4d 100644 --- a/core/src/apps/webauthn/add_resident_credential.py +++ b/core/src/apps/webauthn/add_resident_credential.py @@ -2,7 +2,7 @@ import storage.device from trezor import ui, wire from trezor.messages.Success import Success from trezor.messages.WebAuthnAddResidentCredential import WebAuthnAddResidentCredential -from trezor.ui.text import Text +from trezor.ui.components.tt.text import Text from apps.common.confirm import require_confirm diff --git a/core/src/apps/webauthn/confirm.py b/core/src/apps/webauthn/confirm.py index dac83df164..7381e85d46 100644 --- a/core/src/apps/webauthn/confirm.py +++ b/core/src/apps/webauthn/confirm.py @@ -1,5 +1,5 @@ from trezor import ui -from trezor.ui.text import text_center_trim_left, text_center_trim_right +from trezor.ui.components.tt.text import text_center_trim_left, text_center_trim_right if False: from typing import Optional diff --git a/core/src/apps/webauthn/fido2.py b/core/src/apps/webauthn/fido2.py index ec0bcd2048..b4478ff88c 100644 --- a/core/src/apps/webauthn/fido2.py +++ b/core/src/apps/webauthn/fido2.py @@ -8,9 +8,14 @@ import storage.resident_credentials from trezor import config, io, log, loop, ui, utils, workflow from trezor.crypto import aes, der, hashlib, hmac, random from trezor.crypto.curve import nist256p1 -from trezor.ui.confirm import CONFIRMED, Confirm, ConfirmPageable, Pageable +from trezor.ui.components.tt.confirm import ( + CONFIRMED, + Confirm, + ConfirmPageable, + Pageable, +) +from trezor.ui.components.tt.text import Text from trezor.ui.popup import Popup -from trezor.ui.text import Text from apps.base import set_homescreen from apps.common import cbor diff --git a/core/src/apps/webauthn/list_resident_credentials.py b/core/src/apps/webauthn/list_resident_credentials.py index 538b7b8426..4b1576232f 100644 --- a/core/src/apps/webauthn/list_resident_credentials.py +++ b/core/src/apps/webauthn/list_resident_credentials.py @@ -4,7 +4,7 @@ from trezor.messages.WebAuthnCredentials import WebAuthnCredentials from trezor.messages.WebAuthnListResidentCredentials import ( WebAuthnListResidentCredentials, ) -from trezor.ui.text import Text +from trezor.ui.components.tt.text import Text from apps.common.confirm import require_confirm diff --git a/core/src/trezor/ui/components/common/__init__.py b/core/src/trezor/ui/components/common/__init__.py new file mode 100644 index 0000000000..40f9dc493e --- /dev/null +++ b/core/src/trezor/ui/components/common/__init__.py @@ -0,0 +1,18 @@ +""" +The components/common module contains code that is used by both components/tt +and components/t1. +""" + +if False: + from typing import List + + +def break_path_to_lines(path_str: str, per_line: int) -> List[str]: + lines = [] + while len(path_str) > per_line: + i = path_str[:per_line].rfind("/") + lines.append(path_str[:i]) + path_str = path_str[i:] + lines.append(path_str) + + return lines diff --git a/core/src/trezor/ui/components/common/confirm.py b/core/src/trezor/ui/components/common/confirm.py new file mode 100644 index 0000000000..09da8e7864 --- /dev/null +++ b/core/src/trezor/ui/components/common/confirm.py @@ -0,0 +1,45 @@ +from trezor import loop, ui + +if __debug__: + from apps.debug import confirm_signal + +if False: + from typing import List, Tuple, Optional + +CONFIRMED = object() +CANCELLED = object() +INFO = object() + + +class ConfirmBase(ui.Layout): + def __init__( + self, + content: ui.Component, + confirm: Optional[ui.Component] = None, + cancel: Optional[ui.Component] = None, + ) -> None: + self.content = content + self.confirm = confirm + self.cancel = cancel + + def dispatch(self, event: int, x: int, y: int) -> None: + super().dispatch(event, x, y) + self.content.dispatch(event, x, y) + if self.confirm is not None: + self.confirm.dispatch(event, x, y) + if self.cancel is not None: + self.cancel.dispatch(event, x, y) + + def on_confirm(self) -> None: + raise ui.Result(CONFIRMED) + + def on_cancel(self) -> None: + raise ui.Result(CANCELLED) + + if __debug__: + + def read_content(self) -> List[str]: + return self.content.read_content() + + def create_tasks(self) -> Tuple[loop.Task, ...]: + return super().create_tasks() + (confirm_signal(),) diff --git a/core/src/trezor/ui/text.py b/core/src/trezor/ui/components/common/text.py similarity index 95% rename from core/src/trezor/ui/text.py rename to core/src/trezor/ui/components/common/text.py index 883605e526..2db3dd5868 100644 --- a/core/src/trezor/ui/text.py +++ b/core/src/trezor/ui/components/common/text.py @@ -2,14 +2,18 @@ from micropython import const from trezor import ui +from ...constants import ( + TEXT_HEADER_HEIGHT, + TEXT_LINE_HEIGHT, + TEXT_LINE_HEIGHT_HALF, + TEXT_MARGIN_LEFT, + TEXT_MAX_LINES, +) + if False: from typing import Any, List, Optional, Union -TEXT_HEADER_HEIGHT = const(48) -TEXT_LINE_HEIGHT = const(26) -TEXT_LINE_HEIGHT_HALF = const(13) -TEXT_MARGIN_LEFT = const(14) -TEXT_MAX_LINES = const(5) + TextContent = Union[str, int] # needs to be different from all colors and font ids BR = const(-256) @@ -17,10 +21,6 @@ BR_HALF = const(-257) _FONTS = (ui.NORMAL, ui.BOLD, ui.MONO) -if False: - TextContent = Union[str, int] - - DASH_WIDTH = ui.display.text_width("-", ui.BOLD) @@ -360,7 +360,7 @@ if __debug__: self.screen_contents.append(string[start : start + length]) -class Text(ui.Component): +class TextBase(ui.Component): def __init__( self, header_text: str, @@ -406,25 +406,7 @@ class Text(ui.Component): self.content.append(BR_HALF) def on_render(self) -> None: - if self.repaint: - ui.header( - self.header_text, - self.header_icon, - ui.TITLE_GREY, - ui.BG, - self.icon_color, - ) - render_text( - self.content, - self.new_lines, - self.max_lines, - item_offset=self.content_offset, - char_offset=self.char_offset, - break_words=self.break_words, - line_width=self.line_width, - render_page_overflow=self.render_page_overflow, - ) - self.repaint = False + pass if __debug__: @@ -437,7 +419,7 @@ class Text(ui.Component): self.on_render() finally: self.repaint = should_repaint - return display_mock.screen_contents + return [self.header_text] + display_mock.screen_contents LABEL_LEFT = const(0) diff --git a/core/src/trezor/ui/button.py b/core/src/trezor/ui/components/tt/button.py similarity index 100% rename from core/src/trezor/ui/button.py rename to core/src/trezor/ui/components/tt/button.py diff --git a/core/src/trezor/ui/checklist.py b/core/src/trezor/ui/components/tt/checklist.py similarity index 96% rename from core/src/trezor/ui/checklist.py rename to core/src/trezor/ui/components/tt/checklist.py index f9ac187851..a5185ec63b 100644 --- a/core/src/trezor/ui/checklist.py +++ b/core/src/trezor/ui/components/tt/checklist.py @@ -1,7 +1,8 @@ from micropython import const from trezor import res, ui -from trezor.ui.text import TEXT_HEADER_HEIGHT, TEXT_LINE_HEIGHT + +from ...constants import TEXT_HEADER_HEIGHT, TEXT_LINE_HEIGHT if False: from typing import Iterable, List, Union diff --git a/core/src/trezor/ui/confirm.py b/core/src/trezor/ui/components/tt/confirm.py similarity index 84% rename from core/src/trezor/ui/confirm.py rename to core/src/trezor/ui/components/tt/confirm.py index c3b09deffa..9129969b4d 100644 --- a/core/src/trezor/ui/confirm.py +++ b/core/src/trezor/ui/components/tt/confirm.py @@ -1,29 +1,21 @@ from micropython import const from trezor import loop, res, ui, utils -from trezor.ui.button import ( - Button, - ButtonAbort, - ButtonCancel, - ButtonConfirm, - ButtonDefault, -) from trezor.ui.loader import Loader, LoaderDefault +from ..common.confirm import CANCELLED, CONFIRMED, INFO, ConfirmBase +from .button import Button, ButtonAbort, ButtonCancel, ButtonConfirm, ButtonDefault + if __debug__: from apps.debug import swipe_signal, confirm_signal if False: - from typing import Any, Optional, List, Tuple - from trezor.ui.button import ButtonContent, ButtonStyleType + from typing import Any, List, Tuple, Optional + from .button import ButtonContent, ButtonStyleType from trezor.ui.loader import LoaderStyleType -CONFIRMED = object() -CANCELLED = object() -INFO = object() - -class Confirm(ui.Layout): +class Confirm(ConfirmBase): DEFAULT_CONFIRM = res.load(ui.ICON_CONFIRM) DEFAULT_CONFIRM_STYLE = ButtonConfirm DEFAULT_CANCEL = res.load(ui.ICON_CANCEL) @@ -38,8 +30,9 @@ class Confirm(ui.Layout): cancel_style: ButtonStyleType = DEFAULT_CANCEL_STYLE, major_confirm: bool = False, ) -> None: - super().__init__() self.content = content + button_confirm: Optional[Button] = None + button_cancel: Optional[Button] = None if confirm is not None: if cancel is None: @@ -48,10 +41,8 @@ class Confirm(ui.Layout): area = ui.grid(13, cells_x=2) else: area = ui.grid(9, n_x=2) - self.confirm: Optional[Button] = Button(area, confirm, confirm_style) - self.confirm.on_click = self.on_confirm # type: ignore - else: - self.confirm = None + button_confirm = Button(area, confirm, confirm_style) + button_confirm.on_click = self.on_confirm # type: ignore if cancel is not None: if confirm is None: @@ -60,32 +51,10 @@ class Confirm(ui.Layout): area = ui.grid(12, cells_x=1) else: area = ui.grid(8, n_x=2) - self.cancel: Optional[Button] = Button(area, cancel, cancel_style) - self.cancel.on_click = self.on_cancel # type: ignore - else: - self.cancel = None + button_cancel = Button(area, cancel, cancel_style) + button_cancel.on_click = self.on_cancel # type: ignore - def dispatch(self, event: int, x: int, y: int) -> None: - super().dispatch(event, x, y) - self.content.dispatch(event, x, y) - if self.confirm is not None: - self.confirm.dispatch(event, x, y) - if self.cancel is not None: - self.cancel.dispatch(event, x, y) - - def on_confirm(self) -> None: - raise ui.Result(CONFIRMED) - - def on_cancel(self) -> None: - raise ui.Result(CANCELLED) - - if __debug__: - - def read_content(self) -> List[str]: - return self.content.read_content() - - def create_tasks(self) -> Tuple[loop.Task, ...]: - return super().create_tasks() + (confirm_signal(),) + super().__init__(content, button_confirm, button_cancel) class Pageable: @@ -117,7 +86,7 @@ class ConfirmPageable(Confirm): self.pageable = pageable async def handle_paging(self) -> None: - from trezor.ui.swipe import SWIPE_HORIZONTAL, SWIPE_LEFT, SWIPE_RIGHT, Swipe + from .swipe import SWIPE_HORIZONTAL, SWIPE_LEFT, SWIPE_RIGHT, Swipe if self.pageable.is_first(): directions = SWIPE_LEFT diff --git a/core/src/trezor/ui/info.py b/core/src/trezor/ui/components/tt/info.py similarity index 90% rename from core/src/trezor/ui/info.py rename to core/src/trezor/ui/components/tt/info.py index ededd977cd..e8c08b158b 100644 --- a/core/src/trezor/ui/info.py +++ b/core/src/trezor/ui/components/tt/info.py @@ -1,11 +1,13 @@ from trezor import res, ui -from trezor.ui.button import Button, ButtonConfirm -from trezor.ui.confirm import CONFIRMED -from trezor.ui.text import TEXT_LINE_HEIGHT, TEXT_MARGIN_LEFT, render_text + +from ...constants import TEXT_LINE_HEIGHT, TEXT_MARGIN_LEFT +from .button import Button, ButtonConfirm +from .confirm import CONFIRMED +from .text import render_text if False: from typing import Type - from trezor.ui.button import ButtonContent + from .button import ButtonContent class DefaultInfoConfirm: diff --git a/core/src/trezor/ui/num_input.py b/core/src/trezor/ui/components/tt/num_input.py similarity index 94% rename from core/src/trezor/ui/num_input.py rename to core/src/trezor/ui/components/tt/num_input.py index a5005db9c0..05f979fd33 100644 --- a/core/src/trezor/ui/num_input.py +++ b/core/src/trezor/ui/components/tt/num_input.py @@ -1,6 +1,7 @@ from trezor import ui -from trezor.ui.button import Button -from trezor.ui.text import LABEL_CENTER, Label + +from .button import Button +from .text import LABEL_CENTER, Label class NumInput(ui.Component): diff --git a/core/src/trezor/ui/passphrase.py b/core/src/trezor/ui/components/tt/passphrase.py similarity index 97% rename from core/src/trezor/ui/passphrase.py rename to core/src/trezor/ui/components/tt/passphrase.py index b8612cb0d0..d3c6646d88 100644 --- a/core/src/trezor/ui/passphrase.py +++ b/core/src/trezor/ui/components/tt/passphrase.py @@ -2,12 +2,13 @@ from micropython import const from trezor import io, loop, res, ui, workflow from trezor.ui import display -from trezor.ui.button import Button, ButtonClear, ButtonConfirm -from trezor.ui.swipe import SWIPE_HORIZONTAL, SWIPE_LEFT, Swipe + +from .button import Button, ButtonClear, ButtonConfirm +from .swipe import SWIPE_HORIZONTAL, SWIPE_LEFT, Swipe if False: from typing import Iterable, List, Optional, Tuple - from trezor.ui.button import ButtonContent, ButtonStyleStateType + from .button import ButtonContent, ButtonStyleStateType SPACE = res.load(ui.ICON_SPACE) diff --git a/core/src/trezor/ui/pin.py b/core/src/trezor/ui/components/tt/pin.py similarity index 97% rename from core/src/trezor/ui/pin.py rename to core/src/trezor/ui/components/tt/pin.py index 16a6d3d265..ab73893805 100644 --- a/core/src/trezor/ui/pin.py +++ b/core/src/trezor/ui/components/tt/pin.py @@ -3,13 +3,8 @@ from micropython import const from trezor import config, res, ui from trezor.crypto import random from trezor.ui import display -from trezor.ui.button import ( - Button, - ButtonCancel, - ButtonClear, - ButtonConfirm, - ButtonMono, -) + +from .button import Button, ButtonCancel, ButtonClear, ButtonConfirm, ButtonMono if False: from trezor import loop diff --git a/core/src/trezor/ui/scroll.py b/core/src/trezor/ui/components/tt/scroll.py similarity index 97% rename from core/src/trezor/ui/scroll.py rename to core/src/trezor/ui/components/tt/scroll.py index 781b2f920b..13ba788132 100644 --- a/core/src/trezor/ui/scroll.py +++ b/core/src/trezor/ui/components/tt/scroll.py @@ -1,9 +1,10 @@ from micropython import const from trezor import loop, res, ui, utils -from trezor.ui.button import Button, ButtonCancel, ButtonConfirm, ButtonDefault -from trezor.ui.confirm import CANCELLED, CONFIRMED -from trezor.ui.swipe import SWIPE_DOWN, SWIPE_UP, SWIPE_VERTICAL, Swipe + +from .button import Button, ButtonCancel, ButtonConfirm, ButtonDefault +from .confirm import CANCELLED, CONFIRMED +from .swipe import SWIPE_DOWN, SWIPE_UP, SWIPE_VERTICAL, Swipe if __debug__: from apps.debug import confirm_signal, swipe_signal, notify_layout_change diff --git a/core/src/trezor/ui/swipe.py b/core/src/trezor/ui/components/tt/swipe.py similarity index 100% rename from core/src/trezor/ui/swipe.py rename to core/src/trezor/ui/components/tt/swipe.py diff --git a/core/src/trezor/ui/components/tt/text.py b/core/src/trezor/ui/components/tt/text.py new file mode 100644 index 0000000000..28b2c4f0dd --- /dev/null +++ b/core/src/trezor/ui/components/tt/text.py @@ -0,0 +1,139 @@ +from micropython import const + +from trezor import res, ui +from trezor.ui import display, style + +from ..common.text import ( # noqa: F401 + BR, + BR_HALF, + TEXT_MAX_LINES, + Span, + TextBase, + render_text, +) + +if False: + from typing import List + + +def header( + title: str, + icon: str = style.ICON_DEFAULT, + fg: int = style.FG, + bg: int = style.BG, + ifg: int = style.GREEN, +) -> None: + if icon is not None: + display.icon(14, 15, res.load(icon), ifg, bg) + display.text(44, 35, title, ui.BOLD, fg, bg) + + +class Text(TextBase): + def on_render(self) -> None: + if self.repaint: + header( + self.header_text, + self.header_icon, + ui.TITLE_GREY, + ui.BG, + self.icon_color, + ) + render_text( + self.content, + self.new_lines, + self.max_lines, + item_offset=self.content_offset, + char_offset=self.char_offset, + break_words=self.break_words, + line_width=self.line_width, + render_page_overflow=self.render_page_overflow, + ) + self.repaint = False + + +LABEL_LEFT = const(0) +LABEL_CENTER = const(1) +LABEL_RIGHT = const(2) + + +class Label(ui.Component): + def __init__( + self, + area: ui.Area, + content: str, + align: int = LABEL_LEFT, + style: int = ui.NORMAL, + ) -> None: + super().__init__() + self.area = area + self.content = content + self.align = align + self.style = style + + def on_render(self) -> None: + if self.repaint: + align = self.align + ax, ay, aw, ah = self.area + ui.display.bar(ax, ay, aw, ah, ui.BG) + tx = ax + aw // 2 + ty = ay + ah // 2 + 8 + if align is LABEL_LEFT: + ui.display.text(tx, ty, self.content, self.style, ui.FG, ui.BG) + elif align is LABEL_CENTER: + ui.display.text_center(tx, ty, self.content, self.style, ui.FG, ui.BG) + elif align is LABEL_RIGHT: + ui.display.text_right(tx, ty, self.content, self.style, ui.FG, ui.BG) + self.repaint = False + + if __debug__: + + def read_content(self) -> List[str]: + return [self.content] + + +def text_center_trim_left( + x: int, y: int, text: str, font: int = ui.NORMAL, width: int = ui.WIDTH - 16 +) -> None: + if ui.display.text_width(text, font) <= width: + ui.display.text_center(x, y, text, font, ui.FG, ui.BG) + return + + ELLIPSIS_WIDTH = ui.display.text_width("...", ui.BOLD) + if width < ELLIPSIS_WIDTH: + return + + text_length = 0 + for i in range(1, len(text)): + if ui.display.text_width(text[-i:], font) + ELLIPSIS_WIDTH > width: + text_length = i - 1 + break + + text_width = ui.display.text_width(text[-text_length:], font) + x -= (text_width + ELLIPSIS_WIDTH) // 2 + ui.display.text(x, y, "...", ui.BOLD, ui.GREY, ui.BG) + x += ELLIPSIS_WIDTH + ui.display.text(x, y, text[-text_length:], font, ui.FG, ui.BG) + + +def text_center_trim_right( + x: int, y: int, text: str, font: int = ui.NORMAL, width: int = ui.WIDTH - 16 +) -> None: + if ui.display.text_width(text, font) <= width: + ui.display.text_center(x, y, text, font, ui.FG, ui.BG) + return + + ELLIPSIS_WIDTH = ui.display.text_width("...", ui.BOLD) + if width < ELLIPSIS_WIDTH: + return + + text_length = 0 + for i in range(1, len(text)): + if ui.display.text_width(text[:i], font) + ELLIPSIS_WIDTH > width: + text_length = i - 1 + break + + text_width = ui.display.text_width(text[:text_length], font) + x -= (text_width + ELLIPSIS_WIDTH) // 2 + ui.display.text(x, y, text[:text_length], font, ui.FG, ui.BG) + x += text_width + ui.display.text(x, y, "...", ui.BOLD, ui.GREY, ui.BG) diff --git a/core/src/trezor/ui/word_select.py b/core/src/trezor/ui/components/tt/word_select.py similarity index 97% rename from core/src/trezor/ui/word_select.py rename to core/src/trezor/ui/components/tt/word_select.py index a9ce2e4aa7..f3b600a142 100644 --- a/core/src/trezor/ui/word_select.py +++ b/core/src/trezor/ui/components/tt/word_select.py @@ -1,5 +1,6 @@ from trezor import ui -from trezor.ui.button import Button + +from .button import Button if False: from trezor import loop diff --git a/core/src/trezor/ui/constants/__init__.py b/core/src/trezor/ui/constants/__init__.py new file mode 100644 index 0000000000..ef1cf9b8e0 --- /dev/null +++ b/core/src/trezor/ui/constants/__init__.py @@ -0,0 +1,8 @@ +from trezor import utils + +if utils.MODEL == "1": + from .t1 import * # noqa: F401,F403 +elif utils.MODEL == "T": + from .tt import * # noqa: F401,F403 +else: + raise ValueError("Unknown Trezor model") diff --git a/core/src/trezor/ui/constants/t1.py b/core/src/trezor/ui/constants/t1.py new file mode 100644 index 0000000000..bc382d0415 --- /dev/null +++ b/core/src/trezor/ui/constants/t1.py @@ -0,0 +1,7 @@ +from micropython import const + +TEXT_HEADER_HEIGHT = const(13) +TEXT_LINE_HEIGHT = const(9) +TEXT_LINE_HEIGHT_HALF = const(4) +TEXT_MARGIN_LEFT = const(0) +TEXT_MAX_LINES = const(4) diff --git a/core/src/trezor/ui/constants/tt.py b/core/src/trezor/ui/constants/tt.py new file mode 100644 index 0000000000..8676796c38 --- /dev/null +++ b/core/src/trezor/ui/constants/tt.py @@ -0,0 +1,7 @@ +from micropython import const + +TEXT_HEADER_HEIGHT = const(48) +TEXT_LINE_HEIGHT = const(26) +TEXT_LINE_HEIGHT_HALF = const(13) +TEXT_MARGIN_LEFT = const(14) +TEXT_MAX_LINES = const(5) diff --git a/core/tests/test_trezor.ui.text.py b/core/tests/test_trezor.ui.text.py index 086cf0bb57..823a11b947 100644 --- a/core/tests/test_trezor.ui.text.py +++ b/core/tests/test_trezor.ui.text.py @@ -2,7 +2,8 @@ import mock from common import * from trezor import ui -from trezor.ui import text, display +from trezor.ui import display +from trezor.ui.components.common import text if False: from typing import List, Tuple