From 510e4845f3e79def12f201634b6e2c0623ef26bb Mon Sep 17 00:00:00 2001 From: obrusvit Date: Tue, 11 Mar 2025 15:35:01 +0100 Subject: [PATCH] chore: fix clippy and style --- .../ui/layout_eckhart/firmware/action_bar.rs | 69 +++++++++---------- .../src/ui/layout_eckhart/firmware/header.rs | 4 +- .../src/ui/layout_eckhart/firmware/hint.rs | 29 ++++---- .../firmware/hold_to_confirm.rs | 2 +- .../firmware/keyboard/keypad.rs | 4 +- .../firmware/keyboard/mnemonic.rs | 7 +- .../firmware/keyboard/passphrase.rs | 2 +- .../firmware/keyboard/word_count_screen.rs | 4 +- .../firmware/number_input_screen.rs | 7 +- .../ui/layout_eckhart/firmware/qr_screen.rs | 2 +- .../ui/layout_eckhart/firmware/share_words.rs | 7 +- .../ui/layout_eckhart/firmware/text_screen.rs | 22 ++++-- .../layout_eckhart/firmware/vertical_menu.rs | 2 +- .../firmware/vertical_menu_screen.rs | 6 +- .../ui/layout_eckhart/flow/confirm_reset.rs | 6 +- .../src/ui/layout_eckhart/flow/get_address.rs | 6 +- .../ui/layout_eckhart/flow/prompt_backup.rs | 6 +- .../src/ui/layout_eckhart/flow/show_danger.rs | 6 +- .../layout_eckhart/flow/show_share_words.rs | 6 +- 19 files changed, 88 insertions(+), 109 deletions(-) diff --git a/core/embed/rust/src/ui/layout_eckhart/firmware/action_bar.rs b/core/embed/rust/src/ui/layout_eckhart/firmware/action_bar.rs index da6929b2b3..4bff91e3c1 100644 --- a/core/embed/rust/src/ui/layout_eckhart/firmware/action_bar.rs +++ b/core/embed/rust/src/ui/layout_eckhart/firmware/action_bar.rs @@ -81,8 +81,7 @@ impl ActionBar { Self::new( Mode::Timeout, None, - button - .initially_enabled(false), + button.initially_enabled(false), Some(Timeout::new(timeout_ms)), ) } @@ -120,40 +119,37 @@ impl ActionBar { pub fn update(&mut self, new_pager: Pager) { // TODO: review `clone()` of `left_content`/`right_content` - match &mut self.mode { - Mode::Double { pager } => { - let old_is_last = pager.is_last(); - let new_is_last = new_pager.is_last(); - *pager = new_pager; - // Update left button - show original content/style only on first page - if let Some(btn) = &mut self.left_button { - if pager.is_first() { - let (content, style) = unwrap!(self.left_original.clone()); - btn.set_content(content); - btn.set_stylesheet(style); - } else { - btn.set_content(Self::PAGINATE_LEFT_CONTENT); - btn.set_stylesheet(*Self::PAGINATE_STYLESHEET); - } - } - - // Update right button - show original content/style only on last page - if pager.is_last() { - let (content, style) = unwrap!(self.right_original.clone()); - self.right_button.set_content(content); - self.right_button.set_stylesheet(style); + if let Mode::Double { pager } = &mut self.mode { + let old_is_last = pager.is_last(); + let new_is_last = new_pager.is_last(); + *pager = new_pager; + // Update left button - show original content/style only on first page + if let Some(btn) = &mut self.left_button { + if pager.is_first() { + let (content, style) = unwrap!(self.left_original.clone()); + btn.set_content(content); + btn.set_stylesheet(style); } else { - self.right_button.set_content(Self::PAGINATE_RIGHT_CONTENT); - self.right_button.set_stylesheet(*Self::PAGINATE_STYLESHEET); - } - - // If we're entering or leaving the last page and left_short is true, - // we need to update the button placement - if self.left_short && (old_is_last != new_is_last) { - self.place_buttons(self.area); + btn.set_content(Self::PAGINATE_LEFT_CONTENT); + btn.set_stylesheet(*Self::PAGINATE_STYLESHEET); } } - _ => {} + + // Update right button - show original content/style only on last page + if pager.is_last() { + let (content, style) = unwrap!(self.right_original.clone()); + self.right_button.set_content(content); + self.right_button.set_stylesheet(style); + } else { + self.right_button.set_content(Self::PAGINATE_RIGHT_CONTENT); + self.right_button.set_stylesheet(*Self::PAGINATE_STYLESHEET); + } + + // If we're entering or leaving the last page and left_short is true, + // we need to update the button placement + if self.left_short && (old_is_last != new_is_last) { + self.place_buttons(self.area); + } } } @@ -167,11 +163,8 @@ impl ActionBar { Mode::Double { .. } => ( left_button .as_ref() - .map(|b| (b.content().clone(), b.style_sheet().clone())), - Some(( - right_button.content().clone(), - right_button.style_sheet().clone(), - )), + .map(|b| (b.content().clone(), *b.style_sheet())), + Some((right_button.content().clone(), *right_button.style_sheet())), ), _ => (None, None), }; diff --git a/core/embed/rust/src/ui/layout_eckhart/firmware/header.rs b/core/embed/rust/src/ui/layout_eckhart/firmware/header.rs index 8edb94e8e9..22161a58b9 100644 --- a/core/embed/rust/src/ui/layout_eckhart/firmware/header.rs +++ b/core/embed/rust/src/ui/layout_eckhart/firmware/header.rs @@ -230,10 +230,10 @@ impl Component for Header { } if let Some(ButtonMsg::Clicked) = self.left_button.event(ctx, event) { - return Some(self.left_button_msg.clone()); + return Some(self.left_button_msg); }; if let Some(ButtonMsg::Clicked) = self.right_button.event(ctx, event) { - return Some(self.right_button_msg.clone()); + return Some(self.right_button_msg); }; None diff --git a/core/embed/rust/src/ui/layout_eckhart/firmware/hint.rs b/core/embed/rust/src/ui/layout_eckhart/firmware/hint.rs index 74668ff187..89cb7d5bed 100644 --- a/core/embed/rust/src/ui/layout_eckhart/firmware/hint.rs +++ b/core/embed/rust/src/ui/layout_eckhart/firmware/hint.rs @@ -32,6 +32,7 @@ pub struct Hint<'a> { } #[derive(Clone)] +#[allow(clippy::large_enum_variant)] enum HintContent<'a> { Instruction(Instruction<'a>), PageCounter(PageCounter), @@ -90,13 +91,10 @@ impl<'a> Hint<'a> { } pub fn update(&mut self, pager: Pager) { - match &mut self.content { - HintContent::PageCounter(counter) => { - counter.update(pager); - self.swipe_allow_down = counter.pager.is_first(); - self.swipe_allow_up = counter.pager.is_last(); - } - _ => {} + if let HintContent::PageCounter(counter) = &mut self.content { + counter.update(pager); + self.swipe_allow_down = counter.pager.is_first(); + self.swipe_allow_up = counter.pager.is_last(); } } @@ -114,15 +112,12 @@ impl<'a> Component for Hint<'a> { debug_assert!(bounds.width() == screen().width()); debug_assert!(bounds.height() == self.content.height()); let bounds = bounds.inset(Self::HINT_INSETS); - match &mut self.content { - HintContent::Instruction(instruction) => { - let text_area = match instruction.icon { - Some(_) => bounds.split_left(instruction.icon_width()).1, - None => bounds, - }; - instruction.label.place(text_area); - } - _ => {} + if let HintContent::Instruction(instruction) = &mut self.content { + let text_area = match instruction.icon { + Some(_) => bounds.split_left(instruction.icon_width()).1, + None => bounds, + }; + instruction.label.place(text_area); } self.area = bounds; self.area @@ -223,7 +218,7 @@ impl<'a> Instruction<'a> { icon: Option, icon_color: Option, ) -> Self { - let mut text_style = Self::STYLE_INSTRUCTION.clone(); + let mut text_style = *Self::STYLE_INSTRUCTION; text_style.text_color = text_color; Self { label: Label::left_aligned(text, text_style).vertically_centered(), diff --git a/core/embed/rust/src/ui/layout_eckhart/firmware/hold_to_confirm.rs b/core/embed/rust/src/ui/layout_eckhart/firmware/hold_to_confirm.rs index 647947423c..dc6940b7b7 100644 --- a/core/embed/rust/src/ui/layout_eckhart/firmware/hold_to_confirm.rs +++ b/core/embed/rust/src/ui/layout_eckhart/firmware/hold_to_confirm.rs @@ -136,7 +136,7 @@ impl Component for HoldToConfirmAnim { .rollback .duration .checked_add(rollback_elapsed) - .unwrap_or(Duration::default()); + .unwrap_or_default(); let (clip, top_gap) = self.get_clips(rollback_duration_progressed); let top_back_rollback = self.get_top_gap_rollback(rollback_elapsed); let top_gap = top_gap.union(top_back_rollback); diff --git a/core/embed/rust/src/ui/layout_eckhart/firmware/keyboard/keypad.rs b/core/embed/rust/src/ui/layout_eckhart/firmware/keyboard/keypad.rs index 09af77d21c..0656e255b3 100644 --- a/core/embed/rust/src/ui/layout_eckhart/firmware/keyboard/keypad.rs +++ b/core/embed/rust/src/ui/layout_eckhart/firmware/keyboard/keypad.rs @@ -147,7 +147,7 @@ impl Keypad { // Make sure the content fits the keypad. debug_assert!(keypad_content.len() <= Self::MAX_KEYS); - for (i, key_content) in keypad_content.into_iter().enumerate() { + for (i, key_content) in keypad_content.iter().enumerate() { self.keys[i].inner_mut().set_content(key_content.clone()); } self @@ -158,7 +158,7 @@ impl Keypad { // Make sure the index is within bounds. debug_assert!(idx < Self::MAX_KEYS); - &self.keys[idx].inner().content() + self.keys[idx].inner().content() } /// Set the state of the keypad. diff --git a/core/embed/rust/src/ui/layout_eckhart/firmware/keyboard/mnemonic.rs b/core/embed/rust/src/ui/layout_eckhart/firmware/keyboard/mnemonic.rs index 6359466e0a..122f09febc 100644 --- a/core/embed/rust/src/ui/layout_eckhart/firmware/keyboard/mnemonic.rs +++ b/core/embed/rust/src/ui/layout_eckhart/firmware/keyboard/mnemonic.rs @@ -169,11 +169,8 @@ where } fn event(&mut self, ctx: &mut EventCtx, event: Event) -> Option { - match event { - Event::Attach(_) => { - self.on_input_change(ctx); - } - _ => {} + if let Event::Attach(_) = event { + self.on_input_change(ctx); } match self.input.event(ctx, event) { diff --git a/core/embed/rust/src/ui/layout_eckhart/firmware/keyboard/passphrase.rs b/core/embed/rust/src/ui/layout_eckhart/firmware/keyboard/passphrase.rs index a1ad41fdf2..d5787b8fba 100644 --- a/core/embed/rust/src/ui/layout_eckhart/firmware/keyboard/passphrase.rs +++ b/core/embed/rust/src/ui/layout_eckhart/firmware/keyboard/passphrase.rs @@ -443,7 +443,7 @@ impl PassphraseInput { } fn passphrase(&self) -> &str { - &self.textbox.content() + self.textbox.content() } fn update_shown_area(&mut self) { diff --git a/core/embed/rust/src/ui/layout_eckhart/firmware/keyboard/word_count_screen.rs b/core/embed/rust/src/ui/layout_eckhart/firmware/keyboard/word_count_screen.rs index 3f19d7876a..7ac82d76c7 100644 --- a/core/embed/rust/src/ui/layout_eckhart/firmware/keyboard/word_count_screen.rs +++ b/core/embed/rust/src/ui/layout_eckhart/firmware/keyboard/word_count_screen.rs @@ -115,13 +115,13 @@ impl ValueKeypad { pub fn new_single_share() -> Self { const NUMBERS: [u32; 5] = [12, 24, 18, 20, 33]; - const LABELS: [&'static str; 5] = ["12", "24", "18", "20", "33"]; + const LABELS: [&str; 5] = ["12", "24", "18", "20", "33"]; Self::new(&LABELS, &NUMBERS) } pub fn new_multi_share() -> Self { const NUMBERS: [u32; 2] = [20, 33]; - const LABELS: [&'static str; 2] = ["20", "33"]; + const LABELS: [&str; 2] = ["20", "33"]; Self::new(&LABELS, &NUMBERS) } diff --git a/core/embed/rust/src/ui/layout_eckhart/firmware/number_input_screen.rs b/core/embed/rust/src/ui/layout_eckhart/firmware/number_input_screen.rs index f7aff4e1fe..839a1a598c 100644 --- a/core/embed/rust/src/ui/layout_eckhart/firmware/number_input_screen.rs +++ b/core/embed/rust/src/ui/layout_eckhart/firmware/number_input_screen.rs @@ -89,11 +89,8 @@ impl Component for NumberInputScreen { fn event(&mut self, ctx: &mut EventCtx, event: Event) -> Option { self.number_input.event(ctx, event); - if let Some(msg) = self.header.event(ctx, event) { - match msg { - HeaderMsg::Menu => return Some(NumberInputScreenMsg::Menu), - _ => {} - } + if let Some(HeaderMsg::Menu) = self.header.event(ctx, event) { + return Some(NumberInputScreenMsg::Menu); } if let Some(msg) = self.action_bar.event(ctx, event) { diff --git a/core/embed/rust/src/ui/layout_eckhart/firmware/qr_screen.rs b/core/embed/rust/src/ui/layout_eckhart/firmware/qr_screen.rs index edf75a1a5b..93550e2e63 100644 --- a/core/embed/rust/src/ui/layout_eckhart/firmware/qr_screen.rs +++ b/core/embed/rust/src/ui/layout_eckhart/firmware/qr_screen.rs @@ -10,8 +10,8 @@ use crate::{ }; use super::super::{ - firmware::{theme, ActionBar, Header, HeaderMsg}, constant::SCREEN, + firmware::{theme, ActionBar, Header, HeaderMsg}, }; pub enum QrMsg { diff --git a/core/embed/rust/src/ui/layout_eckhart/firmware/share_words.rs b/core/embed/rust/src/ui/layout_eckhart/firmware/share_words.rs index c7af0a5058..4434bfa7f7 100644 --- a/core/embed/rust/src/ui/layout_eckhart/firmware/share_words.rs +++ b/core/embed/rust/src/ui/layout_eckhart/firmware/share_words.rs @@ -154,11 +154,8 @@ impl<'a> Component for ShareWordsScreen<'a> { return None; } - if let Some(msg) = self.header.event(ctx, event) { - match msg { - HeaderMsg::Cancelled => return Some(ShareWordsScreenMsg::Cancelled), - _ => {} - } + if let Some(HeaderMsg::Cancelled) = self.header.event(ctx, event) { + return Some(ShareWordsScreenMsg::Cancelled); } if let Some(msg) = self.action_bar.event(ctx, event) { diff --git a/core/embed/rust/src/ui/layout_eckhart/firmware/text_screen.rs b/core/embed/rust/src/ui/layout_eckhart/firmware/text_screen.rs index b49a7e6494..2cdb737507 100644 --- a/core/embed/rust/src/ui/layout_eckhart/firmware/text_screen.rs +++ b/core/embed/rust/src/ui/layout_eckhart/firmware/text_screen.rs @@ -10,7 +10,7 @@ use crate::ui::{ util::Pager, }; -use super::{action_bar::ActionBarMsg, ActionBar, Header, HeaderMsg, Hint, theme::SIDE_INSETS}; +use super::{action_bar::ActionBarMsg, theme::SIDE_INSETS, ActionBar, Header, HeaderMsg, Hint}; /// Full-screen component for rendering text. /// @@ -68,8 +68,12 @@ where fn update_page(&mut self, page_idx: u16) { self.content.change_page(page_idx); let pager = self.content.pager(); - self.hint.as_mut().map(|h| h.update(pager)); - self.action_bar.as_mut().map(|ab| ab.update(pager)); + if let Some(hint) = self.hint.as_mut() { + hint.update(pager); + } + if let Some(ab) = self.action_bar.as_mut() { + ab.update(pager) + }; } } @@ -155,9 +159,15 @@ where { fn trace(&self, t: &mut dyn crate::trace::Tracer) { t.component("TextComponent"); - self.header.as_ref().map(|header| header.trace(t)); + if let Some(header) = self.header.as_ref() { + header.trace(t); + } self.content.trace(t); - self.hint.as_ref().map(|hint| hint.trace(t)); - self.action_bar.as_ref().map(|ab| ab.trace(t)); + if let Some(hint) = self.hint.as_ref() { + hint.trace(t); + } + if let Some(ab) = self.action_bar.as_ref() { + ab.trace(t); + } } } diff --git a/core/embed/rust/src/ui/layout_eckhart/firmware/vertical_menu.rs b/core/embed/rust/src/ui/layout_eckhart/firmware/vertical_menu.rs index 904d1a1fcd..4e68a5f663 100644 --- a/core/embed/rust/src/ui/layout_eckhart/firmware/vertical_menu.rs +++ b/core/embed/rust/src/ui/layout_eckhart/firmware/vertical_menu.rs @@ -138,7 +138,7 @@ impl VerticalMenu { button .area() .top_left() - .ofs(Offset::x(button.content_offset().x).into()), + .ofs(Offset::x(button.content_offset().x)), Offset::new(button.area().width() - 2 * button.content_offset().x, 1), ); Bar::new(separator) diff --git a/core/embed/rust/src/ui/layout_eckhart/firmware/vertical_menu_screen.rs b/core/embed/rust/src/ui/layout_eckhart/firmware/vertical_menu_screen.rs index eb0a80b24a..ec54150930 100644 --- a/core/embed/rust/src/ui/layout_eckhart/firmware/vertical_menu_screen.rs +++ b/core/embed/rust/src/ui/layout_eckhart/firmware/vertical_menu_screen.rs @@ -61,13 +61,13 @@ impl VerticalMenuScreen { Event::Touch(touch_event) => { let shifted_event = match touch_event { TouchEvent::TouchStart(point) if self.menu.area().contains(point) => Some( - TouchEvent::TouchStart(point.ofs(Offset::y(self.menu.get_offset())).into()), + TouchEvent::TouchStart(point.ofs(Offset::y(self.menu.get_offset()))), ), TouchEvent::TouchMove(point) if self.menu.area().contains(point) => Some( - TouchEvent::TouchMove(point.ofs(Offset::y(self.menu.get_offset())).into()), + TouchEvent::TouchMove(point.ofs(Offset::y(self.menu.get_offset()))), ), TouchEvent::TouchEnd(point) if self.menu.area().contains(point) => Some( - TouchEvent::TouchEnd(point.ofs(Offset::y(self.menu.get_offset())).into()), + TouchEvent::TouchEnd(point.ofs(Offset::y(self.menu.get_offset()))), ), _ => None, // Ignore touch events outside the bounds }; diff --git a/core/embed/rust/src/ui/layout_eckhart/flow/confirm_reset.rs b/core/embed/rust/src/ui/layout_eckhart/flow/confirm_reset.rs index 87895112b6..55857af9d0 100644 --- a/core/embed/rust/src/ui/layout_eckhart/flow/confirm_reset.rs +++ b/core/embed/rust/src/ui/layout_eckhart/flow/confirm_reset.rs @@ -32,10 +32,8 @@ impl FlowController for ConfirmReset { *self as usize } - fn handle_swipe(&'static self, direction: Direction) -> Decision { - match (self, direction) { - _ => self.do_nothing(), - } + fn handle_swipe(&'static self, _direction: Direction) -> Decision { + self.do_nothing() } fn handle_event(&'static self, msg: FlowMsg) -> Decision { diff --git a/core/embed/rust/src/ui/layout_eckhart/flow/get_address.rs b/core/embed/rust/src/ui/layout_eckhart/flow/get_address.rs index 2761ff5df3..8c4edad363 100644 --- a/core/embed/rust/src/ui/layout_eckhart/flow/get_address.rs +++ b/core/embed/rust/src/ui/layout_eckhart/flow/get_address.rs @@ -46,10 +46,8 @@ impl FlowController for GetAddress { *self as usize } - fn handle_swipe(&'static self, direction: Direction) -> Decision { - match (self, direction) { - _ => self.do_nothing(), - } + fn handle_swipe(&'static self, _direction: Direction) -> Decision { + self.do_nothing() } fn handle_event(&'static self, msg: FlowMsg) -> Decision { diff --git a/core/embed/rust/src/ui/layout_eckhart/flow/prompt_backup.rs b/core/embed/rust/src/ui/layout_eckhart/flow/prompt_backup.rs index d152636896..6cceaa1de0 100644 --- a/core/embed/rust/src/ui/layout_eckhart/flow/prompt_backup.rs +++ b/core/embed/rust/src/ui/layout_eckhart/flow/prompt_backup.rs @@ -37,10 +37,8 @@ impl FlowController for PromptBackup { *self as usize } - fn handle_swipe(&'static self, direction: Direction) -> Decision { - match (self, direction) { - _ => self.do_nothing(), - } + fn handle_swipe(&'static self, _direction: Direction) -> Decision { + self.do_nothing() } fn handle_event(&'static self, msg: FlowMsg) -> Decision { diff --git a/core/embed/rust/src/ui/layout_eckhart/flow/show_danger.rs b/core/embed/rust/src/ui/layout_eckhart/flow/show_danger.rs index 513d072994..15319888cd 100644 --- a/core/embed/rust/src/ui/layout_eckhart/flow/show_danger.rs +++ b/core/embed/rust/src/ui/layout_eckhart/flow/show_danger.rs @@ -39,10 +39,8 @@ impl FlowController for ShowDanger { *self as usize } - fn handle_swipe(&'static self, direction: Direction) -> Decision { - match (self, direction) { - _ => self.do_nothing(), - } + fn handle_swipe(&'static self, _direction: Direction) -> Decision { + self.do_nothing() } fn handle_event(&'static self, msg: FlowMsg) -> Decision { diff --git a/core/embed/rust/src/ui/layout_eckhart/flow/show_share_words.rs b/core/embed/rust/src/ui/layout_eckhart/flow/show_share_words.rs index 372452dae2..bac2984227 100644 --- a/core/embed/rust/src/ui/layout_eckhart/flow/show_share_words.rs +++ b/core/embed/rust/src/ui/layout_eckhart/flow/show_share_words.rs @@ -39,10 +39,8 @@ impl FlowController for ShowShareWords { *self as usize } - fn handle_swipe(&'static self, direction: Direction) -> Decision { - match (self, direction) { - _ => self.do_nothing(), - } + fn handle_swipe(&'static self, _direction: Direction) -> Decision { + self.do_nothing() } fn handle_event(&'static self, msg: FlowMsg) -> Decision {