From b9faca4f339123779c221fcbaa6a38389d50ffb7 Mon Sep 17 00:00:00 2001 From: Lukas Bielesch Date: Thu, 28 Nov 2024 16:29:11 +0100 Subject: [PATCH] fixup! chore(core): show the last passphrase character for a while --- .../component/keyboard/passphrase.rs | 32 +++++---- .../model_tt/component/keyboard/passphrase.rs | 65 +++++++------------ 2 files changed, 37 insertions(+), 60 deletions(-) diff --git a/core/embed/rust/src/ui/model_mercury/component/keyboard/passphrase.rs b/core/embed/rust/src/ui/model_mercury/component/keyboard/passphrase.rs index 503fac9f69..6e0cb875d3 100644 --- a/core/embed/rust/src/ui/model_mercury/component/keyboard/passphrase.rs +++ b/core/embed/rust/src/ui/model_mercury/component/keyboard/passphrase.rs @@ -505,11 +505,12 @@ impl Input { } } - fn render_dots<'s>(&self, last_char: bool, area: Rect, target: &mut impl Renderer<'s>) { + fn render_dots<'s>(&self, area: Rect, target: &mut impl Renderer<'s>) { let style = theme::label_keyboard_mono(); - let bullet = theme::ICON_PIN_BULLET; + let bullet = theme::ICON_PIN_BULLET.toif; let mut cursor = area.left_center(); let all_chars = self.textbox.content().len(); + let last_char = self.display_style == DisplayStyle::LastChar; if all_chars > 0 { // Find out how much text can fit into the textbox. @@ -521,6 +522,7 @@ impl Input { area.width() - 1, ); let visible_chars = truncated.len(); + let visible_dots = visible_chars - last_char as usize; // Jiggle when overflowed. if all_chars > visible_chars @@ -550,13 +552,16 @@ impl Input { cursor.x += Self::X_STEP; char_idx += 1; } - // Classical dot(s) - for _ in char_idx..(visible_chars - 1) { - shape::ToifImage::new(cursor, bullet) - .with_align(Alignment2D::TOP_LEFT) - .with_fg(style.text_color) - .render(target); - cursor.x += Self::X_STEP; + + if visible_dots > 0 { + // Classical dot(s) + for _ in char_idx..visible_dots { + shape::ToifImage::new(cursor, bullet) + .with_align(Alignment2D::TOP_LEFT) + .with_fg(style.text_color) + .render(target); + cursor.x += Self::X_STEP; + } } if last_char { @@ -574,12 +579,6 @@ impl Input { if self.multi_tap.pending_key().is_some() { render_pending_marker(target, cursor, last, style.text_font, style.text_color); } - } else { - // Last classical dot - shape::ToifImage::new(cursor, bullet) - .with_align(Alignment2D::TOP_LEFT) - .with_fg(style.text_color) - .render(target); } } } @@ -624,8 +623,7 @@ impl Component for Input { if !self.textbox.content().is_empty() { match self.display_style { DisplayStyle::Chars => self.render_chars(text_area, target), - DisplayStyle::Dots => self.render_dots(false, text_area, target), - DisplayStyle::LastChar => self.render_dots(true, text_area, target), + _ => self.render_dots(text_area, target), } } } diff --git a/core/embed/rust/src/ui/model_tt/component/keyboard/passphrase.rs b/core/embed/rust/src/ui/model_tt/component/keyboard/passphrase.rs index 7a92458bc1..3f22b8d31d 100644 --- a/core/embed/rust/src/ui/model_tt/component/keyboard/passphrase.rs +++ b/core/embed/rust/src/ui/model_tt/component/keyboard/passphrase.rs @@ -1,5 +1,5 @@ use crate::{ - strutil::TString, + strutil::{ShortString, TString}, time::Duration, ui::{ component::{ @@ -8,7 +8,7 @@ use crate::{ }, display, event::TouchEvent, - geometry::{Alignment, Alignment2D, Grid, Offset, Rect}, + geometry::{Alignment, Grid, Offset, Rect}, model_tt::component::{ button::{Button, ButtonContent, ButtonMsg}, keyboard::common::{render_pending_marker, MultiTapKeyboard}, @@ -417,11 +417,11 @@ impl Input { } } - fn render_dots<'s>(&self, last_char: bool, area: Rect, target: &mut impl Renderer<'s>) { + fn render_dots<'s>(&self, area: Rect, target: &mut impl Renderer<'s>) { let style = theme::label_keyboard_mono(); - let dot = theme::ICON_MAGIC.toif; - let mut cursor = area.top_left(); + let mut cursor = area.top_left() + Offset::y(style.text_font.text_height()); let all_chars = self.textbox.content().len(); + let last_char = self.display_style == DisplayStyle::LastChar; if all_chars > 0 { // Find out how much text can fit into the textbox. @@ -443,41 +443,27 @@ impl Input { cursor.x += Self::TWITCH; } - // Adapt y position for the icons - cursor.y += Self::Y_STEP; - let mut char_idx = 0; - // Small leftmost dot. - if all_chars > visible_chars + 1 { - shape::ToifImage::new(cursor, theme::DOT_SMALL.toif) - .with_align(Alignment2D::TOP_LEFT) - .with_fg(theme::GREY_DARK) - .render(target); - cursor.x += Self::X_STEP; - char_idx += 1; - } - // Greyed out dot. - if all_chars > visible_chars { - shape::ToifImage::new(cursor, theme::DOT_SMALL.toif) - .with_align(Alignment2D::TOP_LEFT) - .with_fg(style.text_color) - .render(target); - cursor.x += Self::X_STEP; - char_idx += 1; - } - // Classical dot(s) - for _ in char_idx..(visible_chars - 1) { - shape::ToifImage::new(cursor, dot) - .with_align(Alignment2D::TOP_LEFT) - .with_fg(style.text_color) - .render(target); - cursor.x += Self::X_STEP; + let visible_dots = visible_chars - last_char as usize; + let mut dots = ShortString::new(); + for _ in 0..visible_dots { + dots.push('*').unwrap(); } + // Paint the dots + shape::Text::new(cursor, &dots) + .with_align(Alignment::Start) + .with_font(style.text_font) + .with_fg(theme::GREY_MEDIUM) + .render(target); + if last_char { - // Adapt y position for the character - cursor.y = area.top_left().y + style.text_font.text_height(); // This should not fail because all_chars > 0 let last = &self.textbox.content()[(all_chars - 1)..all_chars]; + + // Adapt x position for the character + cursor.x += + style.text_font.text_width(&truncated) - style.text_font.text_width(&last); + // Paint the last character shape::Text::new(cursor, last) .with_align(Alignment::Start) @@ -488,12 +474,6 @@ impl Input { if self.multi_tap.pending_key().is_some() { render_pending_marker(target, cursor, last, style.text_font, style.text_color); } - } else { - // Last classical dot - shape::ToifImage::new(cursor, dot) - .with_align(Alignment2D::TOP_LEFT) - .with_fg(style.text_color) - .render(target); } } } @@ -538,8 +518,7 @@ impl Component for Input { if !self.textbox.content().is_empty() { match self.display_style { DisplayStyle::Chars => self.render_chars(text_area, target), - DisplayStyle::Dots => self.render_dots(false, text_area, target), - DisplayStyle::LastChar => self.render_dots(true, text_area, target), + _ => self.render_dots(text_area, target), } } }