Skip to content

Stack

TStack is the type behind VStack, HStack and the responsive Stack. Stack lays out its children vertically on small windows and horizontally from the medium size class on (768dp and wider). Use it for toolbars or groups of cards that should wrap into a column on phones.

Window 1200dp wideWindow 400dp wide
Stack, horizontalStack, vertical
return Stack(
	Text("One").BackgroundColor("#C9E7F8").Padding(Padding{}.All(L16)),
	Text("Two").BackgroundColor("#FDE2C4").Padding(Padding{}.All(L16)),
	Text("Three").BackgroundColor("#D8F0D2").Padding(Padding{}.All(L16)),
).Gap(L8).
	BackgroundColor(ColorCardBody).
	Padding(Padding{}.All(L16)).
	Border(Border{}.Radius(L16))

A stack clips its children. If a child has a shadow, add padding to the stack or call NoClip(true).

Constructors

ConstructorDescription
Stack(children ...core.View) TStackResponsive stack which decides between a vertical and a horizontal layout by the window size class.
VStack(children ...core.View) TStackLays out the children in a column, see VStack.
HStack(children ...core.View) TStackLays out the children in a row, see HStack.

Nil children are skipped, so you can pass the result of If directly.

Methods

MethodDescription
AccessibilityLabel(label string) DecoredViewSets the label used by screen readers for accessibility.
Action(f func()) TStackSets the callback function to be invoked when the stack is clicked or tapped.
Alignment(alignment Alignment) TStackSets how the children are aligned within the stack.
Animation(animation Animation) TStackSets an animation of the stack.
Append(children ...core.View) TStackAdds more children to the stack.
Background(bg Background) TStackSets a background of gradients and images.
BackgroundColor(color Color) TStackSets the background color of the stack.
Border(border Border) DecoredViewSets the border of the stack.
Enabled(enabled bool) TStackHas only an effect if StylePreset is applied, otherwise it is ignored.
FocusedBackgroundColor(backgroundColor Color) TStackSets the background color of the stack when it is focused (e.g., via keyboard navigation).
FocusedBorder(border Border) TStackSets the border styling when the stack is focused.
FocusedOutline(outline Outline) TStackSets the outline styling when the stack is focused.
Font(font Font) TStackSets the font style applied to text content inside the stack.
Frame(frame Frame) DecoredViewSets the frame of the stack.
FullWidth() TStackSets the width of the stack to the full available width.
Gap(gap Length) TStackSets the space between the children.
HRef(url core.URI) TStackSets the URL that the stack navigates to when clicked if no action is specified.
HoveredBackgroundColor(backgroundColor Color) TStackSets the background color of the stack when the user hovers over it.
HoveredBorder(border Border) TStackSets the border styling when the stack is hovered.
HoveredOutline(outline Outline) TStackSets the outline styling when the stack is hovered.
HtmlTag(tag string) TStackDefines the html tag that the stack should be rendered as.
ID(id string) TStackAssigns a unique identifier to the stack, useful for testing or referencing.
Key(name, id string) TStackIdentifies the action across renders by what it acts on, e.g. (“remove”, rowID).
Layout(layout StackLayout) TStackSets the orientation: StackLayoutAuto, StackLayoutVertical or StackLayoutHorizontal; use Wrap for wrapping rows.
NoClip(b bool) TStackDisables clipping of the children if set to true.
Opacity(opacity float64) TStackSets the visibility of this component in the range [0..1], including all children.
Outline(outline Outline) TStackSets the default outline styling for the stack.
Padding(padding Padding) DecoredViewSets the inner spacing around the children.
Position(position Position) TStackSets the position of the stack within its parent layout.
PressedBackgroundColor(backgroundColor Color) TStackSets the background color of the stack when it is pressed or clicked.
PressedBorder(border Border) TStackSets the border styling when the stack is pressed or clicked.
PressedOutline(outline Outline) TStackSets the outline styling when the stack is pressed or clicked.
Responsive(fn func(wnd core.Window, stack TStack) TStack) TStackRegisters a function which adapts the stack to the window right before rendering.
StylePreset(preset StylePreset) TStackApplies a predefined style preset to the stack, controlling its appearance.
Target(target string) TStackSets the name of the browsing context, like _self, _blank, _parent, _top.
TextColor(textColor Color) TStackSets the color of text content inside the stack.
Transformation(transformation Transformation) TStackApplies a transformation like rotation or scaling.
Visible(visible bool) DecoredViewControls the visibility of the stack; setting false hides it.
With(fn func(stack TStack) TStack) TStackApplies a transformation function to the stack itself and returns the result.
WithFrame(fn func(Frame) Frame) DecoredViewApplies a transformation function to the stack’s frame and returns the updated component.
WithPadding(padding Padding) TStackLike Padding, but returns TStack so that you can continue the chain.
Wrap(wrap bool) TStackWraps the children into multiple rows if a horizontal stack has a limited width.

Related