zng/
stack.rs

1#![cfg(feature = "stack")]
2
3//! Stack layout widget, nodes and properties.
4//!
5//! The [`Stack!`](struct@Stack) widget is a layout panel stacks children, in Z and in a [`direction`](struct@Stack#method.direction).
6//!
7//! The example below declares a stack that animates between directions.
8//!
9//! ```
10//! use zng::prelude::*;
11//!
12//! # fn example() {
13//! let direction = var(StackDirection::top_to_bottom());
14//! # let _ =
15//! Stack! {
16//!     direction = direction.easing(1.secs(), |t| easing::ease_out(easing::expo, t));
17//!     spacing = 10;
18//!     children_align = layout::Align::CENTER;
19//!
20//!     toggle::selector = toggle::Selector::single(direction);
21//!     children =
22//!         [
23//!             ("top_to_bottom", StackDirection::top_to_bottom()),
24//!             ("left_to_right", StackDirection::left_to_right()),
25//!             ("bottom_to_top", StackDirection::bottom_to_top()),
26//!             ("right_to_left", StackDirection::right_to_left()),
27//!             (
28//!                 "diagonal",
29//!                 StackDirection {
30//!                     place: layout::Point::bottom_right(),
31//!                     origin: layout::Point::top_left(),
32//!                     is_rtl_aware: false,
33//!                 },
34//!             ),
35//!         ]
36//!         .into_iter()
37//!         .map(|(label, direction)| {
38//!             Toggle! {
39//!                 child = Text!(label);
40//!                 value::<StackDirection> = direction;
41//!             }
42//!         }),
43//!     ;
44//! }
45//! # ; }
46//! ```
47//!
48//! Note that the [`StackDirection`] is defined by two points, the stack widget resolves the `place` point in the previous
49//! child and the `origin` point in the next child and then positions the next child so that both points overlap. This enables
50//! custom layouts like partially overlapping children and the traditional horizontal and vertical stack.
51//!
52//! # Full API
53//!
54//! See [`zng_wgt_stack`] for the full widget API.
55
56pub use zng_wgt_stack::{
57    Stack, StackDirection, WidgetInfoStackExt, get_index, get_index_len, get_rev_index, is_even, is_first, is_last, is_odd, lazy_sample,
58    lazy_size, node, stack_nodes,
59};