1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-19 05:58:09 +00:00

refactor(core/ui/mercury): delete CancelInfoConfirm

[no changelog]
This commit is contained in:
Martin Milata 2024-07-30 01:19:41 +02:00
parent 6ec9937ead
commit 2572705d1f
18 changed files with 95 additions and 108 deletions

View File

@ -3,7 +3,7 @@ use core::mem;
use heapless::Vec;
use crate::{
strutil::TString,
strutil::{ShortString, TString},
time::Duration,
ui::{
button_request::{ButtonRequest, ButtonRequestCode},
@ -578,3 +578,34 @@ impl EventCtx {
self.transition_out
}
}
/// Component::Msg for component parts of a swipe flow. Converting results of
/// different screens to a shared type makes things easier to work with.
///
/// Also currently the type for message emitted by Flow::event to
/// micropython. They don't need to be the same.
#[derive(Clone)]
pub enum FlowMsg {
Confirmed,
Cancelled,
Info,
Choice(usize),
Text(ShortString),
}
#[cfg(feature = "micropython")]
impl TryFrom<FlowMsg> for crate::micropython::obj::Obj {
type Error = crate::error::Error;
fn try_from(val: FlowMsg) -> Result<crate::micropython::obj::Obj, Self::Error> {
match val {
FlowMsg::Confirmed => Ok(crate::ui::layout::result::CONFIRMED.as_obj()),
FlowMsg::Cancelled => Ok(crate::ui::layout::result::CANCELLED.as_obj()),
FlowMsg::Info => Ok(crate::ui::layout::result::INFO.as_obj()),
FlowMsg::Choice(i) => {
Ok((crate::ui::layout::result::CONFIRMED.as_obj(), i.try_into()?).try_into()?)
}
FlowMsg::Text(_s) => panic!(),
}
}
}

View File

@ -27,7 +27,7 @@ pub mod text;
pub mod timeout;
pub use bar::Bar;
pub use base::{Child, Component, ComponentExt, Event, EventCtx, Never, TimerToken};
pub use base::{Child, Component, ComponentExt, Event, EventCtx, FlowMsg, Never, TimerToken};
pub use border::Border;
pub use button_request::{ButtonRequestExt, SendButtonRequest};
#[cfg(all(feature = "jpeg", feature = "ui_image_buffer", feature = "micropython"))]

View File

@ -1,7 +1,6 @@
use crate::{
strutil::ShortString,
ui::component::{base::AttachType, swipe_detect::SwipeConfig, SwipeDirection},
};
use crate::ui::component::{base::AttachType, swipe_detect::SwipeConfig, SwipeDirection};
pub use crate::ui::component::FlowMsg;
pub trait Swipable {
fn get_swipe_config(&self) -> SwipeConfig;
@ -9,20 +8,6 @@ pub trait Swipable {
fn get_internal_page_count(&self) -> usize;
}
/// Component::Msg for component parts of a flow. Converting results of
/// different screens to a shared type makes things easier to work with.
///
/// Also currently the type for message emitted by Flow::event to
/// micropython. They don't need to be the same.
#[derive(Clone)]
pub enum FlowMsg {
Confirmed,
Cancelled,
Info,
Choice(usize),
Text(ShortString),
}
/// Composable event handler result.
#[derive(Clone)]
pub enum Decision {

View File

@ -2,6 +2,7 @@ pub mod base;
pub mod page;
mod swipe;
pub use base::{FlowMsg, FlowState, Swipable};
pub use crate::ui::component::FlowMsg;
pub use base::{FlowState, Swipable};
pub use page::SwipePage;
pub use swipe::SwipeFlow;

View File

@ -9,11 +9,11 @@ use crate::{
component::{
base::{AttachType, AttachType::Swipe},
swipe_detect::SwipeSettings,
Component, Event, EventCtx, SwipeDetect, SwipeDetectMsg, SwipeDirection,
Component, Event, EventCtx, FlowMsg, SwipeDetect, SwipeDetectMsg, SwipeDirection,
},
display::Color,
event::{SwipeEvent, TouchEvent},
flow::{base::Decision, FlowMsg, FlowState},
flow::{base::Decision, FlowState},
geometry::Rect,
layout::obj::ObjComponent,
shape::{render_on_display, ConcreteRenderer, Renderer, ScopedRenderer},
@ -370,6 +370,7 @@ impl ObjComponent for SwipeFlow {
.try_into()?),
}
}
fn obj_paint(&mut self) {
render_on_display(None, Some(Color::black()), |target| {
self.render_state(self.state.index(), target);

View File

@ -451,13 +451,6 @@ pub struct ButtonStyle {
pub background_color: Color,
}
#[derive(Clone, Copy)]
pub enum CancelInfoConfirmMsg {
Cancelled,
Info,
Confirmed,
}
#[derive(PartialEq, Eq, Clone)]
pub struct IconText {
text: TString<'static>,

View File

@ -1,21 +1,20 @@
use super::{theme, ButtonStyleSheet, CancelInfoConfirmMsg, Footer, Header};
use super::{theme, ButtonStyleSheet, Footer, Header};
use crate::{
strutil::TString,
ui::{
component::{
swipe_detect::{SwipeConfig, SwipeSettings},
text::TextStyle,
Component, Event,
Event::Swipe,
EventCtx, SwipeDetect, SwipeDirection,
Component,
Event::{self, Swipe},
EventCtx, FlowMsg, SwipeDetect, SwipeDirection,
},
display::{Color, Icon},
event::SwipeEvent,
geometry::{Alignment, Insets, Point, Rect},
lerp::Lerp,
model_mercury::theme::TITLE_HEIGHT,
shape,
shape::Renderer,
shape::{self, Renderer},
},
};
@ -94,7 +93,7 @@ pub struct Frame<T> {
pub enum FrameMsg<T> {
Content(T),
Button(CancelInfoConfirmMsg),
Button(FlowMsg),
}
impl<T> Frame<T>
@ -142,26 +141,26 @@ where
}
#[inline(never)]
fn with_button(mut self, icon: Icon, msg: CancelInfoConfirmMsg, enabled: bool) -> Self {
fn with_button(mut self, icon: Icon, msg: FlowMsg, enabled: bool) -> Self {
self.header = self.header.with_button(icon, enabled, msg);
self
}
pub fn with_cancel_button(self) -> Self {
self.with_button(theme::ICON_CLOSE, CancelInfoConfirmMsg::Cancelled, true)
self.with_button(theme::ICON_CLOSE, FlowMsg::Cancelled, true)
}
pub fn with_menu_button(self) -> Self {
self.with_button(theme::ICON_MENU, CancelInfoConfirmMsg::Info, true)
self.with_button(theme::ICON_MENU, FlowMsg::Info, true)
}
pub fn with_warning_low_icon(self) -> Self {
self.with_button(theme::ICON_WARNING, CancelInfoConfirmMsg::Info, false)
self.with_button(theme::ICON_WARNING, FlowMsg::Info, false)
.button_styled(theme::button_warning_low())
}
pub fn with_danger_icon(self) -> Self {
self.with_button(theme::ICON_WARNING, CancelInfoConfirmMsg::Info, false)
self.with_button(theme::ICON_WARNING, FlowMsg::Info, false)
.button_styled(theme::button_danger())
}
@ -319,7 +318,7 @@ fn frame_event(
footer: &mut Option<Footer>,
ctx: &mut EventCtx,
event: Event,
) -> Option<CancelInfoConfirmMsg> {
) -> Option<FlowMsg> {
horizontal_swipe.event(event, swipe_config);
footer.event(ctx, event);

View File

@ -2,17 +2,15 @@ use crate::{
strutil::TString,
time::{Duration, Stopwatch},
ui::{
component::{text::TextStyle, Component, Event, EventCtx, Label},
component::{text::TextStyle, Component, Event, EventCtx, FlowMsg, Label},
display::{Color, Icon},
geometry::{Alignment, Alignment2D, Insets, Offset, Rect},
lerp::Lerp,
model_mercury::{
component::{Button, ButtonMsg, ButtonStyleSheet, CancelInfoConfirmMsg},
theme,
theme::TITLE_HEIGHT,
component::{Button, ButtonMsg, ButtonStyleSheet},
theme::{self, TITLE_HEIGHT},
},
shape,
shape::Renderer,
shape::{self, Renderer},
util::animation_disabled,
},
};
@ -71,7 +69,7 @@ pub struct Header {
icon: Option<Icon>,
color: Option<Color>,
title_style: TextStyle,
button_msg: CancelInfoConfirmMsg,
button_msg: FlowMsg,
}
impl Header {
@ -85,7 +83,7 @@ impl Header {
icon: None,
color: None,
title_style: theme::label_title_main(),
button_msg: CancelInfoConfirmMsg::Cancelled,
button_msg: FlowMsg::Cancelled,
}
}
#[inline(never)]
@ -134,7 +132,7 @@ impl Header {
}
#[inline(never)]
pub fn with_button(mut self, icon: Icon, enabled: bool, msg: CancelInfoConfirmMsg) -> Self {
pub fn with_button(mut self, icon: Icon, enabled: bool, msg: FlowMsg) -> Self {
let touch_area = Insets::uniform(BUTTON_EXPAND_BORDER);
self.button = Some(
Button::with_icon(icon)
@ -166,7 +164,7 @@ impl Header {
}
impl Component for Header {
type Msg = CancelInfoConfirmMsg;
type Msg = FlowMsg;
fn place(&mut self, bounds: Rect) -> Rect {
let header_area = if let Some(b) = &mut self.button {
@ -208,7 +206,7 @@ impl Component for Header {
}
if let Some(ButtonMsg::Clicked) = self.button.event(ctx, event) {
return Some(self.button_msg);
return Some(self.button_msg.clone());
};
None

View File

@ -45,9 +45,7 @@ mod welcome_screen;
pub use address_details::AddressDetails;
#[cfg(feature = "ui_overlay")]
pub use binary_selection::{BinarySelection, BinarySelectionMsg};
pub use button::{
Button, ButtonContent, ButtonMsg, ButtonStyle, ButtonStyleSheet, CancelInfoConfirmMsg, IconText,
};
pub use button::{Button, ButtonContent, ButtonMsg, ButtonStyle, ButtonStyleSheet, IconText};
#[cfg(feature = "translations")]
pub use coinjoin_progress::CoinJoinProgress;
pub use error::ErrorScreen;

View File

@ -171,8 +171,9 @@ impl ConfirmFido {
.with_swipe(SwipeDirection::Down, SwipeSettings::default())
.with_swipe(SwipeDirection::Right, SwipeSettings::immediate())
.map(|msg| match msg {
FrameMsg::Content(()) => Some(FlowMsg::Confirmed),
FrameMsg::Content(PromptMsg::Confirmed) => Some(FlowMsg::Confirmed),
FrameMsg::Button(_) => Some(FlowMsg::Info),
_ => None,
});
let content_menu = Frame::left_aligned(

View File

@ -19,8 +19,7 @@ use crate::{
use super::super::{
component::{
CancelInfoConfirmMsg, Frame, FrameMsg, PromptMsg, PromptScreen, SwipeContent, VerticalMenu,
VerticalMenuChoiceMsg,
Frame, FrameMsg, PromptMsg, PromptScreen, SwipeContent, VerticalMenu, VerticalMenuChoiceMsg,
},
theme,
};
@ -88,9 +87,7 @@ impl ConfirmFirmwareUpdate {
.with_footer(TR::instructions__swipe_up.into(), None)
.with_swipe(SwipeDirection::Up, SwipeSettings::default())
.with_swipe(SwipeDirection::Left, SwipeSettings::default())
.map(|msg| {
matches!(msg, FrameMsg::Button(CancelInfoConfirmMsg::Info)).then_some(FlowMsg::Info)
});
.map(|msg| matches!(msg, FrameMsg::Button(FlowMsg::Info)).then_some(FlowMsg::Info));
let content_menu = Frame::left_aligned(
TString::empty(),
@ -117,8 +114,7 @@ impl ConfirmFirmwareUpdate {
.with_cancel_button()
.with_swipe(SwipeDirection::Right, SwipeSettings::default())
.map(|msg| {
matches!(msg, FrameMsg::Button(CancelInfoConfirmMsg::Cancelled))
.then_some(FlowMsg::Cancelled)
matches!(msg, FrameMsg::Button(FlowMsg::Cancelled)).then_some(FlowMsg::Cancelled)
});
let content_confirm = Frame::left_aligned(

View File

@ -19,10 +19,7 @@ use crate::{
};
use super::super::{
component::{
CancelInfoConfirmMsg, Frame, FrameMsg, PromptMsg, PromptScreen, VerticalMenu,
VerticalMenuChoiceMsg,
},
component::{Frame, FrameMsg, PromptMsg, PromptScreen, VerticalMenu, VerticalMenuChoiceMsg},
theme,
};
@ -83,8 +80,9 @@ impl SetNewPin {
.with_footer(TR::instructions__swipe_up.into(), None)
.with_swipe(SwipeDirection::Up, SwipeSettings::default())
.with_swipe(SwipeDirection::Left, SwipeSettings::default())
.map(|msg| {
matches!(msg, FrameMsg::Button(CancelInfoConfirmMsg::Info)).then_some(FlowMsg::Info)
.map(|msg| match msg {
FrameMsg::Button(bm) => Some(bm),
_ => None,
});
let content_menu = Frame::left_aligned(
@ -95,7 +93,7 @@ impl SetNewPin {
.with_swipe(SwipeDirection::Right, SwipeSettings::immediate())
.map(|msg| match msg {
FrameMsg::Content(VerticalMenuChoiceMsg::Selected(i)) => Some(FlowMsg::Choice(i)),
FrameMsg::Button(CancelInfoConfirmMsg::Cancelled) => Some(FlowMsg::Cancelled),
FrameMsg::Button(FlowMsg::Cancelled) => Some(FlowMsg::Cancelled),
FrameMsg::Button(_) => None,
});
@ -116,7 +114,7 @@ impl SetNewPin {
.with_swipe(SwipeDirection::Up, SwipeSettings::default())
.with_swipe(SwipeDirection::Right, SwipeSettings::immediate())
.map(|msg| match msg {
FrameMsg::Button(CancelInfoConfirmMsg::Cancelled) => Some(FlowMsg::Cancelled),
FrameMsg::Button(bm) => Some(bm),
_ => None,
});
@ -130,7 +128,7 @@ impl SetNewPin {
.with_swipe(SwipeDirection::Right, SwipeSettings::immediate())
.map(|msg| match msg {
FrameMsg::Content(PromptMsg::Confirmed) => Some(FlowMsg::Confirmed),
FrameMsg::Button(CancelInfoConfirmMsg::Cancelled) => Some(FlowMsg::Cancelled),
FrameMsg::Button(FlowMsg::Cancelled) => Some(FlowMsg::Cancelled),
_ => None,
});

View File

@ -21,8 +21,7 @@ use crate::{
use super::super::{
component::{
CancelInfoConfirmMsg, Frame, FrameMsg, PromptMsg, PromptScreen, SwipeContent, VerticalMenu,
VerticalMenuChoiceMsg,
Frame, FrameMsg, PromptMsg, PromptScreen, SwipeContent, VerticalMenu, VerticalMenuChoiceMsg,
},
theme,
};
@ -184,7 +183,7 @@ impl ContinueRecoveryBeforeShares {
.with_swipe(SwipeDirection::Up, SwipeSettings::default())
.with_swipe(SwipeDirection::Right, SwipeSettings::immediate())
.map(|msg| match msg {
FrameMsg::Button(CancelInfoConfirmMsg::Cancelled) => Some(FlowMsg::Cancelled),
FrameMsg::Button(FlowMsg::Cancelled) => Some(FlowMsg::Cancelled),
_ => None,
})
.repeated_button_request(ButtonRequest::new(
@ -202,7 +201,7 @@ impl ContinueRecoveryBeforeShares {
.with_swipe(SwipeDirection::Right, SwipeSettings::immediate())
.map(|msg| match msg {
FrameMsg::Content(PromptMsg::Confirmed) => Some(FlowMsg::Confirmed),
FrameMsg::Button(CancelInfoConfirmMsg::Cancelled) => Some(FlowMsg::Cancelled),
FrameMsg::Button(FlowMsg::Cancelled) => Some(FlowMsg::Cancelled),
_ => None,
});

View File

@ -20,8 +20,8 @@ use crate::{
use super::super::{
component::{
AddressDetails, CancelInfoConfirmMsg, Frame, FrameMsg, PromptMsg, PromptScreen,
StatusScreen, SwipeContent, VerticalMenu, VerticalMenuChoiceMsg,
AddressDetails, Frame, FrameMsg, PromptMsg, PromptScreen, StatusScreen, SwipeContent,
VerticalMenu, VerticalMenuChoiceMsg,
},
theme,
};
@ -217,7 +217,7 @@ impl GetAddress {
.with_swipe(SwipeDirection::Right, SwipeSettings::immediate())
.map(|msg| match msg {
FrameMsg::Content(PromptMsg::Confirmed) => Some(FlowMsg::Confirmed),
FrameMsg::Button(CancelInfoConfirmMsg::Cancelled) => Some(FlowMsg::Cancelled),
FrameMsg::Button(FlowMsg::Cancelled) => Some(FlowMsg::Cancelled),
_ => None,
});

View File

@ -19,8 +19,7 @@ use crate::{
use super::super::{
component::{
CancelInfoConfirmMsg, Frame, FrameMsg, PromptMsg, PromptScreen, SwipeContent, VerticalMenu,
VerticalMenuChoiceMsg,
Frame, FrameMsg, PromptMsg, PromptScreen, SwipeContent, VerticalMenu, VerticalMenuChoiceMsg,
},
theme,
};
@ -83,8 +82,9 @@ impl PromptBackup {
.with_footer(TR::instructions__swipe_up.into(), None)
.with_swipe(SwipeDirection::Up, SwipeSettings::default())
.with_swipe(SwipeDirection::Left, SwipeSettings::default())
.map(|msg| {
matches!(msg, FrameMsg::Button(CancelInfoConfirmMsg::Info)).then_some(FlowMsg::Info)
.map(|msg| match msg {
FrameMsg::Button(bm) => Some(bm),
_ => None,
});
let content_menu = Frame::left_aligned(
@ -95,7 +95,7 @@ impl PromptBackup {
.with_swipe(SwipeDirection::Right, SwipeSettings::immediate())
.map(|msg| match msg {
FrameMsg::Content(VerticalMenuChoiceMsg::Selected(i)) => Some(FlowMsg::Choice(i)),
FrameMsg::Button(CancelInfoConfirmMsg::Cancelled) => Some(FlowMsg::Cancelled),
FrameMsg::Button(FlowMsg::Cancelled) => Some(FlowMsg::Cancelled),
FrameMsg::Button(_) => None,
});
@ -119,7 +119,7 @@ impl PromptBackup {
.with_swipe(SwipeDirection::Up, SwipeSettings::default())
.with_swipe(SwipeDirection::Right, SwipeSettings::immediate())
.map(|msg| match msg {
FrameMsg::Button(CancelInfoConfirmMsg::Cancelled) => Some(FlowMsg::Cancelled),
FrameMsg::Button(FlowMsg::Cancelled) => Some(FlowMsg::Cancelled),
_ => None,
});
@ -133,7 +133,7 @@ impl PromptBackup {
.with_swipe(SwipeDirection::Right, SwipeSettings::immediate())
.map(|msg| match msg {
FrameMsg::Content(PromptMsg::Confirmed) => Some(FlowMsg::Confirmed),
FrameMsg::Button(CancelInfoConfirmMsg::Cancelled) => Some(FlowMsg::Cancelled),
FrameMsg::Button(FlowMsg::Cancelled) => Some(FlowMsg::Cancelled),
_ => None,
});

View File

@ -18,8 +18,8 @@ use core::sync::atomic::{AtomicU16, Ordering};
use super::super::{
component::{
CancelInfoConfirmMsg, Frame, FrameMsg, NumberInputDialog, NumberInputDialogMsg,
SwipeContent, UpdatableMoreInfo, VerticalMenu, VerticalMenuChoiceMsg,
Frame, FrameMsg, NumberInputDialog, NumberInputDialogMsg, SwipeContent, UpdatableMoreInfo,
VerticalMenu, VerticalMenuChoiceMsg,
},
theme,
};
@ -114,7 +114,7 @@ impl RequestNumber {
.with_swipe(SwipeDirection::Right, SwipeSettings::immediate())
.map(|msg| match msg {
FrameMsg::Content(VerticalMenuChoiceMsg::Selected(i)) => Some(FlowMsg::Choice(i)),
FrameMsg::Button(CancelInfoConfirmMsg::Cancelled) => Some(FlowMsg::Cancelled),
FrameMsg::Button(FlowMsg::Cancelled) => Some(FlowMsg::Cancelled),
FrameMsg::Button(_) => None,
});
@ -123,7 +123,7 @@ impl RequestNumber {
.with_cancel_button()
.with_swipe(SwipeDirection::Right, SwipeSettings::immediate())
.map(|msg| match msg {
FrameMsg::Button(CancelInfoConfirmMsg::Cancelled) => Some(FlowMsg::Cancelled),
FrameMsg::Button(FlowMsg::Cancelled) => Some(FlowMsg::Cancelled),
_ => None,
});

View File

@ -7,9 +7,9 @@ use crate::{
translations::TR,
trezorhal::display,
ui::{
component::{base::ComponentExt, swipe_detect::SwipeSettings, SwipeDirection},
component::{base::ComponentExt, swipe_detect::SwipeSettings, FlowMsg, SwipeDirection},
flow::{
base::{DecisionBuilder as _, FlowMsg, StateChange},
base::{DecisionBuilder as _, StateChange},
FlowState, SwipeFlow,
},
layout::obj::LayoutObj,

View File

@ -2,8 +2,7 @@ use core::{cmp::Ordering, convert::TryInto};
use super::{
component::{
AddressDetails, Bip39Input, Button, CancelConfirmMsg, CancelInfoConfirmMsg,
CoinJoinProgress, FidoConfirm, FidoMsg, Frame, FrameMsg, Homescreen, HomescreenMsg,
AddressDetails, Bip39Input, CoinJoinProgress, Frame, FrameMsg, Homescreen, HomescreenMsg,
Lockscreen, MnemonicInput, MnemonicKeyboard, MnemonicKeyboardMsg, PinKeyboard,
PinKeyboardMsg, Progress, PromptScreen, SelectWordCount, SelectWordCountMsg, Slip39Input,
StatusScreen, SwipeUpScreen, SwipeUpScreenMsg, VerticalMenu, VerticalMenuChoiceMsg,
@ -56,18 +55,6 @@ use crate::{
},
};
impl TryFrom<CancelInfoConfirmMsg> for Obj {
type Error = Error;
fn try_from(value: CancelInfoConfirmMsg) -> Result<Self, Self::Error> {
match value {
CancelInfoConfirmMsg::Cancelled => Ok(CANCELLED.as_obj()),
CancelInfoConfirmMsg::Info => Ok(INFO.as_obj()),
CancelInfoConfirmMsg::Confirmed => Ok(CONFIRMED.as_obj()),
}
}
}
impl TryFrom<SelectWordCountMsg> for Obj {
type Error = Error;