Skip to main content

Layer

Struct Layer 

Source
pub struct Layer<K> {
    pub key: K,
    pub frame: Rectangle,
    pub offset: Point,
}
Expand description

One render layer used by stack-style presentation.

Fields§

§key: K

Stable layer key.

§frame: Rectangle

Base frame for the layer.

§offset: Point

Translation offset applied during animation.

Implementations§

Source§

impl<K> Layer<K>

Source

pub const fn new(key: K, frame: Rectangle, offset: Point) -> Self

Creates a layer.

Examples found in repository?
src/stack_view.rs (line 95)
80    pub fn root(frame: Rectangle, title: Localized<'a>) -> Self {
81        let header_height = HEADER_HEIGHT.min(frame.size.height.saturating_sub(1));
82        let header = Rectangle::new(frame.top_left, Size::new(frame.size.width, header_height));
83        let body = Rectangle::new(
84            frame.top_left + Point::new(0, header_height as i32),
85            Size::new(
86                frame.size.width,
87                frame.size.height.saturating_sub(header_height),
88            ),
89        );
90        Self {
91            frame,
92            header,
93            body,
94            layers: StackLayers {
95                base: Layer::new((), body, Point::zero()),
96                overlay: None,
97            },
98            back_button: None,
99            back_title: None,
100            active_title: HeaderTitle {
101                title,
102                center: header.center(),
103            },
104            secondary_title: None,
105        }
106    }
More examples
Hide additional examples
src/stack.rs (line 174)
172    pub fn layers(&self, frame: Rectangle) -> StackLayers<K> {
173        let width = frame.size.width as i32;
174        let idle = Layer::new(self.top(), frame, Point::zero());
175
176        match self.transition {
177            None => StackLayers {
178                base: idle,
179                overlay: None,
180            },
181            Some(Transition::Push {
182                from,
183                to,
184                animation,
185            }) => {
186                let progress = animation.progress_permille();
187                let base = Layer::new(from, frame, Point::zero());
188                let overlay = Layer::new(to, frame, Point::new(lerp_i32(width, 0, progress), 0));
189                StackLayers {
190                    base,
191                    overlay: Some(overlay),
192                }
193            }
194            Some(Transition::Pop {
195                from,
196                to,
197                animation,
198            }) => {
199                let progress = animation.progress_permille();
200                let base = Layer::new(to, frame, Point::zero());
201                let overlay = Layer::new(from, frame, Point::new(lerp_i32(0, width, progress), 0));
202                StackLayers {
203                    base,
204                    overlay: Some(overlay),
205                }
206            }
207        }
208    }
Source

pub fn translated_frame(&self) -> Rectangle

Returns the translated frame after applying the current offset.

Examples found in repository?
src/containers.rs (line 180)
175    pub fn motion(&self, frame: Rectangle) -> Option<StackMotion> {
176        let nav = self.nav_view(frame);
177        nav.layers.overlay.map(|overlay| StackMotion {
178            header: nav.header,
179            body: nav.body,
180            overlay: overlay.translated_frame(),
181        })
182    }
More examples
Hide additional examples
src/app/render.rs (line 57)
52    pub fn stack_motion(&self, bounds: Rectangle) -> Option<StackMotion> {
53        let nav = self.nav_view(bounds);
54        nav.layers.overlay.map(|overlay| StackMotion {
55            header: nav.header,
56            body: nav.body,
57            overlay: overlay.translated_frame(),
58        })
59    }

Trait Implementations§

Source§

impl<K: Clone> Clone for Layer<K>

Source§

fn clone(&self) -> Layer<K>

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<K: Debug> Debug for Layer<K>

Source§

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

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

impl<K: PartialEq> PartialEq for Layer<K>

Source§

fn eq(&self, other: &Layer<K>) -> 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<K: Copy> Copy for Layer<K>

Source§

impl<K: Eq> Eq for Layer<K>

Source§

impl<K> StructuralPartialEq for Layer<K>

Auto Trait Implementations§

§

impl<K> Freeze for Layer<K>
where K: Freeze,

§

impl<K> RefUnwindSafe for Layer<K>
where K: RefUnwindSafe,

§

impl<K> Send for Layer<K>
where K: Send,

§

impl<K> Sync for Layer<K>
where K: Sync,

§

impl<K> Unpin for Layer<K>
where K: Unpin,

§

impl<K> UnsafeUnpin for Layer<K>
where K: UnsafeUnpin,

§

impl<K> UnwindSafe for Layer<K>
where K: 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.