1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-22 23:48:12 +00:00

refactor(core/rust): rename the FlowState trait to FlowController

so that we can use the FlowState name for a type alias
This commit is contained in:
matejcik 2024-09-05 14:41:35 +02:00 committed by matejcik
parent 30c08b6442
commit 9cc03c91d1
19 changed files with 48 additions and 48 deletions

View File

@ -36,11 +36,11 @@ impl Decision {
/// ///
/// Contains a new state (by convention it must be of the same concrete type as /// 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. /// 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 /// Encodes the flow logic as a set of states, and transitions between them
/// triggered by events and swipes. /// triggered by events and swipes.
pub trait FlowState { pub trait FlowController {
/// What to do when user swipes on screen and current component doesn't /// What to do when user swipes on screen and current component doesn't
/// respond to swipe of that direction. /// respond to swipe of that direction.
/// ///
@ -62,7 +62,7 @@ pub trait FlowState {
} }
/// Helper trait for writing nicer flow logic. /// Helper trait for writing nicer flow logic.
pub trait DecisionBuilder: FlowState + Sized { pub trait DecisionBuilder: FlowController + Sized {
#[inline] #[inline]
fn swipe(&'static self, direction: SwipeDirection) -> StateChange { fn swipe(&'static self, direction: SwipeDirection) -> StateChange {
(self, Decision::Transition(AttachType::Swipe(direction))) (self, Decision::Transition(AttachType::Swipe(direction)))
@ -104,4 +104,4 @@ pub trait DecisionBuilder: FlowState + Sized {
} }
} }
impl<T: FlowState> DecisionBuilder for T {} impl<T: FlowController> DecisionBuilder for T {}

View File

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

View File

@ -12,7 +12,7 @@ use crate::{
}, },
display::Color, display::Color,
event::{SwipeEvent, TouchEvent}, event::{SwipeEvent, TouchEvent},
flow::{base::Decision, FlowState}, flow::{base::Decision, FlowController},
geometry::Rect, geometry::Rect,
layout::obj::ObjComponent, layout::obj::ObjComponent,
shape::{render_on_display, ConcreteRenderer, Renderer, ScopedRenderer}, shape::{render_on_display, ConcreteRenderer, Renderer, ScopedRenderer},
@ -95,7 +95,7 @@ impl<T> FlowComponentDynTrait for T where
/// - if it can't then FlowState::handle_swipe is consulted. /// - if it can't then FlowState::handle_swipe is consulted.
pub struct SwipeFlow { pub struct SwipeFlow {
/// Current state of the flow. /// Current state of the flow.
state: &'static dyn FlowState, state: &'static dyn FlowController,
/// Store of all screens which are part of the flow. /// Store of all screens which are part of the flow.
store: Vec<GcBox<dyn FlowComponentDynTrait>, 12>, store: Vec<GcBox<dyn FlowComponentDynTrait>, 12>,
/// Swipe detector. /// Swipe detector.
@ -112,7 +112,7 @@ pub struct SwipeFlow {
} }
impl SwipeFlow { impl SwipeFlow {
pub fn new(initial_state: &'static dyn FlowState) -> Result<Self, error::Error> { pub fn new(initial_state: &'static dyn FlowController) -> Result<Self, error::Error> {
Ok(Self { Ok(Self {
state: initial_state, state: initial_state,
swipe: SwipeDetect::new(), swipe: SwipeDetect::new(),
@ -129,7 +129,7 @@ impl SwipeFlow {
/// Pages must be inserted in the order of the flow state index. /// Pages must be inserted in the order of the flow state index.
pub fn with_page( pub fn with_page(
mut self, mut self,
state: &'static dyn FlowState, state: &'static dyn FlowController,
page: impl FlowComponentDynTrait + 'static, page: impl FlowComponentDynTrait + 'static,
) -> Result<Self, error::Error> { ) -> Result<Self, error::Error> {
debug_assert!(self.store.len() == state.index()); debug_assert!(self.store.len() == state.index());

View File

@ -13,7 +13,7 @@ use crate::{
}, },
flow::{ flow::{
base::{DecisionBuilder as _, StateChange}, base::{DecisionBuilder as _, StateChange},
FlowMsg, FlowState, SwipeFlow, SwipePage, FlowMsg, FlowController, SwipeFlow, SwipePage,
}, },
layout::obj::LayoutObj, layout::obj::LayoutObj,
}, },
@ -33,7 +33,7 @@ pub enum ConfirmAction {
Confirm, Confirm,
} }
impl FlowState for ConfirmAction { impl FlowController for ConfirmAction {
fn index(&'static self) -> usize { fn index(&'static self) -> usize {
*self as usize *self as usize
} }
@ -70,7 +70,7 @@ pub enum ConfirmActionSimple {
Menu, Menu,
} }
impl FlowState for ConfirmActionSimple { impl FlowController for ConfirmActionSimple {
#[inline] #[inline]
fn index(&'static self) -> usize { fn index(&'static self) -> usize {
*self as usize *self as usize
@ -193,7 +193,7 @@ fn create_flow(
Option<TString<'static>>, Option<TString<'static>>,
usize, usize,
Result<SwipeFlow, Error>, Result<SwipeFlow, Error>,
&'static dyn FlowState, &'static dyn FlowController,
) { ) {
let prompt_screen = prompt_screen.or_else(|| hold.then_some(title)); let prompt_screen = prompt_screen.or_else(|| hold.then_some(title));
let prompt_pages: usize = prompt_screen.is_some().into(); let prompt_pages: usize = prompt_screen.is_some().into();
@ -204,7 +204,7 @@ fn create_flow(
SwipeFlow::new(&ConfirmActionSimple::Intro) SwipeFlow::new(&ConfirmActionSimple::Intro)
}; };
let page: &dyn FlowState = if prompt_screen.is_some() { let page: &dyn FlowController = if prompt_screen.is_some() {
&ConfirmAction::Intro &ConfirmAction::Intro
} else { } else {
&ConfirmActionSimple::Intro &ConfirmActionSimple::Intro

View File

@ -11,7 +11,7 @@ use crate::{
}, },
flow::{ flow::{
base::{DecisionBuilder as _, StateChange}, base::{DecisionBuilder as _, StateChange},
FlowMsg, FlowState, SwipeFlow, SwipePage, FlowController, FlowMsg, SwipeFlow, SwipePage,
}, },
layout::obj::LayoutObj, layout::obj::LayoutObj,
}, },
@ -39,7 +39,7 @@ pub enum ConfirmFido {
static CRED_SELECTED: AtomicUsize = AtomicUsize::new(0); static CRED_SELECTED: AtomicUsize = AtomicUsize::new(0);
static SINGLE_CRED: AtomicBool = AtomicBool::new(false); static SINGLE_CRED: AtomicBool = AtomicBool::new(false);
impl FlowState for ConfirmFido { impl FlowController for ConfirmFido {
#[inline] #[inline]
fn index(&'static self) -> usize { fn index(&'static self) -> usize {
*self as usize *self as usize

View File

@ -11,7 +11,7 @@ use crate::{
}, },
flow::{ flow::{
base::{DecisionBuilder as _, StateChange}, base::{DecisionBuilder as _, StateChange},
FlowMsg, FlowState, SwipeFlow, FlowMsg, FlowController, SwipeFlow,
}, },
layout::obj::LayoutObj, layout::obj::LayoutObj,
}, },
@ -32,7 +32,7 @@ pub enum ConfirmFirmwareUpdate {
Confirm, Confirm,
} }
impl FlowState for ConfirmFirmwareUpdate { impl FlowController for ConfirmFirmwareUpdate {
#[inline] #[inline]
fn index(&'static self) -> usize { fn index(&'static self) -> usize {
*self as usize *self as usize

View File

@ -12,7 +12,7 @@ use crate::{
}, },
flow::{ flow::{
base::{DecisionBuilder as _, StateChange}, base::{DecisionBuilder as _, StateChange},
FlowMsg, FlowState, SwipeFlow, FlowMsg, FlowController, SwipeFlow,
}, },
layout::obj::LayoutObj, layout::obj::LayoutObj,
}, },
@ -42,7 +42,7 @@ pub enum ConfirmOutput {
CancelTap, CancelTap,
} }
impl FlowState for ConfirmOutput { impl FlowController for ConfirmOutput {
#[inline] #[inline]
fn index(&'static self) -> usize { fn index(&'static self) -> usize {
*self as usize *self as usize
@ -83,7 +83,7 @@ pub enum ConfirmOutputWithAmount {
CancelTap, CancelTap,
} }
impl FlowState for ConfirmOutputWithAmount { impl FlowController for ConfirmOutputWithAmount {
#[inline] #[inline]
fn index(&'static self) -> usize { fn index(&'static self) -> usize {
*self as usize *self as usize
@ -132,7 +132,7 @@ pub enum ConfirmOutputWithSummary {
AccountInfo, AccountInfo,
} }
impl FlowState for ConfirmOutputWithSummary { impl FlowController for ConfirmOutputWithSummary {
#[inline] #[inline]
fn index(&'static self) -> usize { fn index(&'static self) -> usize {
*self as usize *self as usize

View File

@ -12,7 +12,7 @@ use crate::{
}, },
flow::{ flow::{
base::{DecisionBuilder as _, StateChange}, base::{DecisionBuilder as _, StateChange},
FlowMsg, FlowState, SwipeFlow, FlowMsg, FlowController, SwipeFlow,
}, },
layout::obj::LayoutObj, layout::obj::LayoutObj,
}, },
@ -32,7 +32,7 @@ pub enum ConfirmResetCreate {
Confirm, Confirm,
} }
impl FlowState for ConfirmResetCreate { impl FlowController for ConfirmResetCreate {
#[inline] #[inline]
fn index(&'static self) -> usize { fn index(&'static self) -> usize {
*self as usize *self as usize
@ -67,7 +67,7 @@ pub enum ConfirmResetRecover {
Menu, Menu,
} }
impl FlowState for ConfirmResetRecover { impl FlowController for ConfirmResetRecover {
#[inline] #[inline]
fn index(&'static self) -> usize { fn index(&'static self) -> usize {
*self as usize *self as usize

View File

@ -11,7 +11,7 @@ use crate::{
}, },
flow::{ flow::{
base::{DecisionBuilder as _, StateChange}, base::{DecisionBuilder as _, StateChange},
FlowMsg, FlowState, SwipeFlow, FlowMsg, FlowController, SwipeFlow,
}, },
layout::obj::LayoutObj, layout::obj::LayoutObj,
model_mercury::component::SwipeContent, model_mercury::component::SwipeContent,
@ -31,7 +31,7 @@ pub enum SetNewPin {
CancelPinConfirm, CancelPinConfirm,
} }
impl FlowState for SetNewPin { impl FlowController for SetNewPin {
#[inline] #[inline]
fn index(&'static self) -> usize { fn index(&'static self) -> usize {
*self as usize *self as usize

View File

@ -10,7 +10,7 @@ use crate::{
component::{swipe_detect::SwipeSettings, ButtonRequestExt, ComponentExt, SwipeDirection}, component::{swipe_detect::SwipeSettings, ButtonRequestExt, ComponentExt, SwipeDirection},
flow::{ flow::{
base::{DecisionBuilder as _, StateChange}, base::{DecisionBuilder as _, StateChange},
FlowMsg, FlowState, SwipeFlow, FlowMsg, FlowController, SwipeFlow,
}, },
layout::obj::LayoutObj, layout::obj::LayoutObj,
model_mercury::component::SwipeContent, model_mercury::component::SwipeContent,
@ -41,7 +41,7 @@ pub enum ConfirmSummary {
CancelTap, CancelTap,
} }
impl FlowState for ConfirmSummary { impl FlowController for ConfirmSummary {
#[inline] #[inline]
fn index(&'static self) -> usize { fn index(&'static self) -> usize {
*self as usize *self as usize

View File

@ -15,7 +15,7 @@ use crate::{
}, },
flow::{ flow::{
base::{DecisionBuilder as _, StateChange}, base::{DecisionBuilder as _, StateChange},
FlowMsg, FlowState, SwipeFlow, SwipePage, FlowMsg, FlowController, SwipeFlow, SwipePage,
}, },
layout::{obj::LayoutObj, util::RecoveryType}, layout::{obj::LayoutObj, util::RecoveryType},
}, },
@ -52,7 +52,7 @@ pub enum ContinueRecoveryBetweenSharesAdvanced {
RemainingShares, RemainingShares,
} }
impl FlowState for ContinueRecoveryBeforeShares { impl FlowController for ContinueRecoveryBeforeShares {
#[inline] #[inline]
fn index(&'static self) -> usize { fn index(&'static self) -> usize {
*self as usize *self as usize
@ -77,7 +77,7 @@ impl FlowState for ContinueRecoveryBeforeShares {
} }
} }
impl FlowState for ContinueRecoveryBetweenShares { impl FlowController for ContinueRecoveryBetweenShares {
#[inline] #[inline]
fn index(&'static self) -> usize { fn index(&'static self) -> usize {
*self as usize *self as usize

View File

@ -12,7 +12,7 @@ use crate::{
}, },
flow::{ flow::{
base::{DecisionBuilder as _, StateChange}, base::{DecisionBuilder as _, StateChange},
FlowMsg, FlowState, SwipeFlow, SwipePage, FlowMsg, FlowController, SwipeFlow, SwipePage,
}, },
layout::{obj::LayoutObj, util::ConfirmBlob}, layout::{obj::LayoutObj, util::ConfirmBlob},
}, },
@ -40,7 +40,7 @@ pub enum GetAddress {
CancelTap, CancelTap,
} }
impl FlowState for GetAddress { impl FlowController for GetAddress {
#[inline] #[inline]
fn index(&'static self) -> usize { fn index(&'static self) -> usize {
*self as usize *self as usize

View File

@ -11,7 +11,7 @@ use crate::{
}, },
flow::{ flow::{
base::{DecisionBuilder as _, StateChange}, base::{DecisionBuilder as _, StateChange},
FlowMsg, FlowState, SwipeFlow, FlowMsg, FlowController, SwipeFlow,
}, },
layout::obj::LayoutObj, layout::obj::LayoutObj,
}, },
@ -32,7 +32,7 @@ pub enum PromptBackup {
SkipBackupConfirm, SkipBackupConfirm,
} }
impl FlowState for PromptBackup { impl FlowController for PromptBackup {
#[inline] #[inline]
fn index(&'static self) -> usize { fn index(&'static self) -> usize {
*self as usize *self as usize

View File

@ -8,7 +8,7 @@ use crate::{
component::{swipe_detect::SwipeSettings, ButtonRequestExt, ComponentExt, SwipeDirection}, component::{swipe_detect::SwipeSettings, ButtonRequestExt, ComponentExt, SwipeDirection},
flow::{ flow::{
base::{DecisionBuilder as _, StateChange}, base::{DecisionBuilder as _, StateChange},
FlowMsg, FlowState, SwipeFlow, FlowMsg, FlowController, SwipeFlow,
}, },
layout::obj::LayoutObj, layout::obj::LayoutObj,
}, },
@ -31,7 +31,7 @@ pub enum RequestNumber {
Info, Info,
} }
impl FlowState for RequestNumber { impl FlowController for RequestNumber {
#[inline] #[inline]
fn index(&'static self) -> usize { fn index(&'static self) -> usize {
*self as usize *self as usize

View File

@ -7,7 +7,7 @@ use crate::{
component::{ComponentExt, SwipeDirection}, component::{ComponentExt, SwipeDirection},
flow::{ flow::{
base::{DecisionBuilder as _, StateChange}, base::{DecisionBuilder as _, StateChange},
FlowMsg, FlowState, SwipeFlow, FlowMsg, FlowController, SwipeFlow,
}, },
layout::obj::LayoutObj, layout::obj::LayoutObj,
}, },
@ -23,7 +23,7 @@ pub enum RequestPassphrase {
ConfirmEmpty, ConfirmEmpty,
} }
impl FlowState for RequestPassphrase { impl FlowController for RequestPassphrase {
#[inline] #[inline]
fn index(&'static self) -> usize { fn index(&'static self) -> usize {
*self as usize *self as usize

View File

@ -10,7 +10,7 @@ use crate::{
component::{base::ComponentExt, swipe_detect::SwipeSettings, FlowMsg, SwipeDirection}, component::{base::ComponentExt, swipe_detect::SwipeSettings, FlowMsg, SwipeDirection},
flow::{ flow::{
base::{DecisionBuilder as _, StateChange}, base::{DecisionBuilder as _, StateChange},
FlowState, SwipeFlow, FlowController, SwipeFlow,
}, },
layout::obj::LayoutObj, layout::obj::LayoutObj,
}, },
@ -33,7 +33,7 @@ pub enum SetBrightness {
Confirmed, Confirmed,
} }
impl FlowState for SetBrightness { impl FlowController for SetBrightness {
#[inline] #[inline]
fn index(&'static self) -> usize { fn index(&'static self) -> usize {
*self as usize *self as usize

View File

@ -12,7 +12,7 @@ use crate::{
}, },
flow::{ flow::{
base::{DecisionBuilder as _, StateChange}, base::{DecisionBuilder as _, StateChange},
FlowMsg, FlowState, SwipeFlow, FlowMsg, FlowController, SwipeFlow,
}, },
layout::obj::LayoutObj, layout::obj::LayoutObj,
model_mercury::component::{InternallySwipable, InternallySwipableContent, SwipeContent}, model_mercury::component::{InternallySwipable, InternallySwipableContent, SwipeContent},
@ -33,7 +33,7 @@ pub enum ShowShareWords {
CheckBackupIntro, CheckBackupIntro,
} }
impl FlowState for ShowShareWords { impl FlowController for ShowShareWords {
#[inline] #[inline]
fn index(&'static self) -> usize { fn index(&'static self) -> usize {
*self as usize *self as usize

View File

@ -10,7 +10,7 @@ use crate::{
}, },
flow::{ flow::{
base::{DecisionBuilder as _, StateChange}, base::{DecisionBuilder as _, StateChange},
FlowMsg, FlowState, SwipeFlow, FlowMsg, FlowController, SwipeFlow,
}, },
layout::obj::LayoutObj, layout::obj::LayoutObj,
}, },
@ -36,7 +36,7 @@ pub enum ShowTutorial {
HoldToExit, HoldToExit,
} }
impl FlowState for ShowTutorial { impl FlowController for ShowTutorial {
#[inline] #[inline]
fn index(&'static self) -> usize { fn index(&'static self) -> usize {
*self as usize *self as usize

View File

@ -11,7 +11,7 @@ use crate::{
}, },
flow::{ flow::{
base::{DecisionBuilder as _, StateChange}, base::{DecisionBuilder as _, StateChange},
FlowMsg, FlowState, SwipeFlow, FlowMsg, FlowController, SwipeFlow,
}, },
layout::obj::LayoutObj, layout::obj::LayoutObj,
model_mercury::component::SwipeContent, model_mercury::component::SwipeContent,
@ -30,7 +30,7 @@ pub enum WarningHiPrio {
Cancelled, Cancelled,
} }
impl FlowState for WarningHiPrio { impl FlowController for WarningHiPrio {
#[inline] #[inline]
fn index(&'static self) -> usize { fn index(&'static self) -> usize {
*self as usize *self as usize