diff --git a/core/embed/rust/src/ui/model_mercury/layout.rs b/core/embed/rust/src/ui/model_mercury/layout.rs index a0642a1f27..3b2069fd3e 100644 --- a/core/embed/rust/src/ui/model_mercury/layout.rs +++ b/core/embed/rust/src/ui/model_mercury/layout.rs @@ -1,64 +1,25 @@ -use core::{cmp::Ordering, convert::TryInto}; -use heapless::Vec; +use core::convert::TryInto; -use super::{ - component::{ - AddressDetails, Bip39Input, CoinJoinProgress, Frame, FrameMsg, Homescreen, HomescreenMsg, - Lockscreen, MnemonicInput, MnemonicKeyboard, MnemonicKeyboardMsg, PinKeyboard, - PinKeyboardMsg, Progress, PromptScreen, SelectWordCount, SelectWordCountMsg, Slip39Input, - StatusScreen, SwipeUpScreen, SwipeUpScreenMsg, VerticalMenu, VerticalMenuChoiceMsg, - }, - flow::{self}, - theme, +use super::component::{ + AddressDetails, CoinJoinProgress, Frame, FrameMsg, Homescreen, HomescreenMsg, Lockscreen, + MnemonicInput, MnemonicKeyboard, MnemonicKeyboardMsg, PinKeyboard, PinKeyboardMsg, Progress, + PromptScreen, SelectWordCount, SelectWordCountMsg, StatusScreen, SwipeUpScreen, + SwipeUpScreenMsg, VerticalMenu, VerticalMenuChoiceMsg, }; use crate::{ - error::{value_error, Error}, - io::BinaryData, - micropython::{ - iter::IterBuf, - macros::{obj_fn_0, obj_fn_1, obj_fn_kw, obj_module}, - map::Map, - module::Module, - obj::Obj, - qstr::Qstr, - util, - }, - strutil::TString, - translations::TR, - trezorhal::model, + error::Error, + micropython::{macros::obj_module, module::Module, obj::Obj, qstr::Qstr}, ui::{ - backlight::BACKLIGHT_LEVELS_OBJ, component::{ - base::ComponentExt, - connect::Connect, - swipe_detect::SwipeSettings, - text::{ - op::OpTextLayout, - paragraphs::{ - Checklist, Paragraph, ParagraphSource, ParagraphVecLong, ParagraphVecShort, - Paragraphs, VecExt, - }, - TextStyle, - }, - Border, CachedJpeg, Component, FormattedText, Never, Timeout, + text::paragraphs::{ParagraphSource, Paragraphs}, + Component, Never, Timeout, }, flow::Swipable, - geometry::{self, Direction}, layout::{ - base::LAYOUT_STATE, - obj::{ComponentMsgObj, LayoutObj, ATTACH_TYPE_OBJ}, - result::{CANCELLED, CONFIRMED, INFO}, - util::{upy_disable_animation, PropsList, RecoveryType}, - }, - model_mercury::{ - component::{check_homescreen_format, SwipeContent}, - flow::{ - new_confirm_action_simple, - util::{ConfirmBlobParams, ShowInfoParams}, - ConfirmActionExtra, ConfirmActionMenuStrings, ConfirmActionStrings, - }, - theme::ICON_BULLET_CHECKMARK, + obj::ComponentMsgObj, + result::{CANCELLED, CONFIRMED}, }, + model_mercury::component::SwipeContent, }, }; diff --git a/core/embed/rust/src/ui/model_tr/layout.rs b/core/embed/rust/src/ui/model_tr/layout.rs index c59af4b2f5..26c60ea783 100644 --- a/core/embed/rust/src/ui/model_tr/layout.rs +++ b/core/embed/rust/src/ui/model_tr/layout.rs @@ -1,55 +1,23 @@ -use core::{cmp::Ordering, convert::TryInto}; +use core::convert::TryInto; -use heapless::Vec; - -use super::{ - component::{ - AddressDetails, ButtonActions, ButtonDetails, ButtonLayout, ButtonPage, CancelConfirmMsg, - CancelInfoConfirmMsg, CoinJoinProgress, ConfirmHomescreen, Flow, FlowPages, Frame, - Homescreen, Lockscreen, NumberInput, Page, PassphraseEntry, PinEntry, Progress, - ScrollableContent, ScrollableFrame, ShareWords, ShowMore, SimpleChoice, WordlistEntry, - WordlistType, - }, - constant, theme, +use super::component::{ + AddressDetails, ButtonPage, CancelConfirmMsg, CancelInfoConfirmMsg, CoinJoinProgress, + ConfirmHomescreen, Flow, Frame, Homescreen, Lockscreen, NumberInput, Page, PassphraseEntry, + PinEntry, Progress, ScrollableContent, ScrollableFrame, ShowMore, SimpleChoice, WordlistEntry, }; use crate::{ error::Error, - maybe_trace::MaybeTrace, - micropython::{ - gc::Gc, - iter::IterBuf, - list::List, - macros::{obj_fn_0, obj_fn_1, obj_fn_kw, obj_module}, - map::Map, - module::Module, - obj::Obj, - qstr::Qstr, - util, - }, - strutil::TString, - translations::TR, - trezorhal::model, + micropython::{macros::obj_module, map::Map, module::Module, obj::Obj, qstr::Qstr}, ui::{ component::{ base::Component, - connect::Connect, paginated::{PageMsg, Paginate}, - text::{ - op::OpTextLayout, - paragraphs::{ - Checklist, Paragraph, ParagraphSource, ParagraphVecLong, ParagraphVecShort, - Paragraphs, VecExt, - }, - TextStyle, - }, - ComponentExt, FormattedText, Label, LineBreaking, Never, Timeout, + text::paragraphs::{ParagraphSource, Paragraphs}, + Never, Timeout, }, - display::Font, - geometry, layout::{ - obj::{ComponentMsgObj, LayoutObj}, + obj::ComponentMsgObj, result::{CANCELLED, CONFIRMED, INFO}, - util::{ConfirmBlob, RecoveryType}, }, }, }; @@ -233,43 +201,6 @@ impl ComponentMsgObj for super::component::bl_confirm::Confirm<'_> { } } -/// Function to create and call a `ButtonPage` dialog based on paginable content -/// (e.g. `Paragraphs` or `FormattedText`). -/// Has optional title (supply empty `TString` for that) and hold-to-confirm -/// functionality. -fn content_in_button_page( - title: TString<'static>, - content: T, - verb: TString<'static>, - verb_cancel: Option>, - hold: bool, -) -> Result { - // Left button - icon, text or nothing. - let cancel_btn = verb_cancel.map(ButtonDetails::from_text_possible_icon); - - // Right button - text or nothing. - // Optional HoldToConfirm - let mut confirm_btn = if !verb.is_empty() { - Some(ButtonDetails::text(verb)) - } else { - None - }; - if hold { - confirm_btn = confirm_btn.map(|btn| btn.with_default_duration()); - } - - let content = ButtonPage::new(content, theme::BG) - .with_cancel_btn(cancel_btn) - .with_confirm_btn(confirm_btn); - - let mut frame = ScrollableFrame::new(content); - if !title.is_empty() { - frame = frame.with_title(title); - } - let obj = LayoutObj::new(frame)?; - - Ok(obj.into()) -} #[no_mangle] pub static mp_module_trezorui2: Module = obj_module! { /// from trezor import utils diff --git a/core/embed/rust/src/ui/model_tt/layout.rs b/core/embed/rust/src/ui/model_tt/layout.rs index 5a382e23d9..a6e8681db2 100644 --- a/core/embed/rust/src/ui/model_tt/layout.rs +++ b/core/embed/rust/src/ui/model_tt/layout.rs @@ -1,59 +1,27 @@ -use core::{cmp::Ordering, convert::TryInto}; +use core::convert::TryInto; -use super::{ - component::{ - AddressDetails, Bip39Input, Button, ButtonMsg, ButtonPage, ButtonStyleSheet, - CancelConfirmMsg, CancelInfoConfirmMsg, CoinJoinProgress, Dialog, DialogMsg, FidoConfirm, - FidoMsg, Frame, FrameMsg, Homescreen, HomescreenMsg, IconDialog, Lockscreen, MnemonicInput, - MnemonicKeyboard, MnemonicKeyboardMsg, NumberInputDialog, NumberInputDialogMsg, - PassphraseKeyboard, PassphraseKeyboardMsg, PinKeyboard, PinKeyboardMsg, Progress, - SelectWordCount, SelectWordCountMsg, SelectWordMsg, SetBrightnessDialog, SimplePage, - Slip39Input, - }, - theme, +use super::component::{ + AddressDetails, ButtonPage, CancelConfirmMsg, CancelInfoConfirmMsg, CoinJoinProgress, Dialog, + DialogMsg, FidoConfirm, FidoMsg, Frame, FrameMsg, Homescreen, HomescreenMsg, IconDialog, + Lockscreen, MnemonicInput, MnemonicKeyboard, MnemonicKeyboardMsg, NumberInputDialog, + NumberInputDialogMsg, PassphraseKeyboard, PassphraseKeyboardMsg, PinKeyboard, PinKeyboardMsg, + Progress, SelectWordCountMsg, SelectWordMsg, SetBrightnessDialog, SimplePage, }; use crate::{ - error::{value_error, Error}, - io::BinaryData, - micropython::{ - gc::Gc, - iter::IterBuf, - list::List, - macros::{obj_fn_1, obj_fn_kw, obj_module}, - map::Map, - module::Module, - obj::Obj, - qstr::Qstr, - util, - }, + error::Error, + micropython::{macros::obj_module, map::Map, module::Module, obj::Obj, qstr::Qstr, util}, strutil::TString, - translations::TR, - trezorhal::model, ui::{ component::{ - base::ComponentExt, - connect::Connect, - image::BlendedImage, - jpeg::Jpeg, paginated::{PageMsg, Paginate}, placed::GridPlaced, - text::{ - op::OpTextLayout, - paragraphs::{ - Checklist, Paragraph, ParagraphSource, ParagraphVecLong, ParagraphVecShort, - Paragraphs, VecExt, - }, - TextStyle, - }, - Border, Component, Empty, FormattedText, Label, Never, Timeout, + text::paragraphs::{ParagraphSource, Paragraphs}, + Component, FormattedText, Never, Timeout, }, - geometry, layout::{ - obj::{ComponentMsgObj, LayoutObj}, + obj::ComponentMsgObj, result::{CANCELLED, CONFIRMED, INFO}, - util::{ConfirmBlob, PropsList, RecoveryType}, }, - model_tt::component::check_homescreen_format, }, }; @@ -317,59 +285,10 @@ impl ComponentMsgObj for super::component::bl_confirm::Confirm<'_> { } } - -#[cfg(test)] -mod tests { - use serde_json; - - use crate::{ - trace::tests::trace, - ui::{component::text::op::OpTextLayout, geometry::Rect, model_tt::constant}, - }; - - use super::*; - - const SCREEN: Rect = constant::screen().inset(theme::borders()); - - #[test] - fn trace_example_layout() { - let buttons = Button::cancel_confirm( - Button::with_text("Left".into()), - Button::with_text("Right".into()), - false, - ); - - let ops = OpTextLayout::new(theme::TEXT_NORMAL) - .text_normal("Testing text layout, with some text, and some more text. And ") - .text_bold_upper("parameters!"); - let formatted = FormattedText::new(ops); - let mut layout = Dialog::new(formatted, buttons); - layout.place(SCREEN); - - let expected = serde_json::json!({ - "component": "Dialog", - "content": { - "component": "FormattedText", - "text": ["Testing text layout, with", "\n", "some text, and some", "\n", - "more text. And ", "parame", "-", "\n", "ters!"], - "fits": true, - }, - "controls": { - "component": "FixedHeightBar", - "inner": { - "component": "Split", - "first": { - "component": "Button", - "text": "Left", - }, - "second": { - "component": "Button", - "text": "Right", - }, - }, - }, - }); - - assert_eq!(trace(&layout), expected); - } -} +#[no_mangle] +pub static mp_module_trezorui2: Module = obj_module! { + /// from trezor import utils + /// from trezorui_api import * + /// + Qstr::MP_QSTR___name__ => Qstr::MP_QSTR_trezorui2.to_obj(), +}; diff --git a/core/embed/rust/src/ui/model_tt/ui_features_fw.rs b/core/embed/rust/src/ui/model_tt/ui_features_fw.rs index 1c23d897ee..885f998399 100644 --- a/core/embed/rust/src/ui/model_tt/ui_features_fw.rs +++ b/core/embed/rust/src/ui/model_tt/ui_features_fw.rs @@ -1348,3 +1348,62 @@ impl ConfirmBlobParams { LayoutObj::new(frame) } } + +#[cfg(test)] +mod tests { + use serde_json; + + use crate::{ + trace::tests::trace, + ui::{ + component::text::op::OpTextLayout, component::Component, geometry::Rect, + model_tt::constant, + }, + }; + + use super::*; + + const SCREEN: Rect = constant::screen().inset(theme::borders()); + + #[test] + fn trace_example_layout() { + let buttons = Button::cancel_confirm( + Button::with_text("Left".into()), + Button::with_text("Right".into()), + false, + ); + + let ops = OpTextLayout::new(theme::TEXT_NORMAL) + .text_normal("Testing text layout, with some text, and some more text. And ") + .text_bold_upper("parameters!"); + let formatted = FormattedText::new(ops); + let mut layout = Dialog::new(formatted, buttons); + layout.place(SCREEN); + + let expected = serde_json::json!({ + "component": "Dialog", + "content": { + "component": "FormattedText", + "text": ["Testing text layout, with", "\n", "some text, and some", "\n", + "more text. And ", "parame", "-", "\n", "ters!"], + "fits": true, + }, + "controls": { + "component": "FixedHeightBar", + "inner": { + "component": "Split", + "first": { + "component": "Button", + "text": "Left", + }, + "second": { + "component": "Button", + "text": "Right", + }, + }, + }, + }); + + assert_eq!(trace(&layout), expected); + } +}