mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-07-08 15:48:08 +00:00
TR-rust: small things
This commit is contained in:
parent
cf51e80c3e
commit
fc52f1a4a0
@ -41,19 +41,19 @@ where
|
|||||||
Self::new(text, Font::BOLD, Alignment::Center)
|
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) {
|
pub fn update_text(&mut self, text: T) {
|
||||||
self.text = text;
|
self.text = text;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get current text.
|
/// Get current text.
|
||||||
pub fn get_text(&self) -> &T {
|
pub fn get_text(&self) -> &T {
|
||||||
&self.text
|
&self.text
|
||||||
}
|
}
|
||||||
|
|
||||||
// Whether we should display the text content.
|
/// Whether we should display the text content.
|
||||||
// If not, the whole area (Pad) will still be cleared.
|
/// If not, the whole area (Pad) will still be cleared.
|
||||||
// Is valid until this function is called again.
|
/// Is valid until this function is called again.
|
||||||
pub fn show_or_not(&mut self, show: bool) {
|
pub fn show_or_not(&mut self, show: bool) {
|
||||||
self.show_content = show;
|
self.show_content = show;
|
||||||
}
|
}
|
||||||
@ -91,8 +91,6 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn paint_long_content_with_ellipsis(&self) {
|
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(
|
let text_to_display = long_line_content_with_ellipsis(
|
||||||
self.text.as_ref(),
|
self.text.as_ref(),
|
||||||
"...",
|
"...",
|
||||||
@ -100,7 +98,16 @@ where
|
|||||||
self.pad.area.width(),
|
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);
|
common::display(baseline, &text_to_display, self.font);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -336,13 +336,6 @@ where
|
|||||||
/// If defined in the current choice, setting their text,
|
/// If defined in the current choice, setting their text,
|
||||||
/// whether they are long-pressed, and painting them.
|
/// whether they are long-pressed, and painting them.
|
||||||
fn set_buttons(&mut self, ctx: &mut EventCtx) {
|
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();
|
let btn_layout = self.choices.get(self.page_counter).btn_layout();
|
||||||
self.buttons.mutate(ctx, |_ctx, buttons| {
|
self.buttons.mutate(ctx, |_ctx, buttons| {
|
||||||
buttons.set(btn_layout);
|
buttons.set(btn_layout);
|
||||||
|
@ -219,17 +219,16 @@ impl PassphraseEntry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn update_passphrase_dots(&mut self, ctx: &mut EventCtx) {
|
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())
|
String::from(self.passphrase())
|
||||||
} else {
|
} else {
|
||||||
let mut dots: String<MAX_PASSPHRASE_LENGTH> = String::new();
|
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() {
|
for _ in 0..self.textbox.len() {
|
||||||
unwrap!(dots.push_str("*"));
|
unwrap!(dots.push_str("*"));
|
||||||
}
|
}
|
||||||
dots
|
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);
|
self.passphrase_dots.request_complete_repaint(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -314,9 +313,11 @@ impl Component for PassphraseEntry {
|
|||||||
ctx.request_paint();
|
ctx.request_paint();
|
||||||
}
|
}
|
||||||
SPACE_INDEX => {
|
SPACE_INDEX => {
|
||||||
self.append_char(ctx, ' ');
|
if !self.is_full() {
|
||||||
self.update_passphrase_dots(ctx);
|
self.append_char(ctx, ' ');
|
||||||
ctx.request_paint();
|
self.update_passphrase_dots(ctx);
|
||||||
|
ctx.request_paint();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
self.menu_position = page_counter;
|
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) {
|
fn assert_if_debugging_ui(self, #[allow(unused)] message: &str) {
|
||||||
#[cfg(feature = "ui_debug")]
|
#[cfg(feature = "ui_debug")]
|
||||||
if self.is_err() {
|
if self.is_err() {
|
||||||
|
print!("Panic from assert_if_debugging_ui: ");
|
||||||
|
println!(message);
|
||||||
panic!("{}", 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.
|
/// 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
|
/// When the text is too long to fit, it is truncated with ellipsis
|
||||||
/// on the left side.
|
/// on the left side.
|
||||||
// Hardcoding 50 as the length of the returned String - there should
|
/// Hardcoding 50 as the length of the returned String - there should
|
||||||
// not be any lines as long as this.
|
/// not be any lines as long as this.
|
||||||
pub fn long_line_content_with_ellipsis(
|
pub fn long_line_content_with_ellipsis(
|
||||||
text: &str,
|
text: &str,
|
||||||
ellipsis: &str,
|
ellipsis: &str,
|
||||||
|
Loading…
Reference in New Issue
Block a user