zng/layer.rs
1//! Window layers.
2//!
3//! The window layers is a z-order stacking panel that fills the window content area, widgets can be inserted
4//! with a *z-index* that is the [`LayerIndex`]. Layers can be anchored to a normal widget, positioned relative
5//! to it with linked visibility.
6//!
7//! The [`LAYERS`] service can be used to insert and remove layers, the example below uses it to *toggle* a
8//! an adorner positioned relative to the button that inserts and removes it.
9//!
10//! ```
11//! use zng::prelude::*;
12//! # let _scope = APP.defaults();
13//!
14//! let inserted = var(false);
15//! let anchored = WidgetId::new_unique();
16//! # let _ =
17//! Button! {
18//! on_click = hn!(inserted, |_| {
19//! if !inserted.get() {
20//! LAYERS.insert_anchored(LayerIndex::ADORNER, WIDGET.id(), layer::AnchorOffset::out_top(), Text! {
21//! id = anchored;
22//! txt = "Example";
23//! widget::background_color = colors::BLUE;
24//! layout::y = 5;
25//! });
26//! } else {
27//! LAYERS.remove(anchored);
28//! }
29//! inserted.set(!inserted.get());
30//! });
31//! layout::align = layout::Align::CENTER;
32//! child = Text!(inserted.map(|&o| if o { "Remove Layer" } else { "Insert Layer" }.into()));
33//! }
34//! # ;
35//! ```
36//!
37//! Node operations always apply to the window content first then the layers, even with parallelism enabled,
38//! this means that layers always render over the window content and that layer widgets can react to normal widget
39//! updates within the same frame.
40//!
41//! # Full API
42//!
43//! See [`zng_wgt_layer`] for the full layers API.
44
45pub use zng_wgt_layer::{
46 AnchorMode, AnchorOffset, AnchorSize, AnchorTransform, LAYERS, LAYERS_INSERT_CMD, LAYERS_REMOVE_CMD, LayerIndex, adorner, adorner_fn,
47};