Skip to main content

ModalLayer

Struct ModalLayer 

Source
pub struct ModalLayer<M> {
    pub modal: M,
    pub panel: Rectangle,
    pub y_offset: i32,
    pub dim_alpha: u8,
}
Expand description

Render layer for a modal presentation.

Fields§

§modal: M

Modal identifier.

§panel: Rectangle

Settled panel frame.

§y_offset: i32

Vertical offset applied during animation.

§dim_alpha: u8

Backdrop dimming alpha.

Implementations§

Source§

impl<M> ModalLayer<M>

Source

pub const fn new( modal: M, panel: Rectangle, y_offset: i32, dim_alpha: u8, ) -> Self

Creates a modal layer.

Examples found in repository?
src/modal.rs (line 105)
100    pub fn current_with_panel(&self, bounds: Rectangle, panel: Rectangle) -> Option<ModalLayer<M>> {
101        let offscreen = offscreen_offset(bounds, panel);
102
103        match self.state {
104            ModalState::Hidden => None,
105            ModalState::Visible { modal } => Some(ModalLayer::new(modal, panel, 0, DIM_ALPHA_MAX)),
106            ModalState::Showing { modal, animation } => {
107                let progress = animation.progress_permille();
108                Some(ModalLayer::new(
109                    modal,
110                    panel,
111                    lerp_i32(offscreen, 0, progress),
112                    lerp_u8(0, DIM_ALPHA_MAX, progress),
113                ))
114            }
115            ModalState::Hiding { modal, animation } => {
116                let progress = animation.progress_permille();
117                Some(ModalLayer::new(
118                    modal,
119                    panel,
120                    lerp_i32(0, offscreen, progress),
121                    lerp_u8(DIM_ALPHA_MAX, 0, progress),
122                ))
123            }
124        }
125    }
Source

pub fn translated_panel(&self) -> Rectangle

Returns the translated panel frame after applying y_offset.

Examples found in repository?
src/alert_host/mod.rs (line 134)
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    }
150
151    /// Draws the current alert and dimming layer.
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    }

Trait Implementations§

Source§

impl<M: Clone> Clone for ModalLayer<M>

Source§

fn clone(&self) -> ModalLayer<M>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<M: Debug> Debug for ModalLayer<M>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<M: PartialEq> PartialEq for ModalLayer<M>

Source§

fn eq(&self, other: &ModalLayer<M>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<M: Copy> Copy for ModalLayer<M>

Source§

impl<M: Eq> Eq for ModalLayer<M>

Source§

impl<M> StructuralPartialEq for ModalLayer<M>

Auto Trait Implementations§

§

impl<M> Freeze for ModalLayer<M>
where M: Freeze,

§

impl<M> RefUnwindSafe for ModalLayer<M>
where M: RefUnwindSafe,

§

impl<M> Send for ModalLayer<M>
where M: Send,

§

impl<M> Sync for ModalLayer<M>
where M: Sync,

§

impl<M> Unpin for ModalLayer<M>
where M: Unpin,

§

impl<M> UnsafeUnpin for ModalLayer<M>
where M: UnsafeUnpin,

§

impl<M> UnwindSafe for ModalLayer<M>
where M: 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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.