zorder/zlayer utilities
This commit is contained in:
parent
4560618d43
commit
7894cd4dfd
1 changed files with 68 additions and 2 deletions
|
@ -118,12 +118,50 @@ impl AreaLayerId {
|
||||||
pub struct ZOrder(pub i32);
|
pub struct ZOrder(pub i32);
|
||||||
|
|
||||||
impl ZOrder {
|
impl ZOrder {
|
||||||
const DEFAULT: ZOrder = ZOrder(0);
|
const BASE: ZOrder = ZOrder(0);
|
||||||
|
const ABOVE_ALL: ZOrder = ZOrder(i32::MAX);
|
||||||
|
const BELOW_ALL: ZOrder = ZOrder(i32::MIN);
|
||||||
|
|
||||||
|
/// Base z-order, corresponding to a level of 0
|
||||||
|
#[inline(always)]
|
||||||
|
pub fn base() -> Self {
|
||||||
|
Self::BASE
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Maximal z-order - nothing on the same area layer can render above this
|
||||||
|
#[inline(always)]
|
||||||
|
pub fn above_all() -> Self {
|
||||||
|
Self::ABOVE_ALL
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Minimal z-order - nothing on the same area layer can render below this
|
||||||
|
#[inline(always)]
|
||||||
|
pub fn below_all() -> Self {
|
||||||
|
Self::BELOW_ALL
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Above by one level
|
||||||
|
pub fn above(self) -> Self {
|
||||||
|
self.above_by(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Below by one level
|
||||||
|
pub fn below(self) -> Self {
|
||||||
|
self.below_by(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn above_by(self, levels: i32) -> Self {
|
||||||
|
Self(self.0.saturating_add(levels))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn below_by(self, levels: i32) -> Self {
|
||||||
|
Self(self.0.saturating_sub(levels))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for ZOrder {
|
impl Default for ZOrder {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self::DEFAULT
|
Self::BASE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,6 +185,7 @@ impl ZLayer {
|
||||||
Self { area_layer, z }
|
Self { area_layer, z }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Use base Z-level
|
||||||
pub fn from_area_layer(area_layer: AreaLayerId) -> Self {
|
pub fn from_area_layer(area_layer: AreaLayerId) -> Self {
|
||||||
Self::from_area_layer_z(area_layer, ZOrder::default())
|
Self::from_area_layer_z(area_layer, ZOrder::default())
|
||||||
}
|
}
|
||||||
|
@ -158,6 +197,33 @@ impl ZLayer {
|
||||||
pub fn background() -> Self {
|
pub fn background() -> Self {
|
||||||
Self::from_area_layer(AreaLayerId::background())
|
Self::from_area_layer(AreaLayerId::background())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
|
pub fn with_z(self, z: ZOrder) -> Self {
|
||||||
|
Self::from_area_layer_z(self.area_layer, z)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Above by one level
|
||||||
|
#[must_use]
|
||||||
|
pub fn above(self) -> Self {
|
||||||
|
self.with_z(self.z.above())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
|
pub fn above_by(self, levels: i32) -> Self {
|
||||||
|
self.with_z(self.z.above_by(levels))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Below one level
|
||||||
|
#[must_use]
|
||||||
|
pub fn below(self) -> Self {
|
||||||
|
self.with_z(self.z.below())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
|
pub fn below_by(self, levels: i32) -> Self {
|
||||||
|
self.with_z(self.z.below_by(levels))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A unique identifier of a specific [`Shape`] in a [`PaintList`].
|
/// A unique identifier of a specific [`Shape`] in a [`PaintList`].
|
||||||
|
|
Loading…
Reference in a new issue