HStack

HStack — a horizontal layout container that distributes children left-to-right.
Public functions
HStack
| Returns | Function |
|---|---|
| Constructors | |
Self | new() |
| Builder methods | |
Self | spacing(spacing: impl Into<Prop<f32>>) |
Self | alignment(alignment: VAlignment) |
Self | child(widget: impl teksilo_core::IntoTeksiChild) |
Self | children(iter: impl IntoIterator<Item = impl teksilo_core::IntoTeksiChild>) |
Self | child_opt(widget: Option<impl teksilo_core::IntoTeksiChild>) |
Detailed description
Children are given their intrinsic width and the stack's cross-axis height.
Positive slack (leftover space) is distributed among children that carry a
non-zero flex weight (e.g. Spacer, Expand); negative slack (over-constraint)
is absorbed by children with a non-zero shrink weight (e.g. a single-line
TextWidget). Vertical alignment defaults to VAlignment::Center and can be
overridden per-container or per-child.
For a vertical counterpart see VStack.
#![allow(unused)] fn main() { use teksilo_widgets::primitives::{HStack, TextWidget, Spacer}; use teksilo_i18n::lit; let _row = HStack::new() .spacing(8.0) .child(TextWidget::new(lit!("Label"))) .child(Spacer::new()) .child(TextWidget::new(lit!("Value"))); }
Density
The picture above is the widget at TargetDensity::Compact, the mouse-and-keyboard ladder. Below is the same subject on the same canvas with only the ladder changed, so what moves is the density and nothing else — where the subject no longer fits, that is what the denser targets cost it at that size. See docs/density-and-targets.md.
Touch

API reference
📖 Full rustdoc API for this module
pub struct HStack
Import: use teksilo::widgets::HStack;
Horizontal layout container that distributes children left-to-right.
Cross-axis (vertical) alignment defaults to VAlignment::Center and may be
overridden globally via alignment or per-child via
WidgetTree::set_alignment.
#![allow(unused)] fn main() { pub struct HStack { /* fields */ } }
Methods
pub fn new() -> Self
Create an empty HStack with no spacing and VAlignment::Center.
pub fn spacing(mut self, spacing: impl Into<Prop<f32>>) -> Self (default: 0.0)
Set inter-child spacing. Accepts a static f32 or a reactive
Signal<f32> — use a signal derived from
ctx.theme_signal() to track theme-driven spacing changes.
pub fn alignment(mut self, alignment: VAlignment) -> Self (default: VAlignment::Center)
Set the vertical alignment for children that are shorter than the stack's height.
pub fn child(mut self, widget: impl teksilo_core::IntoTeksiChild) -> Self
Add an inline child widget (deferred insertion).
pub fn children( mut self, iter: impl IntoIterator<Item = impl teksilo_core::IntoTeksiChild>, ) -> Self
Add multiple inline children from an iterator.
pub fn child_opt(mut self, widget: Option<impl teksilo_core::IntoTeksiChild>) -> Self
Conditionally add a child. No-op if None.