#[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
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-ui’ PerfOverlayApp 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§
Trait Implementations§
Source§impl Ord for Layer
impl Ord for Layer
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for Layer
impl PartialOrd for Layer
impl Copy for Layer
impl Eq for Layer
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> 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<C> WithAlpha for Cwhere
C: Copy,
impl<C> WithAlpha for Cwhere
C: Copy,
§fn with_alpha_first<A>(self, alpha: A) -> AlphaFirst<A, Self>
fn with_alpha_first<A>(self, alpha: A) -> AlphaFirst<A, Self>
self with alpha, storing alpha before the color in memory
(see [AlphaFirst]).§fn with_alpha_last<A>(self, alpha: A) -> AlphaLast<A, Self>
fn with_alpha_last<A>(self, alpha: A) -> AlphaLast<A, Self>
self with alpha, storing alpha after the color in memory
(see [AlphaLast]).