Expand description
ZStack — a layout container that layers children on top of each other.
The container sizes itself to the maximum width and maximum height across
all children, measured at an unspecified proposal so background rects do not
inflate the size. Height additionally takes a width-bounded query when the
parent bound the width, so a wrapping child reports the height it will really
occupy rather than a single line; see layout_response for why that query is
width-only. Each child is then offered the full container bounds and
positioned according to the container-level Alignment (default: CENTER);
individual children can override alignment via WidgetTree::set_alignment.
The primary use-cases are layered UIs — a background RectWidget beneath
a TextWidget, a floating badge over a button icon — and card-like
compositions where a paint layer and a content layer share the same bounds.
Children that expand to fill their proposal (e.g. RectWidget) fill the
full ZStack area; children with fixed intrinsic sizes are positioned by
alignment.
Propagates shrink weight and minimum size when any child opts in, so
wrapping a shrinkable single-line label in a ZStack stays shrinkable.
let _card = ZStack::new()
.child(RectWidget::new().background(SurfaceRole::Raised))
.child(TextWidget::new(lit!("Hello")));Structs§
- ZStack
- A layout container that stacks children on top of each other.
Size = max of children sizes. Children are positioned according to
the container’s
Alignment(default: center), with per-child overrides.