diff --git a/core/embed/rust/src/ui/component/swipe.rs b/core/embed/rust/src/ui/component/swipe.rs index 5cdaf7c18..01c72a6aa 100644 --- a/core/embed/rust/src/ui/component/swipe.rs +++ b/core/embed/rust/src/ui/component/swipe.rs @@ -25,6 +25,7 @@ impl SwipeDirection { } /// Copy of `model_tt/component/swipe.rs` but without the backlight handling. +#[derive(Clone)] pub struct Swipe { pub area: Rect, pub allow_up: bool, diff --git a/core/embed/rust/src/ui/flow/swipe.rs b/core/embed/rust/src/ui/flow/swipe.rs index 4b154da7a..d2310f52e 100644 --- a/core/embed/rust/src/ui/flow/swipe.rs +++ b/core/embed/rust/src/ui/flow/swipe.rs @@ -5,7 +5,7 @@ use crate::{ animation::Animation, component::{Component, Event, EventCtx, Swipe, SwipeDirection}, flow::{base::Decision, FlowMsg, FlowState, FlowStore}, - geometry::{Offset, Rect}, + geometry::Rect, shape::Renderer, util, }, diff --git a/core/embed/rust/src/ui/model_mercury/component/fido.rs b/core/embed/rust/src/ui/model_mercury/component/fido.rs index 93c279ec9..bdee85ae1 100644 --- a/core/embed/rust/src/ui/model_mercury/component/fido.rs +++ b/core/embed/rust/src/ui/model_mercury/component/fido.rs @@ -1,14 +1,12 @@ use crate::{ strutil::TString, ui::{ - component::{image::Image, Child, Component, Event, EventCtx, Label}, + component::{ + image::Image, Child, Component, Event, EventCtx, Label, Swipe, SwipeDirection, + }, display, geometry::{Insets, Rect}, - model_mercury::component::{ - fido_icons::get_fido_icon_data, - swipe::{Swipe, SwipeDirection}, - theme, ScrollBar, - }, + model_mercury::component::{fido_icons::get_fido_icon_data, theme, ScrollBar}, shape, shape::Renderer, }, diff --git a/core/embed/rust/src/ui/model_mercury/component/keyboard/mnemonic.rs b/core/embed/rust/src/ui/model_mercury/component/keyboard/mnemonic.rs index 381e4fe22..058a4f606 100644 --- a/core/embed/rust/src/ui/model_mercury/component/keyboard/mnemonic.rs +++ b/core/embed/rust/src/ui/model_mercury/component/keyboard/mnemonic.rs @@ -1,10 +1,13 @@ use crate::{ strutil::TString, ui::{ - component::{maybe::paint_overlapping, Child, Component, Event, EventCtx, Label, Maybe}, + component::{ + maybe::paint_overlapping, Child, Component, Event, EventCtx, Label, Maybe, Swipe, + SwipeDirection, + }, geometry::{Alignment, Grid, Insets, Rect}, model_mercury::{ - component::{Button, ButtonMsg, Swipe, SwipeDirection}, + component::{Button, ButtonMsg}, theme, }, shape::Renderer, diff --git a/core/embed/rust/src/ui/model_mercury/component/mod.rs b/core/embed/rust/src/ui/model_mercury/component/mod.rs index 4a12e9a44..6a2e58f7f 100644 --- a/core/embed/rust/src/ui/model_mercury/component/mod.rs +++ b/core/embed/rust/src/ui/model_mercury/component/mod.rs @@ -29,7 +29,6 @@ mod scroll; mod share_words; mod simple_page; mod status_screen; -mod swipe; mod swipe_up_screen; mod welcome_screen; @@ -70,7 +69,6 @@ pub use scroll::ScrollBar; pub use share_words::ShareWords; pub use simple_page::SimplePage; pub use status_screen::StatusScreen; -pub use swipe::{Swipe, SwipeDirection}; pub use swipe_up_screen::{SwipeUpScreen, SwipeUpScreenMsg}; pub use vertical_menu::{VerticalMenu, VerticalMenuChoiceMsg}; pub use welcome_screen::WelcomeScreen; diff --git a/core/embed/rust/src/ui/model_mercury/component/page.rs b/core/embed/rust/src/ui/model_mercury/component/page.rs index e6dfec470..7aab42387 100644 --- a/core/embed/rust/src/ui/model_mercury/component/page.rs +++ b/core/embed/rust/src/ui/model_mercury/component/page.rs @@ -4,7 +4,10 @@ use crate::{ time::Instant, translations::TR, ui::{ - component::{paginated::PageMsg, Component, ComponentExt, Event, EventCtx, Pad, Paginate}, + component::{ + paginated::PageMsg, Component, ComponentExt, Event, EventCtx, Pad, Paginate, Swipe, + SwipeDirection, + }, constant, display::{self, Color}, geometry::{Insets, Rect}, @@ -14,8 +17,7 @@ use crate::{ }; use super::{ - theme, Button, ButtonContent, ButtonMsg, ButtonStyleSheet, Loader, LoaderMsg, ScrollBar, Swipe, - SwipeDirection, + theme, Button, ButtonContent, ButtonMsg, ButtonStyleSheet, Loader, LoaderMsg, ScrollBar, }; use core::cell::Cell; diff --git a/core/embed/rust/src/ui/model_mercury/component/simple_page.rs b/core/embed/rust/src/ui/model_mercury/component/simple_page.rs index 160c049c5..6fa2b9bca 100644 --- a/core/embed/rust/src/ui/model_mercury/component/simple_page.rs +++ b/core/embed/rust/src/ui/model_mercury/component/simple_page.rs @@ -1,11 +1,14 @@ use crate::ui::{ - component::{base::ComponentExt, Component, Event, EventCtx, Pad, PageMsg, Paginate}, + component::{ + base::ComponentExt, Component, Event, EventCtx, Pad, PageMsg, Paginate, Swipe, + SwipeDirection, + }, display::{self, Color}, geometry::{Axis, Insets, Rect}, shape::Renderer, }; -use super::{theme, ScrollBar, Swipe, SwipeDirection}; +use super::{theme, ScrollBar}; use core::cell::Cell; const SCROLLBAR_HEIGHT: i16 = 18; diff --git a/core/embed/rust/src/ui/model_mercury/component/status_screen.rs b/core/embed/rust/src/ui/model_mercury/component/status_screen.rs index dfd789dbe..1fe30e719 100644 --- a/core/embed/rust/src/ui/model_mercury/component/status_screen.rs +++ b/core/embed/rust/src/ui/model_mercury/component/status_screen.rs @@ -1,12 +1,12 @@ use crate::ui::{ - component::{Component, Event, EventCtx, Timeout}, + component::{Component, Event, EventCtx, Swipe, SwipeDirection, Timeout}, display::{Color, Icon}, geometry::{Alignment2D, Rect}, shape, shape::Renderer, }; -use super::{theme, Swipe, SwipeDirection}; +use super::theme; /// Component showing status of an operation. Most typically embedded as a /// content of a Frame and showing success (checkmark with a circle around). diff --git a/core/embed/rust/src/ui/model_mercury/component/swipe.rs b/core/embed/rust/src/ui/model_mercury/component/swipe.rs deleted file mode 100644 index 8f1478353..000000000 --- a/core/embed/rust/src/ui/model_mercury/component/swipe.rs +++ /dev/null @@ -1,161 +0,0 @@ -use crate::ui::{ - component::{Component, Event, EventCtx}, - display, - event::TouchEvent, - geometry::{Point, Rect}, - shape::Renderer, -}; - -use super::theme; - -pub use crate::ui::component::SwipeDirection; - -#[derive(Clone)] -pub struct Swipe { - pub area: Rect, - pub allow_up: bool, - pub allow_down: bool, - pub allow_left: bool, - pub allow_right: bool, - backlight_start: u16, - backlight_end: u16, - origin: Option, -} - -impl Swipe { - const DISTANCE: i32 = 120; - const THRESHOLD: f32 = 0.3; - - pub fn new() -> Self { - Self { - area: Rect::zero(), - allow_up: false, - allow_down: false, - allow_left: false, - allow_right: false, - backlight_start: theme::BACKLIGHT_NORMAL, - backlight_end: theme::BACKLIGHT_NONE, - origin: None, - } - } - - pub fn vertical() -> Self { - Self::new().up().down() - } - - pub fn horizontal() -> Self { - Self::new().left().right() - } - - pub fn up(mut self) -> Self { - self.allow_up = true; - self - } - - pub fn down(mut self) -> Self { - self.allow_down = true; - self - } - - pub fn left(mut self) -> Self { - self.allow_left = true; - self - } - - pub fn right(mut self) -> Self { - self.allow_right = true; - self - } - - fn is_active(&self) -> bool { - self.allow_up || self.allow_down || self.allow_left || self.allow_right - } - - fn ratio(&self, dist: i16) -> f32 { - (dist as f32 / Self::DISTANCE as f32).min(1.0) - } - - fn backlight(&self, ratio: f32) { - let start = self.backlight_start as f32; - let end = self.backlight_end as f32; - let value = start + ratio * (end - start); - display::set_backlight(value as u16); - } -} - -impl Component for Swipe { - type Msg = SwipeDirection; - - fn place(&mut self, bounds: Rect) -> Rect { - self.area = bounds; - self.area - } - - fn event(&mut self, _ctx: &mut EventCtx, event: Event) -> Option { - if !self.is_active() { - return None; - } - match (event, self.origin) { - (Event::Touch(TouchEvent::TouchStart(pos)), _) if self.area.contains(pos) => { - // Mark the starting position of this touch. - self.origin.replace(pos); - } - (Event::Touch(TouchEvent::TouchMove(pos)), Some(origin)) => { - // Consider our allowed directions and the touch distance and modify the display - // backlight accordingly. - let ofs = pos - origin; - let abs = ofs.abs(); - if abs.x > abs.y && (self.allow_left || self.allow_right) { - // Horizontal direction. - if (ofs.x < 0 && self.allow_left) || (ofs.x > 0 && self.allow_right) { - self.backlight(self.ratio(abs.x)); - } - } else if abs.x < abs.y && (self.allow_up || self.allow_down) { - // Vertical direction. - if (ofs.y < 0 && self.allow_up) || (ofs.y > 0 && self.allow_down) { - self.backlight(self.ratio(abs.y)); - } - }; - } - (Event::Touch(TouchEvent::TouchEnd(pos)), Some(origin)) => { - // Touch interaction is over, reset the position. - self.origin.take(); - - // Compare the touch distance with our allowed directions and determine if it - // constitutes a valid swipe. - let ofs = pos - origin; - let abs = ofs.abs(); - if abs.x > abs.y && (self.allow_left || self.allow_right) { - // Horizontal direction. - if self.ratio(abs.x) >= Self::THRESHOLD { - if ofs.x < 0 && self.allow_left { - return Some(SwipeDirection::Left); - } else if ofs.x > 0 && self.allow_right { - return Some(SwipeDirection::Right); - } - } - } else if abs.x < abs.y && (self.allow_up || self.allow_down) { - // Vertical direction. - if self.ratio(abs.y) >= Self::THRESHOLD { - if ofs.y < 0 && self.allow_up { - return Some(SwipeDirection::Up); - } else if ofs.y > 0 && self.allow_down { - return Some(SwipeDirection::Down); - } - } - }; - - // Swipe did not happen, reset the backlight. - self.backlight(0.0); - } - _ => { - // Do nothing. - } - } - None - } - - fn paint(&mut self) {} - - fn render<'s>(&'s self, _target: &mut impl Renderer<'s>) {} -} 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 8e8c85411..05f90bab6 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 @@ -1,11 +1,9 @@ use crate::ui::{ - component::{Component, Event, EventCtx}, + component::{Component, Event, EventCtx, Swipe, SwipeDirection}, geometry::Rect, shape::Renderer, }; -use super::{Swipe, SwipeDirection}; - /// Wrapper component adding "swipe up" handling to `content`. pub struct SwipeUpScreen { content: T, 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 642bba34f..f9d00971d 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 @@ -6,7 +6,7 @@ use crate::{ ui::{ component::{ text::paragraphs::{Paragraph, Paragraphs}, - ComponentExt, + ComponentExt, SwipeDirection, }, flow::{base::Decision, flow_store, FlowMsg, FlowState, FlowStore, SwipeFlow, SwipePage}, layout::obj::LayoutObj, @@ -15,7 +15,7 @@ use crate::{ use heapless::Vec; use super::super::{ - component::{Frame, FrameMsg, PromptScreen, ShareWords, SwipeDirection}, + component::{Frame, FrameMsg, PromptScreen, ShareWords}, theme, };