pub struct ModalHost<M> { /* private fields */ }Expand description
Generic modal transition state machine used by higher-level hosts.
Implementations§
Source§impl<M: Copy> ModalHost<M>
impl<M: Copy> ModalHost<M>
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Creates an empty modal host.
Examples found in repository?
examples/alerts.rs (line 37)
11fn main() {
12 let bounds = Rectangle::new(Point::zero(), Size::new(320, 240));
13 let theme = support::theme();
14 let i18n = support::i18n();
15 let mut canvas = support::NullCanvas::new(bounds.size);
16
17 let spec = AlertSpec::confirm(
18 Localized::new("alert.title", "Delete item?"),
19 Localized::new("alert.message", "This action cannot be undone."),
20 );
21 let mut alert = AlertView::new(spec);
22 let panel = alert.panel(bounds, &theme, &i18n);
23 alert.draw(&mut canvas, panel, &theme, &i18n);
24 let _ = alert.handle_touch(TouchEvent::new(panel.center(), TouchPhase::Start, 1), panel);
25
26 let mut host = AlertHost::<u8, 2>::new();
27 let _ = host.present(7, spec);
28 let _ = host.layer(bounds, &theme, &i18n);
29 host.draw(&mut canvas, bounds, &theme, &i18n);
30 let _ = host.handle_touch(
31 TouchEvent::new(Point::new(160, 160), TouchPhase::End, 2),
32 bounds,
33 &theme,
34 &i18n,
35 );
36
37 let mut modal = ModalHost::new();
38 modal.show(3_u8);
39 let _ = modal.current(bounds, &theme);
40 let _ = Rgb565::BLACK;
41}More examples
Sourcepub fn show(&mut self, modal: M)
pub fn show(&mut self, modal: M)
Starts presenting modal.
Examples found in repository?
examples/alerts.rs (line 38)
11fn main() {
12 let bounds = Rectangle::new(Point::zero(), Size::new(320, 240));
13 let theme = support::theme();
14 let i18n = support::i18n();
15 let mut canvas = support::NullCanvas::new(bounds.size);
16
17 let spec = AlertSpec::confirm(
18 Localized::new("alert.title", "Delete item?"),
19 Localized::new("alert.message", "This action cannot be undone."),
20 );
21 let mut alert = AlertView::new(spec);
22 let panel = alert.panel(bounds, &theme, &i18n);
23 alert.draw(&mut canvas, panel, &theme, &i18n);
24 let _ = alert.handle_touch(TouchEvent::new(panel.center(), TouchPhase::Start, 1), panel);
25
26 let mut host = AlertHost::<u8, 2>::new();
27 let _ = host.present(7, spec);
28 let _ = host.layer(bounds, &theme, &i18n);
29 host.draw(&mut canvas, bounds, &theme, &i18n);
30 let _ = host.handle_touch(
31 TouchEvent::new(Point::new(160, 160), TouchPhase::End, 2),
32 bounds,
33 &theme,
34 &i18n,
35 );
36
37 let mut modal = ModalHost::new();
38 modal.show(3_u8);
39 let _ = modal.current(bounds, &theme);
40 let _ = Rgb565::BLACK;
41}More examples
Sourcepub fn dismiss(&mut self)
pub fn dismiss(&mut self)
Starts dismissing the current modal, if any.
Examples found in repository?
src/alert_host/mod.rs (line 58)
57 pub fn dismiss_presented(&mut self) {
58 self.host.dismiss();
59 }
60
61 /// Alias for [`Self::dismiss_presented`].
62 pub fn dismiss(&mut self) {
63 self.dismiss_presented();
64 }
65
66 /// Clears transient button state.
67 pub fn clear_touch_state(&mut self) {
68 if let Some(alert) = self.alert.as_mut() {
69 alert.clear_touch_state();
70 }
71 }
72
73 /// Returns whether the host is animating a modal transition.
74 pub const fn is_animating(&self) -> bool {
75 self.host.is_animating()
76 }
77
78 /// Advances modal animation state.
79 pub fn advance(&mut self, dt_ms: u32) -> bool {
80 let changed = self.host.advance(dt_ms);
81 if !self.host.has_modal() {
82 self.alert = None;
83 }
84 changed
85 }
86
87 /// Returns the currently presented modal key, if any.
88 pub fn presented_key(&self) -> Option<Modal> {
89 self.alert.as_ref().map(PresentedAlert::key)
90 }
91
92 /// Returns the title of the currently presented modal, if any.
93 pub fn presented_title(&self) -> Option<Localized<'a>> {
94 self.alert.as_ref().map(PresentedAlert::title)
95 }
96
97 /// Returns the current modal layer geometry.
98 pub fn layer(
99 &self,
100 bounds: Rectangle,
101 theme: &FsTheme,
102 i18n: &I18n<'a>,
103 ) -> Option<ModalLayer<Modal>> {
104 let alert = self.alert.as_ref()?;
105 let panel = alert.panel(bounds, theme, i18n);
106 self.host.current_with_panel(bounds, panel)
107 }
108
109 /// Routes one touch event to the alert host.
110 pub fn handle_touch(
111 &mut self,
112 touch: TouchEvent,
113 bounds: Rectangle,
114 theme: &FsTheme,
115 i18n: &I18n<'a>,
116 ) -> AlertHostResponse<Modal> {
117 let Some(alert) = self.alert.as_mut() else {
118 return AlertHostResponse {
119 action: None,
120 captured: false,
121 redraw: false,
122 };
123 };
124
125 let panel = alert.panel(bounds, theme, i18n);
126 let Some(layer) = self.host.current_with_panel(bounds, panel) else {
127 return AlertHostResponse {
128 action: None,
129 captured: false,
130 redraw: false,
131 };
132 };
133
134 let response = alert.handle_touch(touch, layer.translated_panel());
135 if let Some(action) = response.action {
136 self.host.dismiss();
137 return AlertHostResponse {
138 action: Some((alert.key(), action)),
139 captured: true,
140 redraw: true,
141 };
142 }
143
144 AlertHostResponse {
145 action: None,
146 captured: true,
147 redraw: response.redraw,
148 }
149 }Sourcepub const fn is_animating(&self) -> bool
pub const fn is_animating(&self) -> bool
Returns whether a show or hide animation is in progress.
Sourcepub const fn has_modal(&self) -> bool
pub const fn has_modal(&self) -> bool
Returns whether any modal is currently owned by the host.
Sourcepub fn current(
&self,
bounds: Rectangle,
theme: &FsTheme,
) -> Option<ModalLayer<M>>
pub fn current( &self, bounds: Rectangle, theme: &FsTheme, ) -> Option<ModalLayer<M>>
Returns the current modal layer using the default themed panel.
Examples found in repository?
examples/alerts.rs (line 39)
11fn main() {
12 let bounds = Rectangle::new(Point::zero(), Size::new(320, 240));
13 let theme = support::theme();
14 let i18n = support::i18n();
15 let mut canvas = support::NullCanvas::new(bounds.size);
16
17 let spec = AlertSpec::confirm(
18 Localized::new("alert.title", "Delete item?"),
19 Localized::new("alert.message", "This action cannot be undone."),
20 );
21 let mut alert = AlertView::new(spec);
22 let panel = alert.panel(bounds, &theme, &i18n);
23 alert.draw(&mut canvas, panel, &theme, &i18n);
24 let _ = alert.handle_touch(TouchEvent::new(panel.center(), TouchPhase::Start, 1), panel);
25
26 let mut host = AlertHost::<u8, 2>::new();
27 let _ = host.present(7, spec);
28 let _ = host.layer(bounds, &theme, &i18n);
29 host.draw(&mut canvas, bounds, &theme, &i18n);
30 let _ = host.handle_touch(
31 TouchEvent::new(Point::new(160, 160), TouchPhase::End, 2),
32 bounds,
33 &theme,
34 &i18n,
35 );
36
37 let mut modal = ModalHost::new();
38 modal.show(3_u8);
39 let _ = modal.current(bounds, &theme);
40 let _ = Rgb565::BLACK;
41}Sourcepub fn current_with_panel(
&self,
bounds: Rectangle,
panel: Rectangle,
) -> Option<ModalLayer<M>>
pub fn current_with_panel( &self, bounds: Rectangle, panel: Rectangle, ) -> Option<ModalLayer<M>>
Returns the current modal layer using an explicit panel rectangle.
Examples found in repository?
More examples
src/alert_host/mod.rs (line 106)
98 pub fn layer(
99 &self,
100 bounds: Rectangle,
101 theme: &FsTheme,
102 i18n: &I18n<'a>,
103 ) -> Option<ModalLayer<Modal>> {
104 let alert = self.alert.as_ref()?;
105 let panel = alert.panel(bounds, theme, i18n);
106 self.host.current_with_panel(bounds, panel)
107 }
108
109 /// Routes one touch event to the alert host.
110 pub fn handle_touch(
111 &mut self,
112 touch: TouchEvent,
113 bounds: Rectangle,
114 theme: &FsTheme,
115 i18n: &I18n<'a>,
116 ) -> AlertHostResponse<Modal> {
117 let Some(alert) = self.alert.as_mut() else {
118 return AlertHostResponse {
119 action: None,
120 captured: false,
121 redraw: false,
122 };
123 };
124
125 let panel = alert.panel(bounds, theme, i18n);
126 let Some(layer) = self.host.current_with_panel(bounds, panel) else {
127 return AlertHostResponse {
128 action: None,
129 captured: false,
130 redraw: false,
131 };
132 };
133
134 let response = alert.handle_touch(touch, layer.translated_panel());
135 if let Some(action) = response.action {
136 self.host.dismiss();
137 return AlertHostResponse {
138 action: Some((alert.key(), action)),
139 captured: true,
140 redraw: true,
141 };
142 }
143
144 AlertHostResponse {
145 action: None,
146 captured: true,
147 redraw: response.redraw,
148 }
149 }Trait Implementations§
impl<M: Copy> Copy for ModalHost<M>
impl<M: Eq> Eq for ModalHost<M>
impl<M> StructuralPartialEq for ModalHost<M>
Auto Trait Implementations§
impl<M> Freeze for ModalHost<M>where
M: Freeze,
impl<M> RefUnwindSafe for ModalHost<M>where
M: RefUnwindSafe,
impl<M> Send for ModalHost<M>where
M: Send,
impl<M> Sync for ModalHost<M>where
M: Sync,
impl<M> Unpin for ModalHost<M>where
M: Unpin,
impl<M> UnsafeUnpin for ModalHost<M>where
M: UnsafeUnpin,
impl<M> UnwindSafe for ModalHost<M>where
M: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Casts the value.
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Casts the value.
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> OverflowingAs for T
impl<T> OverflowingAs for T
Source§fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
Casts the value.
Source§impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
Source§fn overflowing_cast_from(src: Src) -> (Dst, bool)
fn overflowing_cast_from(src: Src) -> (Dst, bool)
Casts the value.
Source§impl<T> SaturatingAs for T
impl<T> SaturatingAs for T
Source§fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
Casts the value.
Source§impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
Source§fn saturating_cast_from(src: Src) -> Dst
fn saturating_cast_from(src: Src) -> Dst
Casts the value.
Source§impl<T> UnwrappedAs for T
impl<T> UnwrappedAs for T
Source§fn unwrapped_as<Dst>(self) -> Dstwhere
T: UnwrappedCast<Dst>,
fn unwrapped_as<Dst>(self) -> Dstwhere
T: UnwrappedCast<Dst>,
Casts the value.
Source§impl<Src, Dst> UnwrappedCastFrom<Src> for Dstwhere
Src: UnwrappedCast<Dst>,
impl<Src, Dst> UnwrappedCastFrom<Src> for Dstwhere
Src: UnwrappedCast<Dst>,
Source§fn unwrapped_cast_from(src: Src) -> Dst
fn unwrapped_cast_from(src: Src) -> Dst
Casts the value.
Source§impl<T> WrappingAs for T
impl<T> WrappingAs for T
Source§fn wrapping_as<Dst>(self) -> Dstwhere
T: WrappingCast<Dst>,
fn wrapping_as<Dst>(self) -> Dstwhere
T: WrappingCast<Dst>,
Casts the value.
Source§impl<Src, Dst> WrappingCastFrom<Src> for Dstwhere
Src: WrappingCast<Dst>,
impl<Src, Dst> WrappingCastFrom<Src> for Dstwhere
Src: WrappingCast<Dst>,
Source§fn wrapping_cast_from(src: Src) -> Dst
fn wrapping_cast_from(src: Src) -> Dst
Casts the value.