From baceb7b1e4de5281f151433315a973b02ca5d4f1 Mon Sep 17 00:00:00 2001 From: obrusvit Date: Tue, 11 Feb 2025 16:51:23 +0100 Subject: [PATCH] feat(eckhart): implement confirm_value --- .../rust/src/ui/layout_eckhart/theme/mod.rs | 6 ++ .../rust/src/ui/layout_eckhart/ui_firmware.rs | 102 ++++++++++++++---- 2 files changed, 88 insertions(+), 20 deletions(-) diff --git a/core/embed/rust/src/ui/layout_eckhart/theme/mod.rs b/core/embed/rust/src/ui/layout_eckhart/theme/mod.rs index 348255b4cc..097d3564df 100644 --- a/core/embed/rust/src/ui/layout_eckhart/theme/mod.rs +++ b/core/embed/rust/src/ui/layout_eckhart/theme/mod.rs @@ -137,6 +137,12 @@ pub const TEXT_MONO_LIGHT: TextStyle = TextStyle::new( GREY_EXTRA_LIGHT, ); +/// Decide the text style of chunkified text according to its length. +pub fn get_chunkified_text_style(_character_length: usize) -> &'static TextStyle { + // TODO: implement properly for Eckhart, see Delizia implemenation + &TEXT_MONO_MEDIUM +} + pub const fn label_title_main() -> TextStyle { TEXT_SMALL } diff --git a/core/embed/rust/src/ui/layout_eckhart/ui_firmware.rs b/core/embed/rust/src/ui/layout_eckhart/ui_firmware.rs index 80f40b59e5..5071043bc8 100644 --- a/core/embed/rust/src/ui/layout_eckhart/ui_firmware.rs +++ b/core/embed/rust/src/ui/layout_eckhart/ui_firmware.rs @@ -1,14 +1,14 @@ use crate::{ error::Error, io::BinaryData, - micropython::{gc::Gc, list::List, obj::Obj}, + micropython::{gc::Gc, iter::IterBuf, list::List, obj::Obj, util}, strutil::TString, translations::TR, ui::{ component::{ text::{ op::OpTextLayout, - paragraphs::{Paragraph, ParagraphSource, ParagraphVecShort}, + paragraphs::{Paragraph, ParagraphSource, ParagraphVecShort, VecExt}, }, Empty, FormattedText, }, @@ -24,7 +24,7 @@ use crate::{ }; use super::{ - component::{ActionBar, Button, Header, Hint, TextScreen}, + component::{ActionBar, Button, Header, HeaderMsg, Hint, TextScreen}, fonts, theme, UIEckhart, }; @@ -188,22 +188,65 @@ impl FirmwareUI for UIEckhart { } fn confirm_value( - _title: TString<'static>, - _value: Obj, - _description: Option>, - _is_data: bool, - _extra: Option>, + title: TString<'static>, + value: Obj, + description: Option>, + is_data: bool, + extra: Option>, _subtitle: Option>, - _verb: Option>, + verb: Option>, _verb_cancel: Option>, - _info: bool, - _hold: bool, - _chunkify: bool, - _page_counter: bool, + info: bool, + hold: bool, + chunkify: bool, + page_counter: bool, _prompt_screen: bool, - _cancel: bool, + cancel: bool, ) -> Result, Error> { - Err::, Error>(Error::ValueError(c"not implemented")) + let paragraphs = ConfirmValueParams { + description: description.unwrap_or("".into()), + extra: extra.unwrap_or("".into()), + value: if value != Obj::const_none() { + value.try_into()? + } else { + StrOrBytes::Str("".into()) + }, + font: if chunkify { + let value: TString = value.try_into()?; + theme::get_chunkified_text_style(value.len()) + } else if is_data { + &theme::TEXT_MONO_MEDIUM + } else { + &theme::TEXT_MEDIUM + }, + description_font: &theme::TEXT_SMALL, + extra_font: &theme::TEXT_SMALL, + } + .into_paragraphs(); + + let verb = verb.unwrap_or(TR::buttons__confirm.into()); + let right_button = if hold { + Button::with_text(verb).with_long_press(theme::CONFIRM_HOLD_DURATION) + } else { + Button::with_text(verb) + }; + let header = if info { + Header::new(title) + .with_right_button(Button::with_icon(theme::ICON_INFO), HeaderMsg::Menu) + } else { + Header::new(title) + }; + + let mut screen = TextScreen::new(paragraphs) + .with_header(header) + .with_action_bar(ActionBar::new_double( + Button::with_icon(theme::ICON_CROSS), + right_button, + )); + if page_counter { + screen = screen.with_hint(Hint::new_page_counter()); + } + LayoutObj::new(screen) } fn confirm_value_intro( @@ -436,12 +479,31 @@ impl FirmwareUI for UIEckhart { } fn show_info_with_cancel( - _title: TString<'static>, - _items: Obj, + title: TString<'static>, + items: Obj, _horizontal: bool, - _chunkify: bool, + chunkify: bool, ) -> Result { - Err::, Error>(Error::ValueError(c"not implemented")) + let mut paragraphs = ParagraphVecShort::new(); + for para in IterBuf::new().try_iterate(items)? { + let [key, value]: [Obj; 2] = util::iter_into_array(para)?; + let key: TString = key.try_into()?; + let value: TString = value.try_into()?; + paragraphs.add(Paragraph::new(&theme::TEXT_MEDIUM, key).no_break()); + if chunkify { + paragraphs.add(Paragraph::new( + theme::get_chunkified_text_style(value.len()), + value, + )); + } else { + paragraphs.add(Paragraph::new(&theme::TEXT_MONO_MEDIUM, value)); + } + } + + let screen = TextScreen::new(paragraphs.into_paragraphs()) + .with_header(Header::new(title).with_close_button()); + let layout = RootComponent::new(screen); + Ok(layout) } fn show_lockscreen( @@ -495,7 +557,7 @@ impl FirmwareUI for UIEckhart { } fn show_simple( - text: TString<'static>, + _text: TString<'static>, _title: Option>, _button: Option>, ) -> Result, Error> {