From b5dfda6a1d7d6d62691adbdcd743e4a17d3dbe52 Mon Sep 17 00:00:00 2001 From: Martin Milata Date: Thu, 21 Apr 2022 19:21:41 +0200 Subject: [PATCH] fix(core/rust/ui): support longer PIN [no changelog] --- core/embed/rust/src/ui/display.rs | 12 +++ .../src/ui/model_tt/component/keyboard/pin.rs | 75 ++++++++++++++---- .../src/ui/model_tt/res/scroll-small.toif | Bin 0 -> 30 bytes core/embed/rust/src/ui/model_tt/theme.rs | 1 + 4 files changed, 74 insertions(+), 14 deletions(-) create mode 100644 core/embed/rust/src/ui/model_tt/res/scroll-small.toif diff --git a/core/embed/rust/src/ui/display.rs b/core/embed/rust/src/ui/display.rs index a5da26e76..49f68cc73 100644 --- a/core/embed/rust/src/ui/display.rs +++ b/core/embed/rust/src/ui/display.rs @@ -171,6 +171,18 @@ pub fn text_center(baseline: Point, text: &str, font: Font, fg_color: Color, bg_ ); } +pub fn text_right(baseline: Point, text: &str, font: Font, fg_color: Color, bg_color: Color) { + let w = font.text_width(text); + display::text( + baseline.x - w, + baseline.y, + text, + font.0, + fg_color.into(), + bg_color.into(), + ); +} + #[derive(Copy, Clone, PartialEq, Eq)] pub struct Font(i32); diff --git a/core/embed/rust/src/ui/model_tt/component/keyboard/pin.rs b/core/embed/rust/src/ui/model_tt/component/keyboard/pin.rs index 24f5a0617..1727ee827 100644 --- a/core/embed/rust/src/ui/model_tt/component/keyboard/pin.rs +++ b/core/embed/rust/src/ui/model_tt/component/keyboard/pin.rs @@ -24,7 +24,9 @@ pub enum PinKeyboardMsg { Cancelled, } -const MAX_LENGTH: usize = 9; +const MAX_LENGTH: usize = 50; +const MAX_VISIBLE_DOTS: usize = 14; +const MAX_VISIBLE_DIGITS: usize = 16; const DIGIT_COUNT: usize = 10; // 0..10 const ERASE_HOLD_DURATION: Duration = Duration::from_secs(2); @@ -268,7 +270,8 @@ struct PinDots { impl PinDots { const DOT: i32 = 6; - const PADDING: i32 = 4; + const PADDING: i32 = 6; + const TWITCH: i32 = 4; fn new(style: LabelStyle) -> Self { Self { @@ -285,9 +288,9 @@ impl PinDots { } fn size(&self) -> Offset { - let digit_count = self.digits.len(); - let mut width = Self::DOT * (digit_count as i32); - width += Self::PADDING * (digit_count.saturating_sub(1) as i32); + let ndots = self.digits.len().min(MAX_VISIBLE_DOTS); + let mut width = Self::DOT * (ndots as i32); + width += Self::PADDING * (ndots.saturating_sub(1) as i32); Offset::new(width, Self::DOT) } @@ -324,13 +327,28 @@ impl PinDots { fn paint_digits(&self, area: Rect) { let center = area.center() + Offset::y(theme::FONT_MONO.text_height() / 2); - display::text_center( - center, - &self.digits, - theme::FONT_MONO, - self.style.text_color, - self.style.background_color, - ); + let right = + center + Offset::x(theme::FONT_MONO.text_width("0") * (MAX_VISIBLE_DOTS as i32) / 2); + let digits = self.digits.len(); + + if digits <= MAX_VISIBLE_DOTS { + display::text_center( + center, + &self.digits, + theme::FONT_MONO, + self.style.text_color, + self.style.background_color, + ); + } else { + let offset: usize = digits.saturating_sub(MAX_VISIBLE_DIGITS); + display::text_right( + right, + &self.digits[offset..], + theme::FONT_MONO, + self.style.text_color, + self.style.background_color, + ); + } } fn paint_dots(&self, area: Rect) { @@ -338,15 +356,44 @@ impl PinDots { .size() .snap(area.center(), Alignment::Center, Alignment::Center); + let digits = self.digits.len(); + let dots_visible = digits.min(MAX_VISIBLE_DOTS); + let step = Self::DOT + Self::PADDING; + + // Jiggle when overflowed. + if digits > dots_visible && digits % 2 == 0 { + cursor.x += Self::TWITCH + } + + // Small leftmost dot. + if digits > dots_visible + 1 { + display::icon_top_left( + cursor - Offset::x(2 * step), + theme::DOT_SMALL, + self.style.text_color, + self.style.background_color, + ); + } + + // Greyed out dot. + if digits > dots_visible { + display::icon_top_left( + cursor - Offset::x(step), + theme::DOT_ACTIVE, + theme::GREY_LIGHT, + self.style.background_color, + ); + } + // Draw a dot for each PIN digit. - for _ in 0..self.digits.len() { + for _ in 0..dots_visible { display::icon_top_left( cursor, theme::DOT_ACTIVE, self.style.text_color, self.style.background_color, ); - cursor.x += Self::DOT + Self::PADDING; + cursor.x += step; } } } diff --git a/core/embed/rust/src/ui/model_tt/res/scroll-small.toif b/core/embed/rust/src/ui/model_tt/res/scroll-small.toif new file mode 100644 index 0000000000000000000000000000000000000000..67d384c8ae4ce78e0d577d415fe011bfbc1f9131 GIT binary patch literal 30 lcmWIX_e^JFU}F$sU|>j2NJ!ucP4M+j@a1MOl8}&K003C=1%3bk literal 0 HcmV?d00001 diff --git a/core/embed/rust/src/ui/model_tt/theme.rs b/core/embed/rust/src/ui/model_tt/theme.rs index 3180a722e..9366728f2 100644 --- a/core/embed/rust/src/ui/model_tt/theme.rs +++ b/core/embed/rust/src/ui/model_tt/theme.rs @@ -53,6 +53,7 @@ pub const ICON_NEXT: &[u8] = include_res!("model_tt/res/next.toif"); // Scrollbar/PIN dots. pub const DOT_ACTIVE: &[u8] = include_res!("model_tt/res/scroll-active.toif"); pub const DOT_INACTIVE: &[u8] = include_res!("model_tt/res/scroll-inactive.toif"); +pub const DOT_SMALL: &[u8] = include_res!("model_tt/res/scroll-small.toif"); pub fn label_default() -> LabelStyle { LabelStyle {