spacer
Distribute unused space along the main axis of a horizontal or vertical stack.
A stack often needs a gap that grows with the available room, such as the space separating a toolbar title from its status. Add spacer() -> Spacer as a direct child to give that gap a share of the stack's unused main-axis space. The spacer participates in layout without painting visible content.
Flexible Space Allocation
use hera_kit::{ViewExt, h_stack, spacer, text};
let toolbar = h_stack()
.spacing(8.0)
.child(text("Files"))
.child(spacer())
.child(text("Connected"))
.frame(480.0, 44.0);The frame in this example offers the row 480 logical pixels of width. After accounting for the two labels and the gaps between children, the stack assigns the remaining width to the spacer. If several direct spacer children were present, they would share that nonnegative remainder equally.
Available Extent
The stack's orientation determines which dimension a spacer consumes: width in a row and height in a column. A finite parent offer normally provides that available extent. An unbounded proposal does not cause a spacer to expand indefinitely.
If fixed content already consumes the available space, the allocated remainder is zero. A spacer does not compress oversized siblings or introduce layout priorities.
Spacers, Spacing, and Padding
Use a spacer when the separation should vary with unused room. For a constant gap between adjacent children, configure the stack's spacing; for room around a view, use padding. These tools affect different parts of the layout, so choosing one according to the intended relationship makes the result easier to predict.
The stack recognizes spacers from the layout kind of each direct child. A frame or padding wrapper becomes the direct layout node when placed around a spacer, so the wrapped result should not be assumed to receive the same flexible allocation.
Fixed Gaps
For a constant visual separation, prefer the container's .spacing or a deliberate frame rather than relying on whatever space happens to remain. Flexible allocation is most useful when a toolbar or column has a known offered extent.
See h_stack, v_stack, and layout.
Component-Specific Reference
fn spacer() -> SpacerThe spacer has no component-specific configuration methods or constructor arguments. Its behavior comes from being a direct child of a horizontal or vertical stack. Use the parent’s spacing for constant gaps and a finite parent proposal for flexible allocation. Common modifiers are available through ViewExt, but a frame or padding wrapper changes the direct layout node that the stack sees.
See View Modifiers for the complete common modifier reference.
Source Reference
The following files in the Hera checkout define the behavior described on this page.
crates/kit/src/view/primitives.rscrates/kit/src/layout/mod.rs