mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-07 22:10:57 +00:00
feat(core/ui/): introduce SwipeUpScreen
A simple wrapper of a component which supports returning PageMsg::Confirmed if swipe up action was detected.
This commit is contained in:
parent
6b76ec0413
commit
7905770e7e
@ -28,6 +28,7 @@ mod share_words;
|
|||||||
mod simple_page;
|
mod simple_page;
|
||||||
mod status_screen;
|
mod status_screen;
|
||||||
mod swipe;
|
mod swipe;
|
||||||
|
mod swipe_up_screen;
|
||||||
mod welcome_screen;
|
mod welcome_screen;
|
||||||
|
|
||||||
#[cfg(feature = "translations")]
|
#[cfg(feature = "translations")]
|
||||||
@ -66,6 +67,7 @@ pub use share_words::ShareWords;
|
|||||||
pub use simple_page::SimplePage;
|
pub use simple_page::SimplePage;
|
||||||
pub use status_screen::StatusScreen;
|
pub use status_screen::StatusScreen;
|
||||||
pub use swipe::{Swipe, SwipeDirection};
|
pub use swipe::{Swipe, SwipeDirection};
|
||||||
|
pub use swipe_up_screen::{SwipeUpScreen, SwipeUpScreenMsg};
|
||||||
pub use vertical_menu::{VerticalMenu, VerticalMenuChoiceMsg};
|
pub use vertical_menu::{VerticalMenu, VerticalMenuChoiceMsg};
|
||||||
pub use welcome_screen::WelcomeScreen;
|
pub use welcome_screen::WelcomeScreen;
|
||||||
|
|
||||||
|
@ -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<T> {
|
||||||
|
content: T,
|
||||||
|
swipe: Swipe,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum SwipeUpScreenMsg<T> {
|
||||||
|
Swiped,
|
||||||
|
Content(T),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> SwipeUpScreen<T>
|
||||||
|
where
|
||||||
|
T: Component,
|
||||||
|
{
|
||||||
|
pub fn new(content: T) -> Self {
|
||||||
|
Self {
|
||||||
|
content,
|
||||||
|
swipe: Swipe::new().up(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> Component for SwipeUpScreen<T>
|
||||||
|
where
|
||||||
|
T: Component,
|
||||||
|
{
|
||||||
|
type Msg = SwipeUpScreenMsg<T::Msg>;
|
||||||
|
|
||||||
|
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<Self::Msg> {
|
||||||
|
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<T> crate::trace::Trace for SwipeUpScreen<T>
|
||||||
|
where
|
||||||
|
T: crate::trace::Trace,
|
||||||
|
{
|
||||||
|
fn trace(&self, t: &mut dyn crate::trace::Tracer) {
|
||||||
|
t.component("SwipeUpScreen");
|
||||||
|
t.child("content", &self.content);
|
||||||
|
}
|
||||||
|
}
|
@ -24,4 +24,4 @@ pub const SCREEN: Rect = screen();
|
|||||||
/// Spacing between components (e.g. header and main content) and offsets from
|
/// 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 side of the screen. Generally applied everywhere except the top side of
|
||||||
/// the header. [px]
|
/// the header. [px]
|
||||||
pub const SPACING: i16 = 2;
|
pub const SPACING: i16 = 2;
|
||||||
|
@ -54,7 +54,7 @@ use super::{
|
|||||||
MnemonicKeyboard, MnemonicKeyboardMsg, NumberInputDialog, NumberInputDialogMsg,
|
MnemonicKeyboard, MnemonicKeyboardMsg, NumberInputDialog, NumberInputDialogMsg,
|
||||||
PassphraseKeyboard, PassphraseKeyboardMsg, PinKeyboard, PinKeyboardMsg, Progress,
|
PassphraseKeyboard, PassphraseKeyboardMsg, PinKeyboard, PinKeyboardMsg, Progress,
|
||||||
PromptScreen, SelectWordCount, SelectWordCountMsg, ShareWords, SimplePage, Slip39Input,
|
PromptScreen, SelectWordCount, SelectWordCountMsg, ShareWords, SimplePage, Slip39Input,
|
||||||
StatusScreen, VerticalMenu, VerticalMenuChoiceMsg,
|
StatusScreen, SwipeUpScreen, SwipeUpScreenMsg, VerticalMenu, VerticalMenuChoiceMsg,
|
||||||
},
|
},
|
||||||
flow, theme,
|
flow, theme,
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user