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: MModal identifier.
panel: RectangleSettled panel frame.
y_offset: i32Vertical offset applied during animation.
dim_alpha: u8Backdrop dimming alpha.
Implementations§
Source§impl<M> ModalLayer<M>
impl<M> ModalLayer<M>
Sourcepub const fn new(
modal: M,
panel: Rectangle,
y_offset: i32,
dim_alpha: u8,
) -> Self
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 }Sourcepub fn translated_panel(&self) -> Rectangle
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>
impl<M: Clone> Clone for ModalLayer<M>
Source§fn clone(&self) -> ModalLayer<M>
fn clone(&self) -> ModalLayer<M>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<M: Debug> Debug for ModalLayer<M>
impl<M: Debug> Debug for ModalLayer<M>
Source§impl<M: PartialEq> PartialEq for ModalLayer<M>
impl<M: PartialEq> PartialEq for ModalLayer<M>
impl<M: Copy> Copy for ModalLayer<M>
impl<M: Eq> Eq for ModalLayer<M>
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> 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.