zng/
container.rs

1//! Container widget.
2//!
3//! Base widget for all widgets that are designed around a single child widget or a primary child widget surrounded by secondary widgets.
4//!
5//! # Child Inserts
6//!
7//! The example below demonstrates a container with a primary child that fills the available space not taken by the other children.
8//! The top child is also separated from the primary child by 5dip.
9//!
10//! ```
11//! use zng::prelude::*;
12//!
13//! # fn example() {
14//! # let _ =
15//! Container! {
16//!     child_spacing = 5;
17//!     child_top = Text!("secondary (top)");
18//!     child = Text! {
19//!         txt = "primary";
20//!         widget::background_color = colors::BLUE;
21//!     };
22//!     child_bottom = Text!("secondary (bottom)");
23//! }
24//! # ; }
25//! ```
26//!
27//! Note that `Window!` inherits from `Container!` to the example above could become the skeleton of a classic app window:
28//!
29//! ```
30//! # use zng::prelude::*;
31//! # fn example() {
32//! # fn tools() -> UiNode { widget::node::UiNode::nil() }
33//! # fn content() -> UiNode { widget::node::UiNode::nil() }
34//! # fn status() -> UiNode { widget::node::UiNode::nil() }
35//! # let _ =
36//! Window! {
37//!     child_out_top = tools();
38//!     child = content();
39//!     child_out_bottom = status();
40//! }
41//! # ; }
42//! ```
43//!
44//! Note that a similar layout could be achieved using widgets like [`Grid!`], but the child insert properties are a convenient
45//! way to define this kind of widget, also a container widget without child inserts does not pay any extra cost, the insertion
46//! layout implementation if fully contained to the insert properties.
47//!
48//! [`Grid!`]: struct@crate::grid::Grid
49//!
50//! # Child Nodes
51//!
52//! The child can by any [`IntoUiNode`] type, not just widgets, you can use this to plug nodes directly on the UI.
53//!
54//! ```
55//! use zng::{prelude::*, prelude_wgt::*};
56//!
57//! # fn example() {
58//! # let _ =
59//! Container! {
60//!     widget::background_color = colors::BLACK;
61//!     child_align = layout::Align::CENTER;
62//!     child = {
63//!         let size = Size::splat(40);
64//!         let mut render_size = PxSize::zero();
65//!         match_node_leaf(move |op| match op {
66//!             UiNodeOp::Measure { desired_size, .. } => *desired_size = size.layout(),
67//!             UiNodeOp::Layout { final_size, .. } => {
68//!                 render_size = Size::splat(40).layout();
69//!                 *final_size = render_size;
70//!             }
71//!             UiNodeOp::Render { frame } => frame.push_color(PxRect::from_size(render_size), FrameValue::Value(colors::GREEN.into())),
72//!             _ => {}
73//!         })
74//!     };
75//! }
76//! # ; }
77//! ```
78//!
79//! [`IntoUiNode`]: crate::widget::node::IntoUiNode
80//!
81//! # Full API
82//!
83//! See [`zng_wgt_container`] for the full widget API.
84
85pub use zng_wgt_container::{
86    ChildInsert, Container, child, child_bottom, child_end, child_insert, child_left, child_out_bottom, child_out_end, child_out_insert,
87    child_out_left, child_out_over, child_out_right, child_out_spacing, child_out_start, child_out_top, child_out_under, child_over,
88    child_right, child_spacing, child_start, child_top, child_under,
89};