Expand description
Container widget.
Base widget for all widgets that are designed around a single child widget or a primary child widget surrounded by secondary widgets.
§Child Inserts
The example below demonstrates a container with a primary child that fills the available space not taken by the other children. The top child is also separated from the primary child by 5dip.
use zng::prelude::*;
Container! {
child_spacing = 5;
child_top = Text!("secondary (top)");
child = Text! {
txt = "primary";
widget::background_color = colors::BLUE;
};
child_bottom = Text!("secondary (bottom)");
}Note that Window! inherits from Container! to the example above could become the skeleton of a classic app window:
Window! {
child_out_top = tools();
child = content();
child_out_bottom = status();
}Note that a similar layout could be achieved using widgets like Grid!, but the child insert properties are a convenient
way to define this kind of widget, also a container widget without child inserts does not pay any extra cost, the insertion
layout implementation if fully contained to the insert properties.
§Child Nodes
The child can by any IntoUiNode type, not just widgets, you can use this to plug nodes directly on the UI.
use zng::{prelude::*, prelude_wgt::*};
Container! {
widget::background_color = colors::BLACK;
child_align = layout::Align::CENTER;
child = {
let size = Size::splat(40);
let mut render_size = PxSize::zero();
match_node_leaf(move |op| match op {
UiNodeOp::Measure { desired_size, .. } => *desired_size = size.layout(),
UiNodeOp::Layout { final_size, .. } => {
render_size = Size::splat(40).layout();
*final_size = render_size;
}
UiNodeOp::Render { frame } => frame.push_color(PxRect::from_size(render_size), FrameValue::Value(colors::GREEN.into())),
_ => {}
})
};
}§Full API
See zng_wgt_container for the full widget API.
Structs§
- Container
WBase container.
Enums§
- Child
Insert - Placement of a node inserted by the
child_insertproperty.
Functions§
- child
PThe widget’s child.- child_
bottom PInsertnodebelow the widget’s child.- child_
end PInsertnodeto the right of the widget’s child in LTR contexts or to the right of the widget’s child in RTL contexts.- child_
insert PInsertnodein theplacementrelative to the widget’s child.- child_
left PInsertnodeto the left of the widget’s child.- child_
out_ bottom PInsertnodebelow the widget’s child, outside of the child layout.- child_
out_ end PInsertnodeto the right of the widget’s child in LTR contexts or to the right of the widget’s child in RTL contexts, outside of the child layout.- child_
out_ insert PInsertnodein theplacementrelative to the widget’s child, outside of theCHILD_LAYOUTscope, meaning outsidepadding, but still inside the widget.- child_
out_ left PInsertnodeto the left of the widget’s child, outside of the child layout.- child_
out_ over PInsertnodeover the widget’s child, not affected by child layout.- child_
out_ right PInsertnodeto the right of the widget’s child, outside of the child layout.- child_
out_ spacing PSpacing between child and child layout nodes and one of thechild_out_insertproperties.- child_
out_ start PInsertnodeto the left of the widget’s child in LTR contexts or to the right in RTL contexts, outside of the child layout.- child_
out_ top PInsertnodeabove the widget’s child, outside of the child layout.- child_
out_ under PInsertnodeunder the widget’s child, not affected by child layout.- child_
over PInsertnodeover the widget’s child.- child_
right PInsertnodeto the right of the widget’s child.- child_
spacing PSpacing betweenchildand one of thechild_insertproperties.- child_
start PInsertnodeto the left of the widget’s child in LTR contexts or to the right in RTL contexts.- child_
top PInsertnodeabove the widget’s child.- child_
under PInsertnodeunder the widget’s child.