Skip to main content

Layer

Enum Layer 

Source
#[non_exhaustive]
pub enum Layer { World, Hud, Overlay, Debug, }
Expand description

A named z-order tier for Surface::on_tier, covering the split most apps with overlapping UI actually need.

Layers are how overlapping UI avoids depending on draw order: a caller who paints a dropdown on Layer::Overlay gets it on top of the active screen regardless of whether the screen or the dropdown drew first this frame, so the two don’t have to agree on an ordering (contrast with painting both through the same layer, where whichever call happens to run last wins).

Layer derives Ord over its declaration order, so Layer::World < Layer::Hud < Layer::Overlay < Layer::Debug holds without spelling out the underlying grid layer ids – the same relationship Surface::on_tier relies on to keep Layer::Debug the top-most tier no matter what else is open.

This is a convention, not a restriction: Surface::on_layer still accepts any u8, and a tile map or sprite-heavy app with its own multi-layer scheme (terrain/items/actors/…) has no reason to route through Layer at all. Layer exists for the overlapping-UI case: chrome, popups, debug HUDs, where a small, shared, named split is worth more than 256 open numeric ids.

§Examples

A persistent HUD bar and a dropdown that must paint over it, in either order, because they’re on different tiers rather than racing to draw last:

use retroglyph_core::color::Style;
use retroglyph_core::grid::{Grid, Rect};
use retroglyph_core::surface::{Layer, Surface};

let area = Rect::new(0, 0, 20, 5);
let mut grid = Grid::new(20, 5);
let mut surface = Surface::new(&mut grid, area, Layer::World.as_u8());

// The active screen draws on `World`.
surface.print((0, 0), "screen content", Style::default());

// Chrome draws on `Hud`, above the screen.
surface.on_tier(Layer::Hud).print((0, 0), "File  Edit  View", Style::default());

// A dropdown draws on `Overlay`, above the HUD: painting it before or after the two calls
// above makes no difference, because it's on a higher tier, not drawn later.
surface.on_tier(Layer::Overlay).print((0, 1), "New", Style::default());

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

World

The active screen: terrain, entities, game/app content. Grid layer 0.

§

Hud

Persistent chrome: menu bars, status lines, HUD. Grid layer 1.

§

Overlay

Popups, dropdowns, modals, painted over Layer::World and Layer::Hud regardless of draw order. Grid layer 2.

§

Debug

Debug and dev tooling. Always the top-most tier, so it stays visible over an open Layer::Overlay rather than being hidden underneath one. Grid layer 3.

retroglyph-uiPerfOverlayApp default layer is defined as Layer::Debug.as_u8() for exactly this reason: a perf HUD that a popup could paint over would be useless whenever an app actually has a popup open.

Implementations§

Source§

impl Layer

Source

pub const fn as_u8(self) -> u8

This tier’s underlying grid layer id, for Surface::on_layer/Grid APIs that take a raw u8.

Trait Implementations§

Source§

impl Clone for Layer

Source§

fn clone(&self) -> Layer

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Layer

Source§

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

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

impl Default for Layer

Source§

fn default() -> Layer

Returns the “default value” for a type. Read more
Source§

impl From<Layer> for u8

Source§

fn from(layer: Layer) -> Self

Converts to this type from the input type.
Source§

impl Hash for Layer

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for Layer

Source§

fn cmp(&self, other: &Layer) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Layer

Source§

fn eq(&self, other: &Layer) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 PartialOrd for Layer

Source§

fn partial_cmp(&self, other: &Layer) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Copy for Layer

Source§

impl Eq for Layer

Source§

impl StructuralPartialEq for Layer

Auto Trait Implementations§

§

impl Freeze for Layer

§

impl RefUnwindSafe for Layer

§

impl Send for Layer

§

impl Sync for Layer

§

impl Unpin for Layer

§

impl UnsafeUnpin for Layer

§

impl UnwindSafe for Layer

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> 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<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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
§

impl<C> WithAlpha for C
where C: Copy,

§

fn with_alpha_first<A>(self, alpha: A) -> AlphaFirst<A, Self>

Wraps self with alpha, storing alpha before the color in memory (see [AlphaFirst]).
§

fn with_alpha_last<A>(self, alpha: A) -> AlphaLast<A, Self>

Wraps self with alpha, storing alpha after the color in memory (see [AlphaLast]).