From 9f083c1865a67acdc99d6b4c3496c3ee77de9153 Mon Sep 17 00:00:00 2001 From: matejcik Date: Fri, 6 Sep 2024 13:52:41 +0200 Subject: [PATCH] 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...) --- core/embed/rust/src/ui/event/touch.rs | 3 +-- core/embed/rust/src/ui/flow/swipe.rs | 2 +- core/embed/rust/src/ui/model_mercury/component/button.rs | 3 ++- .../rust/src/ui/model_mercury/component/number_input_slider.rs | 1 - .../rust/src/ui/model_mercury/component/swipe_up_screen.rs | 2 +- .../rust/src/ui/model_tt/component/number_input_slider.rs | 1 - 6 files changed, 5 insertions(+), 7 deletions(-) diff --git a/core/embed/rust/src/ui/event/touch.rs b/core/embed/rust/src/ui/event/touch.rs index 093298119f..b99310ebd2 100644 --- a/core/embed/rust/src/ui/event/touch.rs +++ b/core/embed/rust/src/ui/event/touch.rs @@ -14,8 +14,6 @@ pub enum TouchEvent { TouchMove(Point), /// Touch has ended at a point on the screen. TouchEnd(Point), - /// Touch event has been suppressed by more important event - i.e. Swipe. - TouchAbort, } impl TouchEvent { @@ -34,6 +32,7 @@ impl TouchEvent { #[derive(Copy, Clone, PartialEq, Eq)] #[cfg_attr(feature = "debug", derive(ufmt::derive::uDebug))] pub enum SwipeEvent { + Start(Direction), Move(Direction, i16), End(Direction), } diff --git a/core/embed/rust/src/ui/flow/swipe.rs b/core/embed/rust/src/ui/flow/swipe.rs index e702f6ea6f..4fe5d84279 100644 --- a/core/embed/rust/src/ui/flow/swipe.rs +++ b/core/embed/rust/src/ui/flow/swipe.rs @@ -223,7 +223,7 @@ impl SwipeFlow { Some(SwipeDetectMsg::Move(dir, progress)) => { 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, } } else { diff --git a/core/embed/rust/src/ui/model_mercury/component/button.rs b/core/embed/rust/src/ui/model_mercury/component/button.rs index 5ff30c0fbb..46f2cd56fe 100644 --- a/core/embed/rust/src/ui/model_mercury/component/button.rs +++ b/core/embed/rust/src/ui/model_mercury/component/button.rs @@ -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 { State::Initial | State::Disabled => { // Do nothing. diff --git a/core/embed/rust/src/ui/model_mercury/component/number_input_slider.rs b/core/embed/rust/src/ui/model_mercury/component/number_input_slider.rs index 5245e53045..2a7f36e790 100644 --- a/core/embed/rust/src/ui/model_mercury/component/number_input_slider.rs +++ b/core/embed/rust/src/ui/model_mercury/component/number_input_slider.rs @@ -185,7 +185,6 @@ impl Component for NumberInputSlider { ctx.request_paint(); self.touch_eval(pos, ctx, true) } - TouchEvent::TouchAbort => None, }; } None diff --git a/core/embed/rust/src/ui/model_mercury/component/swipe_up_screen.rs b/core/embed/rust/src/ui/model_mercury/component/swipe_up_screen.rs index aee1c8dd01..7c0100d45d 100644 --- a/core/embed/rust/src/ui/model_mercury/component/swipe_up_screen.rs +++ b/core/embed/rust/src/ui/model_mercury/component/swipe_up_screen.rs @@ -56,7 +56,7 @@ impl Component for SwipeUpScreen { Some(SwipeDetectMsg::Move(dir, progress)) => { 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, }; diff --git a/core/embed/rust/src/ui/model_tt/component/number_input_slider.rs b/core/embed/rust/src/ui/model_tt/component/number_input_slider.rs index 07e608262b..a4028dd993 100644 --- a/core/embed/rust/src/ui/model_tt/component/number_input_slider.rs +++ b/core/embed/rust/src/ui/model_tt/component/number_input_slider.rs @@ -147,7 +147,6 @@ impl Component for NumberInputSlider { TouchEvent::TouchStart(pos) => self.slider_eval(pos, ctx), TouchEvent::TouchMove(pos) => self.slider_eval(pos, ctx), TouchEvent::TouchEnd(pos) => self.slider_eval(pos, ctx), - TouchEvent::TouchAbort => None, }; } None