Documentation / Reference

v_stack

Arrange children vertically with spacing and alignment.

Construction

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

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

let content = v_stack()
    .alignment(Alignment::Start)
    .gap(12.0)
    .child(text("Library"))
    .child(text("Saved items"))
    .padding(16.0);

Layout and available space

stack() defaults to Direction::Vertical. Use .direction(Direction::Horizontal) to arrange a row, or change direction from state while keeping the same Stack type. h_stack() and v_stack() are shorthand constructors; both also support .direction(...).

By default, children follow declaration order along the vertical axis. The stack starts with zero gap and Stretch cross-axis alignment. Set alignment explicitly when children should keep their natural cross-axis size.

justify distributes space along the current stack direction. Extra space requires a bounded size from the parent or a size modifier. A direct spacer child can consume remaining space.

Use stable keys for reorderable children. Child composition is eager; a long list does not become virtualized by placing it in a stack.

View-specific reference

stack, h_stack, and v_stack return Stack. Dimensions and paint preserve Stack, so they can be interleaved with child, direction, gap, alignment, and 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.
directionChooses Horizontal or Vertical without replacing the stack or its children. stack() defaults to vertical; h_stack() starts horizontal and v_stack() starts vertical. Gap, alignment, and justification apply to the current direction.
gapSets the distance between adjacent children in logical pixels. The default is zero. Values must be finite and nonnegative; use padding for space around the container.
alignmentSets alignment perpendicular to the current direction (horizontal for a vertical stack, vertical for a horizontal stack). Use Start, Center, End, or Stretch. The stack constructor defaults to Stretch.
justifySets placement along the current direction. The default is Start. SpaceBetween distributes available space between children; Center and End move the sequence within its bounds.

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

direction

Chooses Horizontal or Vertical without replacing the stack or its children. stack() defaults to vertical; h_stack() starts horizontal and v_stack() starts vertical. Gap, alignment, and justification apply to the current direction.

Signature
fn direction(self, direction: Direction) -> Self

gap

Sets the distance between adjacent children in logical pixels. The default is zero. Values must be finite and nonnegative; use padding for space around the container.

Signature
fn gap(self, gap: f32) -> Self

alignment

Sets alignment perpendicular to the current direction (horizontal for a vertical stack, vertical for a horizontal stack). Use Start, Center, End, or Stretch. The stack constructor defaults to Stretch.

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

justify

Sets placement along the current direction. The default is Start. SpaceBetween distributes available space between children; Center and End move the sequence within its bounds.

Signature
fn justify(self, align: 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.