TR-rust: small things

grdddj/debuglink_improvements
grdddj 1 year ago
parent cf51e80c3e
commit fc52f1a4a0

@ -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);
}
}

@ -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);

@ -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<MAX_PASSPHRASE_LENGTH> = 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;

@ -18,6 +18,8 @@ impl<T, E> ResultExt for Result<T, E> {
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<const L: usize>(ch: char) -> String<L> {
/// 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,

Loading…
Cancel
Save