Skip to main content

Spacers

oat-latte has two families of spacers:

TypeBehaviourUse when
VFill / HFillFlex spacer — claims remaining space via flex distributionYou want to push content to one side, or fill variable gaps
VGap / HGapFixed spacer — always claims exactly n cellsYou need a guaranteed fixed gap between two widgets

VFill and HFill

VFill is a flex spacer for VBox; HFill is a flex spacer for HBox. When added with AddChild, a VFill / HFill auto-promotes itself to a flex slot with weight 1 — it is shorthand for AddFlexChild(layout.NewVFill(), 1).

// Push content to either end of an HBox.
row := layout.NewHBox()
row.AddChild(leftLabel)
row.AddChild(layout.NewHFill()) // fills the gap between labels
row.AddChild(rightLabel)

// Fill remaining vertical space in a VBox.
vbox := layout.NewVBox()
vbox.AddChild(topContent)
vbox.AddChild(layout.NewVFill()) // absorbs all remaining rows
vbox.AddChild(bottomContent)

WithMaxSize — capped flex spacer

WithMaxSize(n) caps the spacer's growth at n cells. The spacer still participates in flex distribution but yields any allocation beyond n.

// Gap up to 2 columns — shrinks if the container is tight.
row.AddChild(layout.NewHFill().WithMaxSize(2))

Use WithMaxSize when you want a gap that can gracefully shrink (e.g. inside a resizable dialog). For a gap that must always be a fixed size, use HGap / VGap instead.

VGap and HGap

VGap(n) is a fixed-height inert spacer for use in VBox. HGap(n) is a fixed-width inert spacer for use in HBox. They do not participate in flex distribution — Measure returns a fixed Size and Render is a no-op.

// Exactly 1 row of vertical space between two sections.
vbox := layout.NewVBox(
widget.NewText("Section A"),
layout.NewVGap(1),
widget.NewText("Section B"),
)

// Exactly 2 columns between two buttons.
btnRow := layout.NewHBox()
btnRow.AddChild(layout.NewHFill()) // flex push to the right
btnRow.AddChild(cancelBtn)
btnRow.AddChild(layout.NewHGap(2)) // fixed 2-column gap
btnRow.AddChild(okBtn)
TypeConstructorAxisMeasure result
VGaplayout.NewVGap(n int) *VGapVertical (VBox)Size{Width: 0, Height: n}
HGaplayout.NewHGap(n int) *HGapHorizontal (HBox)Size{Width: n, Height: 0}

n < 0 is clamped to 0. Render is a no-op — both types are pure spacers with no visual output.

VFill/HFill vs VGap/HGap — which to use

ScenarioUse
Push buttons to the right edge of an HBoxHFill
Fixed 2-column gap between two buttonsHGap(2)
Fill all remaining rows in a VBoxVFill
Fixed 1-row gap between two sectionsVGap(1)
Gap that should shrink in a tight dialogHFill.WithMaxSize(2) or VFill.WithMaxSize(1)