1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-05-20 07:48:46 +00:00

feat(eckhart): implement homescreen ButtonContent

This commit is contained in:
obrusvit 2025-03-15 14:32:55 +01:00
parent 822fee8eda
commit 320aa09395
2 changed files with 66 additions and 23 deletions

View File

@ -75,6 +75,11 @@ impl Button {
Self::new(ButtonContent::IconAndText(content)) Self::new(ButtonContent::IconAndText(content))
} }
#[cfg(feature = "micropython")]
pub const fn with_homebar_content(text: Option<TString<'static>>) -> Self {
Self::new(ButtonContent::HomeBar(text))
}
pub const fn empty() -> Self { pub const fn empty() -> Self {
Self::new(ButtonContent::Empty) Self::new(ButtonContent::Empty)
} }
@ -189,6 +194,8 @@ impl Button {
+ Self::LINE_SPACING + Self::LINE_SPACING
+ Self::SUBTEXT_STYLE.text_font.allcase_text_height() + Self::SUBTEXT_STYLE.text_font.allcase_text_height()
} }
#[cfg(feature = "micropython")]
ButtonContent::HomeBar(_) => theme::ACTION_BAR_HEIGHT,
} }
} }
@ -305,6 +312,39 @@ impl Button {
ButtonContent::IconAndText(child) => { ButtonContent::IconAndText(child) => {
child.render(target, self.area, self.style(), self.content_offset, alpha); child.render(target, self.area, self.style(), self.content_offset, alpha);
} }
#[cfg(feature = "micropython")]
ButtonContent::HomeBar(text) => {
let baseline = self.area.center();
if let Some(text) = text {
const OFFSET_Y: Offset = Offset::y(25);
text.map(|text| {
shape::Text::new(baseline, text, style.font)
.with_fg(style.text_color)
.with_align(Alignment::Center)
.with_alpha(alpha)
.render(target);
});
shape::ToifImage::new(
self.area.center() + OFFSET_Y,
theme::ICON_DASH_HORIZONTAL.toif,
)
.with_fg(style.icon_color)
.with_align(Alignment2D::CENTER)
.render(target);
} else {
// double dash icon in the middle
const OFFSET_Y: Offset = Offset::y(5);
shape::ToifImage::new(baseline - OFFSET_Y, theme::ICON_DASH_HORIZONTAL.toif)
.with_fg(theme::GREY_LIGHT)
.with_align(Alignment2D::CENTER)
.render(target);
shape::ToifImage::new(baseline + OFFSET_Y, theme::ICON_DASH_HORIZONTAL.toif)
.with_fg(theme::GREY_LIGHT)
.with_align(Alignment2D::CENTER)
.render(target);
}
}
} }
} }
@ -444,6 +484,8 @@ impl crate::trace::Trace for Button {
ButtonContent::TextAndSubtext(text, _) => { ButtonContent::TextAndSubtext(text, _) => {
t.string("text", *text); t.string("text", *text);
} }
#[cfg(feature = "micropython")]
ButtonContent::HomeBar(text) => t.string("text", text.unwrap_or(TString::empty())),
} }
} }
} }
@ -463,6 +505,8 @@ pub enum ButtonContent {
TextAndSubtext(TString<'static>, TString<'static>), TextAndSubtext(TString<'static>, TString<'static>),
Icon(Icon), Icon(Icon),
IconAndText(IconText), IconAndText(IconText),
#[cfg(feature = "micropython")]
HomeBar(Option<TString<'static>>),
} }
#[derive(PartialEq, Eq, Clone, Copy)] #[derive(PartialEq, Eq, Clone, Copy)]

View File

@ -142,14 +142,12 @@ impl PassphraseKeyboard {
} }
} }
fn key_text(content: &ButtonContent) -> TString<'static> { fn key_text(content: &ButtonContent) -> Option<TString<'static>> {
match content { match content {
ButtonContent::Text(text) => *text, ButtonContent::Text(text) => Some(*text),
ButtonContent::TextAndSubtext(_, _) => "".into(), ButtonContent::Icon(theme::ICON_SPECIAL_CHARS) => Some(" *#".into()),
ButtonContent::Icon(theme::ICON_SPECIAL_CHARS) => " *#".into(), ButtonContent::Icon(_) => Some(" ".into()),
ButtonContent::Icon(_) => " ".into(), _ => None,
ButtonContent::IconAndText(_) => " ".into(),
ButtonContent::Empty => "".into(),
} }
} }
@ -312,7 +310,7 @@ impl Component for PassphraseKeyboard {
match self.keypad.event(ctx, event) { match self.keypad.event(ctx, event) {
Some(KeypadMsg::Key(idx)) => { Some(KeypadMsg::Key(idx)) => {
let text = Self::key_text(self.keypad.get_key_content(idx)); if let Some(text) = Self::key_text(self.keypad.get_key_content(idx)) {
let edit = text.map(|c| self.multi_tap.click_key(ctx, idx, c)); let edit = text.map(|c| self.multi_tap.click_key(ctx, idx, c));
self.input.textbox.apply(ctx, edit); self.input.textbox.apply(ctx, edit);
if text.len() == 1 { if text.len() == 1 {
@ -329,6 +327,7 @@ impl Component for PassphraseKeyboard {
} }
self.input.display_style = DisplayStyle::LastOnly; self.input.display_style = DisplayStyle::LastOnly;
self.update_keypad_state(ctx); self.update_keypad_state(ctx);
}
return None; return None;
} }
Some(KeypadMsg::EraseShort) => { Some(KeypadMsg::EraseShort) => {