Skip to main content

Column & Row

Flex containers that arrange children along a single axis. Column lays out children vertically, Row lays out children horizontally.

Basic Usage

// Vertical layout
widgets.Column{
MainAxisAlignment: widgets.MainAxisAlignmentStart,
CrossAxisAlignment: widgets.CrossAxisAlignmentStretch,
MainAxisSize: widgets.MainAxisSizeMin,
Children: []core.Widget{
header,
content,
footer,
},
}

// Horizontal layout
widgets.Row{
MainAxisAlignment: widgets.MainAxisAlignmentSpaceBetween,
CrossAxisAlignment: widgets.CrossAxisAlignmentCenter,
Children: []core.Widget{
avatar,
widgets.Expanded{Child: title},
menuButton,
},
}

Properties

PropertyTypeDescription
MainAxisAlignmentMainAxisAlignmentHow children are positioned along the main axis
CrossAxisAlignmentCrossAxisAlignmentHow children are positioned along the cross axis
MainAxisSizeMainAxisSizeHow much space the container takes along the main axis
Children[]core.WidgetChild widgets

Main Axis Alignment

Controls how children are positioned along the main axis:

AlignmentEffect
MainAxisAlignmentStartPack at start
MainAxisAlignmentEndPack at end
MainAxisAlignmentCenterCenter children
MainAxisAlignmentSpaceBetweenEqual space between, none at edges
MainAxisAlignmentSpaceAroundEqual space around each child
MainAxisAlignmentSpaceEvenlyEqual space everywhere
widgets.Row{
MainAxisAlignment: widgets.MainAxisAlignmentSpaceEvenly,
CrossAxisAlignment: widgets.CrossAxisAlignmentCenter,
Children: []core.Widget{cancelButton, saveButton},
}

Cross Axis Alignment

Controls how children are positioned along the cross axis:

AlignmentEffect
CrossAxisAlignmentStartAlign to start edge
CrossAxisAlignmentEndAlign to end edge
CrossAxisAlignmentCenterCenter children
CrossAxisAlignmentStretchStretch to fill cross axis
widgets.Column{
CrossAxisAlignment: widgets.CrossAxisAlignmentStretch,
Children: []core.Widget{cardOne, cardTwo},
}

Main Axis Size

Controls how much space the flex container takes:

SizeEffect
MainAxisSizeMax (default)Take all available space
MainAxisSizeMinTake minimum needed space

MainAxisSizeMax is the zero value, so Row{} and Column{} expand to fill their parent by default. Set MainAxisSizeMin explicitly when you want shrink-wrap behavior.

widgets.Column{
MainAxisSize: widgets.MainAxisSizeMin, // Only as tall as content
Children: items,
}

Spacing

Use VSpace and HSpace for consistent gaps:

widgets.Column{
MainAxisSize: widgets.MainAxisSizeMin,
Children: []core.Widget{
header,
widgets.VSpace(16), // 16px vertical gap
body,
widgets.VSpace(24),
footer,
},
}

widgets.Row{
CrossAxisAlignment: widgets.CrossAxisAlignmentCenter,
MainAxisSize: widgets.MainAxisSizeMin,
Children: []core.Widget{
icon,
widgets.HSpace(8), // 8px horizontal gap
label,
},
}