Skip to main content

devela/ui/view/
layer.rs

1// devela/src/ui/view/layer.rs
2//
3//! Defines [`UiLayer`].
4//
5
6#[doc = crate::_tags!(ui ord)]
7/// Visual ordering layer for a UI view.
8#[doc = crate::_doc_meta! {
9    location("ui/view", struct UiLayer),
10    test_size_of(UiLayer = 2|16; niche !Option),
11}]
12#[must_use]
13#[repr(transparent)]
14#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
15pub struct UiLayer(i16);
16
17#[rustfmt::skip]
18impl UiLayer {
19    /// The default visual layer.
20    pub const BASE: Self = Self(0);
21
22    /// Constructs a visual layer from its raw value.
23    pub const fn new(raw: i16) -> Self { Self(raw) }
24
25    /// Returns the raw layer value.
26    #[must_use]
27    pub const fn raw(self) -> i16 { self.0 }
28
29    /// Returns the next higher layer.
30    pub const fn above(self) -> Self { Self(self.0 + 1) }
31    /// Returns the next lower layer.
32    pub const fn below(self) -> Self { Self(self.0 - 1) }
33}