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

refactor(core/rust): replace TouchAbort event with explicit abort via a detected swipe

worth considering:

pub enum Phase {
    Start,
    Move,
    End,
}

pub enum TouchEvent {
    Touch(Phase, Point),
    Swipe(Phase, Point),
}

(Swipe needs its own Phase because it needs a progress on the Move, but
otherwise...)
This commit is contained in:
matejcik 2024-09-06 13:52:41 +02:00 committed by matejcik
parent 943d6d9b30
commit 9f083c1865
6 changed files with 5 additions and 7 deletions

View File

@ -14,8 +14,6 @@ pub enum TouchEvent {
TouchMove(Point), TouchMove(Point),
/// Touch has ended at a point on the screen. /// Touch has ended at a point on the screen.
TouchEnd(Point), TouchEnd(Point),
/// Touch event has been suppressed by more important event - i.e. Swipe.
TouchAbort,
} }
impl TouchEvent { impl TouchEvent {
@ -34,6 +32,7 @@ impl TouchEvent {
#[derive(Copy, Clone, PartialEq, Eq)] #[derive(Copy, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "debug", derive(ufmt::derive::uDebug))] #[cfg_attr(feature = "debug", derive(ufmt::derive::uDebug))]
pub enum SwipeEvent { pub enum SwipeEvent {
Start(Direction),
Move(Direction, i16), Move(Direction, i16),
End(Direction), End(Direction),
} }

View File

@ -223,7 +223,7 @@ impl SwipeFlow {
Some(SwipeDetectMsg::Move(dir, progress)) => { Some(SwipeDetectMsg::Move(dir, progress)) => {
Event::Swipe(SwipeEvent::Move(dir, progress as i16)) Event::Swipe(SwipeEvent::Move(dir, progress as i16))
} }
Some(SwipeDetectMsg::Start(_)) => Event::Touch(TouchEvent::TouchAbort), Some(SwipeDetectMsg::Start(dir)) => Event::Swipe(SwipeEvent::Start(dir)),
None => event, None => event,
} }
} else { } else {

View File

@ -353,7 +353,8 @@ impl Component for Button {
} }
} }
} }
Event::Touch(TouchEvent::TouchAbort) => { Event::Swipe(_) => {
// When a swipe is detected, abort any ongoing touch.
match self.state { match self.state {
State::Initial | State::Disabled => { State::Initial | State::Disabled => {
// Do nothing. // Do nothing.

View File

@ -185,7 +185,6 @@ impl Component for NumberInputSlider {
ctx.request_paint(); ctx.request_paint();
self.touch_eval(pos, ctx, true) self.touch_eval(pos, ctx, true)
} }
TouchEvent::TouchAbort => None,
}; };
} }
None None

View File

@ -56,7 +56,7 @@ impl<T: Swipable + Component> Component for SwipeUpScreen<T> {
Some(SwipeDetectMsg::Move(dir, progress)) => { Some(SwipeDetectMsg::Move(dir, progress)) => {
Event::Swipe(SwipeEvent::Move(dir, progress as i16)) Event::Swipe(SwipeEvent::Move(dir, progress as i16))
} }
Some(SwipeDetectMsg::Start(_)) => Event::Touch(TouchEvent::TouchAbort), Some(SwipeDetectMsg::Start(dir)) => Event::Swipe(SwipeEvent::Start(dir)),
_ => event, _ => event,
}; };

View File

@ -147,7 +147,6 @@ impl Component for NumberInputSlider {
TouchEvent::TouchStart(pos) => self.slider_eval(pos, ctx), TouchEvent::TouchStart(pos) => self.slider_eval(pos, ctx),
TouchEvent::TouchMove(pos) => self.slider_eval(pos, ctx), TouchEvent::TouchMove(pos) => self.slider_eval(pos, ctx),
TouchEvent::TouchEnd(pos) => self.slider_eval(pos, ctx), TouchEvent::TouchEnd(pos) => self.slider_eval(pos, ctx),
TouchEvent::TouchAbort => None,
}; };
} }
None None