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 fd9053a01..71fc05395 100644 --- a/core/embed/rust/src/ui/model_mercury/component/mod.rs +++ b/core/embed/rust/src/ui/model_mercury/component/mod.rs @@ -28,6 +28,7 @@ mod share_words; mod simple_page; mod status_screen; mod swipe; +mod swipe_up_screen; mod welcome_screen; #[cfg(feature = "translations")] @@ -66,6 +67,7 @@ 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/swipe_up_screen.rs b/core/embed/rust/src/ui/model_mercury/component/swipe_up_screen.rs new file mode 100644 index 000000000..8e8c85411 --- /dev/null +++ b/core/embed/rust/src/ui/model_mercury/component/swipe_up_screen.rs @@ -0,0 +1,76 @@ +use crate::ui::{ + component::{Component, Event, EventCtx}, + geometry::Rect, + shape::Renderer, +}; + +use super::{Swipe, SwipeDirection}; + +/// Wrapper component adding "swipe up" handling to `content`. +pub struct SwipeUpScreen { + content: T, + swipe: Swipe, +} + +pub enum SwipeUpScreenMsg { + Swiped, + Content(T), +} + +impl SwipeUpScreen +where + T: Component, +{ + pub fn new(content: T) -> Self { + Self { + content, + swipe: Swipe::new().up(), + } + } +} + +impl Component for SwipeUpScreen +where + T: Component, +{ + type Msg = SwipeUpScreenMsg; + + fn place(&mut self, bounds: Rect) -> Rect { + self.swipe.place(bounds); + self.content.place(bounds); + bounds + } + + fn event(&mut self, ctx: &mut EventCtx, event: Event) -> Option { + if let Some(SwipeDirection::Up) = self.swipe.event(ctx, event) { + return Some(SwipeUpScreenMsg::Swiped); + } + self.content + .event(ctx, event) + .map(SwipeUpScreenMsg::Content) + } + + fn paint(&mut self) { + todo!() + } + + fn render<'s>(&'s self, target: &mut impl Renderer<'s>) { + self.content.render(target); + } + + #[cfg(feature = "ui_bounds")] + fn bounds(&self, sink: &mut dyn FnMut(Rect)) { + self.content.bounds(sink); + } +} + +#[cfg(feature = "ui_debug")] +impl crate::trace::Trace for SwipeUpScreen +where + T: crate::trace::Trace, +{ + fn trace(&self, t: &mut dyn crate::trace::Tracer) { + t.component("SwipeUpScreen"); + t.child("content", &self.content); + } +} diff --git a/core/embed/rust/src/ui/model_mercury/constant.rs b/core/embed/rust/src/ui/model_mercury/constant.rs index 9f0d9e3d5..dbf3ea9cb 100644 --- a/core/embed/rust/src/ui/model_mercury/constant.rs +++ b/core/embed/rust/src/ui/model_mercury/constant.rs @@ -24,4 +24,4 @@ pub const SCREEN: Rect = screen(); /// Spacing between components (e.g. header and main content) and offsets from /// the side of the screen. Generally applied everywhere except the top side of /// the header. [px] -pub const SPACING: i16 = 2; +pub const SPACING: i16 = 2; diff --git a/core/embed/rust/src/ui/model_mercury/layout.rs b/core/embed/rust/src/ui/model_mercury/layout.rs index cbdb00622..76b30e6bf 100644 --- a/core/embed/rust/src/ui/model_mercury/layout.rs +++ b/core/embed/rust/src/ui/model_mercury/layout.rs @@ -54,7 +54,7 @@ use super::{ MnemonicKeyboard, MnemonicKeyboardMsg, NumberInputDialog, NumberInputDialogMsg, PassphraseKeyboard, PassphraseKeyboardMsg, PinKeyboard, PinKeyboardMsg, Progress, PromptScreen, SelectWordCount, SelectWordCountMsg, ShareWords, SimplePage, Slip39Input, - StatusScreen, VerticalMenu, VerticalMenuChoiceMsg, + StatusScreen, SwipeUpScreen, SwipeUpScreenMsg, VerticalMenu, VerticalMenuChoiceMsg, }, flow, theme, };