1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-03-12 14:16:06 +00:00

chore: fix clippy and style

This commit is contained in:
obrusvit 2025-03-11 15:35:01 +01:00
parent b90dc276da
commit 510e4845f3
19 changed files with 88 additions and 109 deletions

View File

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

View File

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

View File

@ -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>,
icon_color: Option<Color>,
) -> 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(),

View File

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

View File

@ -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.

View File

@ -169,11 +169,8 @@ where
}
fn event(&mut self, ctx: &mut EventCtx, event: Event) -> Option<Self::Msg> {
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) {

View File

@ -443,7 +443,7 @@ impl PassphraseInput {
}
fn passphrase(&self) -> &str {
&self.textbox.content()
self.textbox.content()
}
fn update_shown_area(&mut self) {

View File

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

View File

@ -89,11 +89,8 @@ impl Component for NumberInputScreen {
fn event(&mut self, ctx: &mut EventCtx, event: Event) -> Option<Self::Msg> {
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) {

View File

@ -10,8 +10,8 @@ use crate::{
};
use super::super::{
firmware::{theme, ActionBar, Header, HeaderMsg},
constant::SCREEN,
firmware::{theme, ActionBar, Header, HeaderMsg},
};
pub enum QrMsg {

View File

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

View File

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

View File

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

View File

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

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {