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//! # let _scope = APP.defaults();
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//! ("top_to_bottom", StackDirection::top_to_bottom()),
23//! ("left_to_right", StackDirection::left_to_right()),
24//! ("bottom_to_top", StackDirection::bottom_to_top()),
25//! ("right_to_left", StackDirection::right_to_left()),
26//! ("diagonal", StackDirection {
27//! place: layout::Point::bottom_right(),
28//! origin: layout::Point::top_left(),
29//! is_rtl_aware: false,
30//! }),
31//! ]
32//! .into_iter()
33//! .map(|(label, direction)| Toggle! {
34//! child = Text!(label);
35//! value::<StackDirection> = direction;
36//! })
37//! .collect::<UiVec>();
38//! }
39//! # ;
40//! ```
41//!
42//! Note that the [`StackDirection`] is defined by two points, the stack widget resolves the `place` point in the previous
43//! child and the `origin` point in the next child and then positions the next child so that both points overlap. This enables
44//! custom layouts like partially overlapping children and the traditional horizontal and vertical stack.
45//!
46//! # Full API
47//!
48//! See [`zng_wgt_stack`] for the full widget API.
49
50pub use zng_wgt_stack::{
51 Stack, StackDirection, WidgetInfoStackExt, get_index, get_index_len, get_rev_index, is_even, is_first, is_last, is_odd, lazy_sample,
52 lazy_size, node, stack_nodes, stack_nodes_layout_by,
53};