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//! # fn example() {
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(
21//! LayerIndex::ADORNER,
22//! WIDGET.id(),
23//! layer::AnchorOffset::out_top(),
24//! Text! {
25//! id = anchored;
26//! txt = "Example";
27//! widget::background_color = colors::BLUE;
28//! layout::y = 5;
29//! },
30//! );
31//! } else {
32//! LAYERS.remove(anchored);
33//! }
34//! inserted.set(!inserted.get());
35//! });
36//! layout::align = layout::Align::CENTER;
37//! child = Text!(inserted.map(|&o| if o { "Remove Layer" } else { "Insert Layer" }.into()));
38//! }
39//! # ; }
40//! ```
41//!
42//! Node operations always apply to the window content first then the layers, even with parallelism enabled,
43//! this means that layers always render over the window content and that layer widgets can react to normal widget
44//! updates within the same frame.
45//!
46//! # Full API
47//!
48//! See [`zng_wgt_layer`] for the full layers API.
49
50pub use zng_wgt_layer::{
51 AnchorMode, AnchorOffset, AnchorSize, AnchorTransform, LAYERS, LAYERS_INSERT_CMD, LAYERS_REMOVE_CMD, LayerIndex, adorner, adorner_fn,
52};