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:
parent
b90dc276da
commit
510e4845f3
@ -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,8 +119,7 @@ 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 } => {
|
||||
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;
|
||||
@ -153,8 +151,6 @@ impl ActionBar {
|
||||
self.place_buttons(self.area);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn new(
|
||||
@ -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),
|
||||
};
|
||||
|
@ -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
|
||||
|
@ -32,6 +32,7 @@ pub struct Hint<'a> {
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
#[allow(clippy::large_enum_variant)]
|
||||
enum HintContent<'a> {
|
||||
Instruction(Instruction<'a>),
|
||||
PageCounter(PageCounter),
|
||||
@ -90,14 +91,11 @@ impl<'a> Hint<'a> {
|
||||
}
|
||||
|
||||
pub fn update(&mut self, pager: Pager) {
|
||||
match &mut self.content {
|
||||
HintContent::PageCounter(counter) => {
|
||||
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();
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the height of the component. In case of the instruction, the
|
||||
@ -114,16 +112,13 @@ 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) => {
|
||||
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(),
|
||||
|
@ -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);
|
||||
|
@ -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.
|
||||
|
@ -169,12 +169,9 @@ where
|
||||
}
|
||||
|
||||
fn event(&mut self, ctx: &mut EventCtx, event: Event) -> Option<Self::Msg> {
|
||||
match event {
|
||||
Event::Attach(_) => {
|
||||
if let Event::Attach(_) = event {
|
||||
self.on_input_change(ctx);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
match self.input.event(ctx, event) {
|
||||
Some(MnemonicInputMsg::Confirmed) => {
|
||||
|
@ -443,7 +443,7 @@ impl PassphraseInput {
|
||||
}
|
||||
|
||||
fn passphrase(&self) -> &str {
|
||||
&self.textbox.content()
|
||||
self.textbox.content()
|
||||
}
|
||||
|
||||
fn update_shown_area(&mut self) {
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -10,8 +10,8 @@ use crate::{
|
||||
};
|
||||
|
||||
use super::super::{
|
||||
firmware::{theme, ActionBar, Header, HeaderMsg},
|
||||
constant::SCREEN,
|
||||
firmware::{theme, ActionBar, Header, HeaderMsg},
|
||||
};
|
||||
|
||||
pub enum QrMsg {
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
};
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user