Skip to Content
bloom

Alignment and spacing

Center nodes, align children across a row or column, justify leftover space along it, and put gaps between children.

Center a node

bloom.Centered(child) places a child at its natural size in the middle of its space:

bloom.Centered(bloom.Box(panel, bloom.Text("hi")))
        ┌──┐
        │hi│
        └──┘

Align children across a row or column

In a row, children stretch to the row's full height by default, and in a column, to its full width. Align changes that, for every child of the row or column:

bloom.Row(sidebar, content).Align(bloom.Start) // each child at its natural height, at the top

Or for one slot only:

bloom.Row(
	bloom.Fixed(10, tall),
	bloom.Auto(badge).Align(bloom.Center), // vertically centered next to tall
)

The values, of type bloom.Align, are bloom.Stretch (the default), bloom.Start, bloom.Center, and bloom.End. They aren't the same as the flex values that Justify takes below, though some share a name.

Justify children along a row or column

When no child grows, there may be space left over along the row or column. Justify decides where it goes, using the values from the flex package:

import "bloomfx.dev/bloom/flex"

bloom.Row(a, b).Justify(flex.SpaceBetween)
┌─┐                        ┌─┐
│a│                        │b│
└─┘                        └─┘
ValueLeftover space goes
flex.Startafter the children (the default)
flex.Centerequally before and after them
flex.Endbefore them
flex.SpaceBetweenbetween the children, none at the edges
flex.SpaceAroundaround each child, so the edges get half as much as between children
flex.SpaceEvenlyequally between children and at both edges

Put a gap between children

Gap(n) puts n cells between each pair of children:

bloom.Row(cancel, save).Gap(2)
bloom.Column(fields...).Gap(1)

A slot that can never have any cells, such as Fixed(0, ...) or one that has collapsed, doesn't get a gap, so hiding a child doesn't leave a double gap behind.

A grid or a wrap takes two values, Gap(x, y), for the space between columns and between rows.

Last updated on

On this page