Documentation / Reference

z_stack

Layer children in shared bounds.

Construction

Use z_stack() -> Overlay. Import constructors and common modifiers from refract::prelude::*.

z-stack.rs
use refract::prelude::*;

let card = z_stack()
    .alignment(Alignment::End, Alignment::Start)
    .child(view().width(240.0).height(160.0).background(Color::BLUE))
    .child(text("New").padding(8.0).background(Color::WHITE));

Layering and bounds

Children share the overlay's bounds instead of advancing along a row or column. By default, later children are painted above earlier children. Use z_index(i32) to change sibling stacking order. Give the overlay explicit dimensions when it should occupy a fixed area.

Use alignment(horizontal, vertical) to position each child within the shared grid cell on both web and native. End, Start places smaller children at the top right, as in the badge example above. Both axes default to Stretch; explicit child sizes are preserved.

Alignment changes placement without changing child identity, declaration order, paint order, or keyboard focus order. Configure alignment before wrapper modifiers such as padding or frame.

View-specific reference

z_stack returns Overlay, with child composition, two-axis alignment, and shared element modifiers. Dimensions and paint preserve Overlay, so they can be interleaved with child and alignment methods. It has no row/column direction, gap, or justification methods.

MethodPurpose
childAppends one child. Successive calls can accept different concrete view types; declaration order determines child order.
childrenAppends an iterator in iteration order. Items must share one concrete view type. All children are constructed eagerly.
maybe_childAppends the supplied view for Some. None inserts an Empty description to preserve the position of later unkeyed siblings; it does not create a host element.
alignmentAligns each child horizontally and vertically within the shared cell. Each axis accepts Start, Center, End, or Stretch and defaults to Stretch. Explicit child sizes are preserved. SpaceBetween behaves like Start because children overlap rather than being distributed. Preserves Overlay and does not change paint or keyboard focus order.

child

Appends one child. Successive calls can accept different concrete view types; declaration order determines child order.

Signature
fn child(self, child: impl View) -> Self

children

Appends an iterator in iteration order. Items must share one concrete view type. All children are constructed eagerly.

Signature
fn children<V: View>(self, children: impl IntoIterator<Item = V>) -> Self

maybe_child

Appends the supplied view for Some. None inserts an Empty description to preserve the position of later unkeyed siblings; it does not create a host element.

Signature
fn maybe_child<V: View>(self, child: Option<V>) -> Self

alignment

Aligns each child horizontally and vertically within the shared cell. Each axis accepts Start, Center, End, or Stretch and defaults to Stretch. Explicit child sizes are preserved. SpaceBetween behaves like Start because children overlap rather than being distributed. Preserves Overlay and does not change paint or keyboard focus order.

Signature
fn alignment(self, horizontal: Alignment, vertical: Alignment) -> Self

Common view modifiers

Dimensions, paint, labels, and disabled state preserve each concrete builder type, so their builder methods can be interleaved. padding and frame return wrappers; configure the inner element before adding those. ViewExt supplies the shared API for composed views.

See View Modifiers for shared methods and modifier ordering. Focus bindings and callbacks preserve concrete builders; see focus modifiers and Input & Focus for requests, observation, and indicators.

Source reference

The implementation is in crates/core/src/view/primitives.rs. Primitive and layout builders are in crates/core/src/view/primitives.rs. Shared modifiers are in crates/core/src/view/modifiers.rs. Style values and validation are in crates/core/src/style.rs.