Skip to main content

AlertHost

Struct AlertHost 

Source
pub struct AlertHost<'a, Modal, const MAX_ACTIONS: usize> { /* private fields */ }
Expand description

High-level modal alert presenter owned by the framework.

Implementations§

Source§

impl<'a, Modal, const MAX_ACTIONS: usize> AlertHost<'a, Modal, MAX_ACTIONS>
where Modal: Copy + Eq,

Source

pub const fn new() -> Self

Creates an empty alert host.

Examples found in repository?
examples/alerts.rs (line 26)
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}
Source

pub fn present<const N: usize>( &mut self, key: Modal, spec: AlertSpec<'a, N>, ) -> Result<(), AlertHostError>

Presents a new alert.

Examples found in repository?
examples/alerts.rs (line 27)
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}
Source

pub fn dismiss_presented(&mut self)

Dismisses the currently presented alert, if any.

Examples found in repository?
src/alert_host/mod.rs (line 63)
62    pub fn dismiss(&mut self) {
63        self.dismiss_presented();
64    }
Source

pub fn dismiss(&mut self)

Source

pub fn clear_touch_state(&mut self)

Clears transient button state.

Source

pub const fn is_animating(&self) -> bool

Returns whether the host is animating a modal transition.

Source

pub fn advance(&mut self, dt_ms: u32) -> bool

Advances modal animation state.

Source

pub fn presented_key(&self) -> Option<Modal>

Returns the currently presented modal key, if any.

Source

pub fn presented_title(&self) -> Option<Localized<'a>>

Returns the title of the currently presented modal, if any.

Source

pub fn layer( &self, bounds: Rectangle, theme: &FsTheme, i18n: &I18n<'a>, ) -> Option<ModalLayer<Modal>>

Returns the current modal layer geometry.

Examples found in repository?
examples/alerts.rs (line 28)
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
Hide additional examples
src/alert_host/mod.rs (line 159)
152    pub fn draw<D>(&self, display: &mut D, bounds: Rectangle, theme: &FsTheme, i18n: &I18n<'a>)
153    where
154        D: UiCanvas,
155    {
156        let Some(alert) = self.alert.as_ref() else {
157            return;
158        };
159        let Some(layer) = self.layer(bounds, theme, i18n) else {
160            return;
161        };
162
163        display.dim_rect(bounds, layer.dim_alpha);
164        alert.draw(display, layer.translated_panel(), theme, i18n);
165    }
Source

pub fn handle_touch( &mut self, touch: TouchEvent, bounds: Rectangle, theme: &FsTheme, i18n: &I18n<'a>, ) -> AlertHostResponse<Modal>

Routes one touch event to the alert host.

Examples found in repository?
examples/alerts.rs (lines 30-35)
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}
Source

pub fn draw<D>( &self, display: &mut D, bounds: Rectangle, theme: &FsTheme, i18n: &I18n<'a>, )
where D: UiCanvas,

Draws the current alert and dimming layer.

Examples found in repository?
examples/alerts.rs (line 29)
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}

Auto Trait Implementations§

§

impl<'a, Modal, const MAX_ACTIONS: usize> Freeze for AlertHost<'a, Modal, MAX_ACTIONS>
where Modal: Freeze,

§

impl<'a, Modal, const MAX_ACTIONS: usize> RefUnwindSafe for AlertHost<'a, Modal, MAX_ACTIONS>
where Modal: RefUnwindSafe,

§

impl<'a, Modal, const MAX_ACTIONS: usize> Send for AlertHost<'a, Modal, MAX_ACTIONS>
where Modal: Send,

§

impl<'a, Modal, const MAX_ACTIONS: usize> Sync for AlertHost<'a, Modal, MAX_ACTIONS>
where Modal: Sync,

§

impl<'a, Modal, const MAX_ACTIONS: usize> Unpin for AlertHost<'a, Modal, MAX_ACTIONS>
where Modal: Unpin,

§

impl<'a, Modal, const MAX_ACTIONS: usize> UnsafeUnpin for AlertHost<'a, Modal, MAX_ACTIONS>
where Modal: UnsafeUnpin,

§

impl<'a, Modal, const MAX_ACTIONS: usize> UnwindSafe for AlertHost<'a, Modal, MAX_ACTIONS>
where Modal: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.