From 9cc03c91d1d259f9893b3c55bf83d192c1228d94 Mon Sep 17 00:00:00 2001 From: matejcik Date: Thu, 5 Sep 2024 14:41:35 +0200 Subject: [PATCH] refactor(core/rust): rename the FlowState trait to FlowController so that we can use the FlowState name for a type alias --- core/embed/rust/src/ui/flow/base.rs | 8 ++++---- core/embed/rust/src/ui/flow/mod.rs | 2 +- core/embed/rust/src/ui/flow/swipe.rs | 8 ++++---- .../rust/src/ui/model_mercury/flow/confirm_action.rs | 10 +++++----- .../rust/src/ui/model_mercury/flow/confirm_fido.rs | 4 ++-- .../ui/model_mercury/flow/confirm_firmware_update.rs | 4 ++-- .../rust/src/ui/model_mercury/flow/confirm_output.rs | 8 ++++---- .../rust/src/ui/model_mercury/flow/confirm_reset.rs | 6 +++--- .../src/ui/model_mercury/flow/confirm_set_new_pin.rs | 4 ++-- .../rust/src/ui/model_mercury/flow/confirm_summary.rs | 4 ++-- .../src/ui/model_mercury/flow/continue_recovery.rs | 6 +++--- .../rust/src/ui/model_mercury/flow/get_address.rs | 4 ++-- .../rust/src/ui/model_mercury/flow/prompt_backup.rs | 4 ++-- .../rust/src/ui/model_mercury/flow/request_number.rs | 4 ++-- .../src/ui/model_mercury/flow/request_passphrase.rs | 4 ++-- .../rust/src/ui/model_mercury/flow/set_brightness.rs | 4 ++-- .../rust/src/ui/model_mercury/flow/show_share_words.rs | 4 ++-- .../rust/src/ui/model_mercury/flow/show_tutorial.rs | 4 ++-- .../rust/src/ui/model_mercury/flow/warning_hi_prio.rs | 4 ++-- 19 files changed, 48 insertions(+), 48 deletions(-) diff --git a/core/embed/rust/src/ui/flow/base.rs b/core/embed/rust/src/ui/flow/base.rs index eddfb80f26..f187b939a3 100644 --- a/core/embed/rust/src/ui/flow/base.rs +++ b/core/embed/rust/src/ui/flow/base.rs @@ -36,11 +36,11 @@ impl Decision { /// /// Contains a new state (by convention it must be of the same concrete type as /// the current one) and a Decision object that tells the flow what to do next. -pub type StateChange = (&'static dyn FlowState, Decision); +pub type StateChange = (&'static dyn FlowController, Decision); /// Encodes the flow logic as a set of states, and transitions between them /// triggered by events and swipes. -pub trait FlowState { +pub trait FlowController { /// What to do when user swipes on screen and current component doesn't /// respond to swipe of that direction. /// @@ -62,7 +62,7 @@ pub trait FlowState { } /// Helper trait for writing nicer flow logic. -pub trait DecisionBuilder: FlowState + Sized { +pub trait DecisionBuilder: FlowController + Sized { #[inline] fn swipe(&'static self, direction: SwipeDirection) -> StateChange { (self, Decision::Transition(AttachType::Swipe(direction))) @@ -104,4 +104,4 @@ pub trait DecisionBuilder: FlowState + Sized { } } -impl DecisionBuilder for T {} +impl DecisionBuilder for T {} diff --git a/core/embed/rust/src/ui/flow/mod.rs b/core/embed/rust/src/ui/flow/mod.rs index cd01cd02d7..a464c8f747 100644 --- a/core/embed/rust/src/ui/flow/mod.rs +++ b/core/embed/rust/src/ui/flow/mod.rs @@ -3,6 +3,6 @@ pub mod page; mod swipe; pub use crate::ui::component::FlowMsg; -pub use base::{FlowState, Swipable}; +pub use base::{FlowController, Swipable}; pub use page::SwipePage; pub use swipe::SwipeFlow; diff --git a/core/embed/rust/src/ui/flow/swipe.rs b/core/embed/rust/src/ui/flow/swipe.rs index 0b6f15a3a0..5214508161 100644 --- a/core/embed/rust/src/ui/flow/swipe.rs +++ b/core/embed/rust/src/ui/flow/swipe.rs @@ -12,7 +12,7 @@ use crate::{ }, display::Color, event::{SwipeEvent, TouchEvent}, - flow::{base::Decision, FlowState}, + flow::{base::Decision, FlowController}, geometry::Rect, layout::obj::ObjComponent, shape::{render_on_display, ConcreteRenderer, Renderer, ScopedRenderer}, @@ -95,7 +95,7 @@ impl FlowComponentDynTrait for T where /// - if it can't then FlowState::handle_swipe is consulted. pub struct SwipeFlow { /// Current state of the flow. - state: &'static dyn FlowState, + state: &'static dyn FlowController, /// Store of all screens which are part of the flow. store: Vec, 12>, /// Swipe detector. @@ -112,7 +112,7 @@ pub struct SwipeFlow { } impl SwipeFlow { - pub fn new(initial_state: &'static dyn FlowState) -> Result { + pub fn new(initial_state: &'static dyn FlowController) -> Result { Ok(Self { state: initial_state, swipe: SwipeDetect::new(), @@ -129,7 +129,7 @@ impl SwipeFlow { /// Pages must be inserted in the order of the flow state index. pub fn with_page( mut self, - state: &'static dyn FlowState, + state: &'static dyn FlowController, page: impl FlowComponentDynTrait + 'static, ) -> Result { debug_assert!(self.store.len() == state.index()); diff --git a/core/embed/rust/src/ui/model_mercury/flow/confirm_action.rs b/core/embed/rust/src/ui/model_mercury/flow/confirm_action.rs index 7450fbdfe5..e32d41d7e6 100644 --- a/core/embed/rust/src/ui/model_mercury/flow/confirm_action.rs +++ b/core/embed/rust/src/ui/model_mercury/flow/confirm_action.rs @@ -13,7 +13,7 @@ use crate::{ }, flow::{ base::{DecisionBuilder as _, StateChange}, - FlowMsg, FlowState, SwipeFlow, SwipePage, + FlowMsg, FlowController, SwipeFlow, SwipePage, }, layout::obj::LayoutObj, }, @@ -33,7 +33,7 @@ pub enum ConfirmAction { Confirm, } -impl FlowState for ConfirmAction { +impl FlowController for ConfirmAction { fn index(&'static self) -> usize { *self as usize } @@ -70,7 +70,7 @@ pub enum ConfirmActionSimple { Menu, } -impl FlowState for ConfirmActionSimple { +impl FlowController for ConfirmActionSimple { #[inline] fn index(&'static self) -> usize { *self as usize @@ -193,7 +193,7 @@ fn create_flow( Option>, usize, Result, - &'static dyn FlowState, + &'static dyn FlowController, ) { let prompt_screen = prompt_screen.or_else(|| hold.then_some(title)); let prompt_pages: usize = prompt_screen.is_some().into(); @@ -204,7 +204,7 @@ fn create_flow( SwipeFlow::new(&ConfirmActionSimple::Intro) }; - let page: &dyn FlowState = if prompt_screen.is_some() { + let page: &dyn FlowController = if prompt_screen.is_some() { &ConfirmAction::Intro } else { &ConfirmActionSimple::Intro diff --git a/core/embed/rust/src/ui/model_mercury/flow/confirm_fido.rs b/core/embed/rust/src/ui/model_mercury/flow/confirm_fido.rs index 306563b5e5..a5f14d4766 100644 --- a/core/embed/rust/src/ui/model_mercury/flow/confirm_fido.rs +++ b/core/embed/rust/src/ui/model_mercury/flow/confirm_fido.rs @@ -11,7 +11,7 @@ use crate::{ }, flow::{ base::{DecisionBuilder as _, StateChange}, - FlowMsg, FlowState, SwipeFlow, SwipePage, + FlowController, FlowMsg, SwipeFlow, SwipePage, }, layout::obj::LayoutObj, }, @@ -39,7 +39,7 @@ pub enum ConfirmFido { static CRED_SELECTED: AtomicUsize = AtomicUsize::new(0); static SINGLE_CRED: AtomicBool = AtomicBool::new(false); -impl FlowState for ConfirmFido { +impl FlowController for ConfirmFido { #[inline] fn index(&'static self) -> usize { *self as usize diff --git a/core/embed/rust/src/ui/model_mercury/flow/confirm_firmware_update.rs b/core/embed/rust/src/ui/model_mercury/flow/confirm_firmware_update.rs index b20d35b9b8..e6f7f27e31 100644 --- a/core/embed/rust/src/ui/model_mercury/flow/confirm_firmware_update.rs +++ b/core/embed/rust/src/ui/model_mercury/flow/confirm_firmware_update.rs @@ -11,7 +11,7 @@ use crate::{ }, flow::{ base::{DecisionBuilder as _, StateChange}, - FlowMsg, FlowState, SwipeFlow, + FlowMsg, FlowController, SwipeFlow, }, layout::obj::LayoutObj, }, @@ -32,7 +32,7 @@ pub enum ConfirmFirmwareUpdate { Confirm, } -impl FlowState for ConfirmFirmwareUpdate { +impl FlowController for ConfirmFirmwareUpdate { #[inline] fn index(&'static self) -> usize { *self as usize diff --git a/core/embed/rust/src/ui/model_mercury/flow/confirm_output.rs b/core/embed/rust/src/ui/model_mercury/flow/confirm_output.rs index 09756d7495..c383d7e5dc 100644 --- a/core/embed/rust/src/ui/model_mercury/flow/confirm_output.rs +++ b/core/embed/rust/src/ui/model_mercury/flow/confirm_output.rs @@ -12,7 +12,7 @@ use crate::{ }, flow::{ base::{DecisionBuilder as _, StateChange}, - FlowMsg, FlowState, SwipeFlow, + FlowMsg, FlowController, SwipeFlow, }, layout::obj::LayoutObj, }, @@ -42,7 +42,7 @@ pub enum ConfirmOutput { CancelTap, } -impl FlowState for ConfirmOutput { +impl FlowController for ConfirmOutput { #[inline] fn index(&'static self) -> usize { *self as usize @@ -83,7 +83,7 @@ pub enum ConfirmOutputWithAmount { CancelTap, } -impl FlowState for ConfirmOutputWithAmount { +impl FlowController for ConfirmOutputWithAmount { #[inline] fn index(&'static self) -> usize { *self as usize @@ -132,7 +132,7 @@ pub enum ConfirmOutputWithSummary { AccountInfo, } -impl FlowState for ConfirmOutputWithSummary { +impl FlowController for ConfirmOutputWithSummary { #[inline] fn index(&'static self) -> usize { *self as usize diff --git a/core/embed/rust/src/ui/model_mercury/flow/confirm_reset.rs b/core/embed/rust/src/ui/model_mercury/flow/confirm_reset.rs index 424eb31e8d..968308d54b 100644 --- a/core/embed/rust/src/ui/model_mercury/flow/confirm_reset.rs +++ b/core/embed/rust/src/ui/model_mercury/flow/confirm_reset.rs @@ -12,7 +12,7 @@ use crate::{ }, flow::{ base::{DecisionBuilder as _, StateChange}, - FlowMsg, FlowState, SwipeFlow, + FlowMsg, FlowController, SwipeFlow, }, layout::obj::LayoutObj, }, @@ -32,7 +32,7 @@ pub enum ConfirmResetCreate { Confirm, } -impl FlowState for ConfirmResetCreate { +impl FlowController for ConfirmResetCreate { #[inline] fn index(&'static self) -> usize { *self as usize @@ -67,7 +67,7 @@ pub enum ConfirmResetRecover { Menu, } -impl FlowState for ConfirmResetRecover { +impl FlowController for ConfirmResetRecover { #[inline] fn index(&'static self) -> usize { *self as usize diff --git a/core/embed/rust/src/ui/model_mercury/flow/confirm_set_new_pin.rs b/core/embed/rust/src/ui/model_mercury/flow/confirm_set_new_pin.rs index f8ff95535c..fcacf26d1d 100644 --- a/core/embed/rust/src/ui/model_mercury/flow/confirm_set_new_pin.rs +++ b/core/embed/rust/src/ui/model_mercury/flow/confirm_set_new_pin.rs @@ -11,7 +11,7 @@ use crate::{ }, flow::{ base::{DecisionBuilder as _, StateChange}, - FlowMsg, FlowState, SwipeFlow, + FlowMsg, FlowController, SwipeFlow, }, layout::obj::LayoutObj, model_mercury::component::SwipeContent, @@ -31,7 +31,7 @@ pub enum SetNewPin { CancelPinConfirm, } -impl FlowState for SetNewPin { +impl FlowController for SetNewPin { #[inline] fn index(&'static self) -> usize { *self as usize diff --git a/core/embed/rust/src/ui/model_mercury/flow/confirm_summary.rs b/core/embed/rust/src/ui/model_mercury/flow/confirm_summary.rs index a5766390f2..38b003d680 100644 --- a/core/embed/rust/src/ui/model_mercury/flow/confirm_summary.rs +++ b/core/embed/rust/src/ui/model_mercury/flow/confirm_summary.rs @@ -10,7 +10,7 @@ use crate::{ component::{swipe_detect::SwipeSettings, ButtonRequestExt, ComponentExt, SwipeDirection}, flow::{ base::{DecisionBuilder as _, StateChange}, - FlowMsg, FlowState, SwipeFlow, + FlowMsg, FlowController, SwipeFlow, }, layout::obj::LayoutObj, model_mercury::component::SwipeContent, @@ -41,7 +41,7 @@ pub enum ConfirmSummary { CancelTap, } -impl FlowState for ConfirmSummary { +impl FlowController for ConfirmSummary { #[inline] fn index(&'static self) -> usize { *self as usize diff --git a/core/embed/rust/src/ui/model_mercury/flow/continue_recovery.rs b/core/embed/rust/src/ui/model_mercury/flow/continue_recovery.rs index 19cab2ba9a..b15f227030 100644 --- a/core/embed/rust/src/ui/model_mercury/flow/continue_recovery.rs +++ b/core/embed/rust/src/ui/model_mercury/flow/continue_recovery.rs @@ -15,7 +15,7 @@ use crate::{ }, flow::{ base::{DecisionBuilder as _, StateChange}, - FlowMsg, FlowState, SwipeFlow, SwipePage, + FlowMsg, FlowController, SwipeFlow, SwipePage, }, layout::{obj::LayoutObj, util::RecoveryType}, }, @@ -52,7 +52,7 @@ pub enum ContinueRecoveryBetweenSharesAdvanced { RemainingShares, } -impl FlowState for ContinueRecoveryBeforeShares { +impl FlowController for ContinueRecoveryBeforeShares { #[inline] fn index(&'static self) -> usize { *self as usize @@ -77,7 +77,7 @@ impl FlowState for ContinueRecoveryBeforeShares { } } -impl FlowState for ContinueRecoveryBetweenShares { +impl FlowController for ContinueRecoveryBetweenShares { #[inline] fn index(&'static self) -> usize { *self as usize diff --git a/core/embed/rust/src/ui/model_mercury/flow/get_address.rs b/core/embed/rust/src/ui/model_mercury/flow/get_address.rs index 89a4ba9363..f61cca6a91 100644 --- a/core/embed/rust/src/ui/model_mercury/flow/get_address.rs +++ b/core/embed/rust/src/ui/model_mercury/flow/get_address.rs @@ -12,7 +12,7 @@ use crate::{ }, flow::{ base::{DecisionBuilder as _, StateChange}, - FlowMsg, FlowState, SwipeFlow, SwipePage, + FlowMsg, FlowController, SwipeFlow, SwipePage, }, layout::{obj::LayoutObj, util::ConfirmBlob}, }, @@ -40,7 +40,7 @@ pub enum GetAddress { CancelTap, } -impl FlowState for GetAddress { +impl FlowController for GetAddress { #[inline] fn index(&'static self) -> usize { *self as usize diff --git a/core/embed/rust/src/ui/model_mercury/flow/prompt_backup.rs b/core/embed/rust/src/ui/model_mercury/flow/prompt_backup.rs index e0f548e56b..fae81b4164 100644 --- a/core/embed/rust/src/ui/model_mercury/flow/prompt_backup.rs +++ b/core/embed/rust/src/ui/model_mercury/flow/prompt_backup.rs @@ -11,7 +11,7 @@ use crate::{ }, flow::{ base::{DecisionBuilder as _, StateChange}, - FlowMsg, FlowState, SwipeFlow, + FlowMsg, FlowController, SwipeFlow, }, layout::obj::LayoutObj, }, @@ -32,7 +32,7 @@ pub enum PromptBackup { SkipBackupConfirm, } -impl FlowState for PromptBackup { +impl FlowController for PromptBackup { #[inline] fn index(&'static self) -> usize { *self as usize diff --git a/core/embed/rust/src/ui/model_mercury/flow/request_number.rs b/core/embed/rust/src/ui/model_mercury/flow/request_number.rs index ceb791e555..c2830f273f 100644 --- a/core/embed/rust/src/ui/model_mercury/flow/request_number.rs +++ b/core/embed/rust/src/ui/model_mercury/flow/request_number.rs @@ -8,7 +8,7 @@ use crate::{ component::{swipe_detect::SwipeSettings, ButtonRequestExt, ComponentExt, SwipeDirection}, flow::{ base::{DecisionBuilder as _, StateChange}, - FlowMsg, FlowState, SwipeFlow, + FlowMsg, FlowController, SwipeFlow, }, layout::obj::LayoutObj, }, @@ -31,7 +31,7 @@ pub enum RequestNumber { Info, } -impl FlowState for RequestNumber { +impl FlowController for RequestNumber { #[inline] fn index(&'static self) -> usize { *self as usize diff --git a/core/embed/rust/src/ui/model_mercury/flow/request_passphrase.rs b/core/embed/rust/src/ui/model_mercury/flow/request_passphrase.rs index 53f47e2b64..4e1d37d966 100644 --- a/core/embed/rust/src/ui/model_mercury/flow/request_passphrase.rs +++ b/core/embed/rust/src/ui/model_mercury/flow/request_passphrase.rs @@ -7,7 +7,7 @@ use crate::{ component::{ComponentExt, SwipeDirection}, flow::{ base::{DecisionBuilder as _, StateChange}, - FlowMsg, FlowState, SwipeFlow, + FlowMsg, FlowController, SwipeFlow, }, layout::obj::LayoutObj, }, @@ -23,7 +23,7 @@ pub enum RequestPassphrase { ConfirmEmpty, } -impl FlowState for RequestPassphrase { +impl FlowController for RequestPassphrase { #[inline] fn index(&'static self) -> usize { *self as usize diff --git a/core/embed/rust/src/ui/model_mercury/flow/set_brightness.rs b/core/embed/rust/src/ui/model_mercury/flow/set_brightness.rs index f0b6c6b33f..46ed8b8c86 100644 --- a/core/embed/rust/src/ui/model_mercury/flow/set_brightness.rs +++ b/core/embed/rust/src/ui/model_mercury/flow/set_brightness.rs @@ -10,7 +10,7 @@ use crate::{ component::{base::ComponentExt, swipe_detect::SwipeSettings, FlowMsg, SwipeDirection}, flow::{ base::{DecisionBuilder as _, StateChange}, - FlowState, SwipeFlow, + FlowController, SwipeFlow, }, layout::obj::LayoutObj, }, @@ -33,7 +33,7 @@ pub enum SetBrightness { Confirmed, } -impl FlowState for SetBrightness { +impl FlowController for SetBrightness { #[inline] fn index(&'static self) -> usize { *self as usize diff --git a/core/embed/rust/src/ui/model_mercury/flow/show_share_words.rs b/core/embed/rust/src/ui/model_mercury/flow/show_share_words.rs index 99b51833cf..93cb14ddd3 100644 --- a/core/embed/rust/src/ui/model_mercury/flow/show_share_words.rs +++ b/core/embed/rust/src/ui/model_mercury/flow/show_share_words.rs @@ -12,7 +12,7 @@ use crate::{ }, flow::{ base::{DecisionBuilder as _, StateChange}, - FlowMsg, FlowState, SwipeFlow, + FlowMsg, FlowController, SwipeFlow, }, layout::obj::LayoutObj, model_mercury::component::{InternallySwipable, InternallySwipableContent, SwipeContent}, @@ -33,7 +33,7 @@ pub enum ShowShareWords { CheckBackupIntro, } -impl FlowState for ShowShareWords { +impl FlowController for ShowShareWords { #[inline] fn index(&'static self) -> usize { *self as usize diff --git a/core/embed/rust/src/ui/model_mercury/flow/show_tutorial.rs b/core/embed/rust/src/ui/model_mercury/flow/show_tutorial.rs index 27d9d20fb0..ccab4c39e9 100644 --- a/core/embed/rust/src/ui/model_mercury/flow/show_tutorial.rs +++ b/core/embed/rust/src/ui/model_mercury/flow/show_tutorial.rs @@ -10,7 +10,7 @@ use crate::{ }, flow::{ base::{DecisionBuilder as _, StateChange}, - FlowMsg, FlowState, SwipeFlow, + FlowMsg, FlowController, SwipeFlow, }, layout::obj::LayoutObj, }, @@ -36,7 +36,7 @@ pub enum ShowTutorial { HoldToExit, } -impl FlowState for ShowTutorial { +impl FlowController for ShowTutorial { #[inline] fn index(&'static self) -> usize { *self as usize diff --git a/core/embed/rust/src/ui/model_mercury/flow/warning_hi_prio.rs b/core/embed/rust/src/ui/model_mercury/flow/warning_hi_prio.rs index 0c7993ed1c..27e84f9de2 100644 --- a/core/embed/rust/src/ui/model_mercury/flow/warning_hi_prio.rs +++ b/core/embed/rust/src/ui/model_mercury/flow/warning_hi_prio.rs @@ -11,7 +11,7 @@ use crate::{ }, flow::{ base::{DecisionBuilder as _, StateChange}, - FlowMsg, FlowState, SwipeFlow, + FlowMsg, FlowController, SwipeFlow, }, layout::obj::LayoutObj, model_mercury::component::SwipeContent, @@ -30,7 +30,7 @@ pub enum WarningHiPrio { Cancelled, } -impl FlowState for WarningHiPrio { +impl FlowController for WarningHiPrio { #[inline] fn index(&'static self) -> usize { *self as usize