mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-22 15:38:11 +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:
parent
30c08b6442
commit
9cc03c91d1
@ -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<T: FlowState> DecisionBuilder for T {}
|
||||
impl<T: FlowController> DecisionBuilder for T {}
|
||||
|
@ -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;
|
||||
|
@ -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<T> 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<GcBox<dyn FlowComponentDynTrait>, 12>,
|
||||
/// Swipe detector.
|
||||
@ -112,7 +112,7 @@ pub struct 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 {
|
||||
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<Self, error::Error> {
|
||||
debug_assert!(self.store.len() == state.index());
|
||||
|
@ -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<TString<'static>>,
|
||||
usize,
|
||||
Result<SwipeFlow, Error>,
|
||||
&'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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user