Layout
The layout system splits rectangular areas according to constraints.
Functions
VSplit
go
func VSplit(area Rect, constraints ...Constraint) []RectSplits vertically (top to bottom). Returns one Rect per constraint.
HSplit
go
func HSplit(area Rect, constraints ...Constraint) []RectSplits horizontally (left to right). Returns one Rect per constraint.
Layout
go
func Layout(area Rect, dir Direction, constraints []Constraint) []RectGeneral-purpose split with explicit direction (Horizontal or Vertical).
Constraints
| Constructor | Description |
|---|---|
Fixed(n) | Exactly n cells |
Flex(weight) | Proportional share of remaining space |
Percent(p) | Percentage of total space |
Min(n) | At least n cells |
Max(n) | At most n cells |
Resolution Order
FixedandPercentare allocated firstMaxis allocated up to its limitMinis allocated at its minimum- Remaining space is distributed to
Flexitems by weight - Any rounding remainder goes to the last
Flexitem Minconstraints are satisfied by taking fromFlexitems if needed
Examples
go
// Header, content, footer
rows := tui.VSplit(area, tui.Fixed(3), tui.Flex(1), tui.Fixed(1))
// 30% sidebar, flexible main
cols := tui.HSplit(area, tui.Percent(30), tui.Flex(1))
// Three equal columns
cols := tui.HSplit(area, tui.Flex(1), tui.Flex(1), tui.Flex(1))
// 2:1 ratio
cols := tui.HSplit(area, tui.Flex(2), tui.Flex(1))