Documentation / Reference
v_stack
Arrange children vertically with spacing and alignment.
Construction
Use v_stack() -> Stack. Import constructors and common modifiers from refract::prelude::*.
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.
| Method | Purpose |
|---|---|
child | Appends one child. Successive calls can accept different concrete view types; declaration order determines child order. |
children | Appends an iterator in iteration order. Items must share one concrete view type. All children are constructed eagerly. |
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. |
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. |
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. |
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. |
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. |
child
Appends one child. Successive calls can accept different concrete view types; declaration order determines child order.
fn child(self, child: impl View) -> Selfchildren
Appends an iterator in iteration order. Items must share one concrete view type. All children are constructed eagerly.
fn children<V: View>(self, children: impl IntoIterator<Item = V>) -> Selfmaybe_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.
fn maybe_child<V: View>(self, child: Option<V>) -> Selfdirection
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.
fn direction(self, direction: Direction) -> Selfgap
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.
fn gap(self, gap: f32) -> Selfalignment
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.
fn alignment(self, align: Alignment) -> Selfjustify
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.
fn justify(self, align: Alignment) -> SelfCommon 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.