From fc52f1a4a0bb8cf6eb86ea78bf755b497d0fe33c Mon Sep 17 00:00:00 2001 From: grdddj Date: Sat, 8 Apr 2023 18:57:46 +0200 Subject: [PATCH] TR-rust: small things --- .../ui/model_tr/component/changing_text.rs | 23 ++++++++++++------- .../component/input_methods/choice.rs | 7 ------ .../component/input_methods/passphrase.rs | 13 ++++++----- core/embed/rust/src/ui/util.rs | 6 +++-- 4 files changed, 26 insertions(+), 23 deletions(-) diff --git a/core/embed/rust/src/ui/model_tr/component/changing_text.rs b/core/embed/rust/src/ui/model_tr/component/changing_text.rs index 4a54efdc8..a56238caf 100644 --- a/core/embed/rust/src/ui/model_tr/component/changing_text.rs +++ b/core/embed/rust/src/ui/model_tr/component/changing_text.rs @@ -41,19 +41,19 @@ where Self::new(text, Font::BOLD, Alignment::Center) } - // Update the text to be displayed in the line. + /// Update the text to be displayed in the line. pub fn update_text(&mut self, text: T) { self.text = text; } - // Get current text. + /// Get current text. pub fn get_text(&self) -> &T { &self.text } - // Whether we should display the text content. - // If not, the whole area (Pad) will still be cleared. - // Is valid until this function is called again. + /// Whether we should display the text content. + /// If not, the whole area (Pad) will still be cleared. + /// Is valid until this function is called again. pub fn show_or_not(&mut self, show: bool) { self.show_content = show; } @@ -91,8 +91,6 @@ where } fn paint_long_content_with_ellipsis(&self) { - // TODO: it would be nice to have a "shifting" movement - // when changing the text that is not completely visible let text_to_display = long_line_content_with_ellipsis( self.text.as_ref(), "...", @@ -100,7 +98,16 @@ where self.pad.area.width(), ); - let baseline = Point::new(self.pad.area.x0, self.y_baseline()); + // Creating the notion of motion by shifting the text left and right with + // each new text character. + // (So that it is apparent for the user that the text is changing.) + let x_offset = if self.text.as_ref().len() % 2 == 0 { + 0 + } else { + 2 + }; + + let baseline = Point::new(self.pad.area.x0 + x_offset, self.y_baseline()); common::display(baseline, &text_to_display, self.font); } } diff --git a/core/embed/rust/src/ui/model_tr/component/input_methods/choice.rs b/core/embed/rust/src/ui/model_tr/component/input_methods/choice.rs index 29275e09e..1e09cb1cf 100644 --- a/core/embed/rust/src/ui/model_tr/component/input_methods/choice.rs +++ b/core/embed/rust/src/ui/model_tr/component/input_methods/choice.rs @@ -336,13 +336,6 @@ where /// If defined in the current choice, setting their text, /// whether they are long-pressed, and painting them. fn set_buttons(&mut self, ctx: &mut EventCtx) { - // TODO: offer the possibility to change the buttons from the client - // (button details could be changed in the same index) - // Use-case: BIN button in PIN is deleting last digit if the PIN is not empty, - // otherwise causing Cancel. Would be nice to allow deleting as a single click - // and Cancel as HTC. PIN client would check if the PIN is empty/not and - // adjust the HTC/not. - let btn_layout = self.choices.get(self.page_counter).btn_layout(); self.buttons.mutate(ctx, |_ctx, buttons| { buttons.set(btn_layout); diff --git a/core/embed/rust/src/ui/model_tr/component/input_methods/passphrase.rs b/core/embed/rust/src/ui/model_tr/component/input_methods/passphrase.rs index 73e80b02a..7802ce914 100644 --- a/core/embed/rust/src/ui/model_tr/component/input_methods/passphrase.rs +++ b/core/embed/rust/src/ui/model_tr/component/input_methods/passphrase.rs @@ -219,17 +219,16 @@ impl PassphraseEntry { } fn update_passphrase_dots(&mut self, ctx: &mut EventCtx) { - let text = if self.show_plain_passphrase { + let text_to_show = if self.show_plain_passphrase { String::from(self.passphrase()) } else { let mut dots: String = String::new(); - // TODO: ChangingTextLine could have `is_masked: bool` to do this automatically for _ in 0..self.textbox.len() { unwrap!(dots.push_str("*")); } dots }; - self.passphrase_dots.inner_mut().update_text(text); + self.passphrase_dots.inner_mut().update_text(text_to_show); self.passphrase_dots.request_complete_repaint(ctx); } @@ -314,9 +313,11 @@ impl Component for PassphraseEntry { ctx.request_paint(); } SPACE_INDEX => { - self.append_char(ctx, ' '); - self.update_passphrase_dots(ctx); - ctx.request_paint(); + if !self.is_full() { + self.append_char(ctx, ' '); + self.update_passphrase_dots(ctx); + ctx.request_paint(); + } } _ => { self.menu_position = page_counter; diff --git a/core/embed/rust/src/ui/util.rs b/core/embed/rust/src/ui/util.rs index f0c998864..8d0150d9c 100644 --- a/core/embed/rust/src/ui/util.rs +++ b/core/embed/rust/src/ui/util.rs @@ -18,6 +18,8 @@ impl ResultExt for Result { fn assert_if_debugging_ui(self, #[allow(unused)] message: &str) { #[cfg(feature = "ui_debug")] if self.is_err() { + print!("Panic from assert_if_debugging_ui: "); + println!(message); panic!("{}", message); } } @@ -152,8 +154,8 @@ pub fn char_to_string(ch: char) -> String { /// Returns text to be fit on one line of a given length. /// When the text is too long to fit, it is truncated with ellipsis /// on the left side. -// Hardcoding 50 as the length of the returned String - there should -// not be any lines as long as this. +/// Hardcoding 50 as the length of the returned String - there should +/// not be any lines as long as this. pub fn long_line_content_with_ellipsis( text: &str, ellipsis: &str,