-
Notifications
You must be signed in to change notification settings - Fork 4
Layout System
There is no grid system, no absolute positioning to learn, and no separate Row or Column components.
Everything is built with a single Box component and a handful of layout properties.
Once you understand these properties, you can build almost any interface:
- Forms
- Dashboards
- Sidebars
- Headers
- Toolbars
- Dialogs
- Settings screens
Every layout starts the same way.
retui.Box(
retui.Props{},
retui.NewStyle(),
// children...
)A Box always has three parts:
- Props – controls the layout.
- Style – controls the appearance.
- Children – the content inside the box.
┌────────────────────────────┐
│ Props │
├────────────────────────────┤
│ Style │
├────────────────────────────┤
│ Children │
└────────────────────────────┘
If you don't specify a width or height, the box automatically sizes itself to fit its content.
Direction controls how children are arranged.
There are only two options.
Children are placed side by side.
retui.Box(
retui.Props{
Direction: retui.Row,
Gap: 2,
},
retui.NewStyle(),
retui.Text("Left", retui.NewStyle()),
retui.Text("Right", retui.NewStyle()),
)Result
Left Right
Typical uses:
- Toolbars
- Navigation bars
- Form rows
- Header layouts
Children are stacked vertically.
retui.Box(
retui.Props{
Direction: retui.Column,
},
retui.NewStyle(),
retui.Text("One", retui.NewStyle()),
retui.Text("Two", retui.NewStyle()),
retui.Text("Three", retui.NewStyle()),
)Result
One
Two
Three
Typical uses:
- Forms
- Menus
- Sidebars
- Dashboards
Boxes can contain other boxes.
Example:
┌──────────────────────────────┐
│ Header │
├──────────────────────────────┤
│ Sidebar │ Main Content │
│ │ │
│ │ │
├──────────────────────────────┤
│ Footer │
└──────────────────────────────┘
This layout is simply:
Column
├── Header
├── Row
│ ├── Sidebar
│ └── Content
└── Footer
Large applications are built by nesting small layouts together.
RetUI supports three sizing modes.
A fixed size never changes.
Width: retui.Fixed(30)Perfect for:
- Sidebars
- Labels
- Navigation menus
A grow size expands to fill the remaining space.
Width: retui.Grow(1)Example
+---------+------------------------+
| Sidebar | Main Content |
+---------+------------------------+
The sidebar keeps its width.
The content fills everything else.
Multiple growing boxes share space according to their weight.
Width: retui.Grow(1)
Width: retui.Grow(2)Result
+---------+-------------------------+
| 1/3 | 2/3 |
+---------+-------------------------+
The second box receives twice as much space.
A fit size uses only the space required by its content.
Width: retui.Fit()This is also the default.
Gap adds space between children.
Gap: 3Result
A B C
Gap never adds space around the outside of the box.
It only separates its children.
Padding adds space inside the box.
Padding: [4]int{1,2,1,2}Order:
Top
Right
Bottom
Left
Example
Without padding
+------------+
|Hello World |
+------------+
With padding
+--------------+
| |
| Hello World |
| |
+--------------+
Padding makes components easier to read.
Margin adds space outside the box.
Unlike padding, margin separates one box from another.
Without margin
+-----++-----+
| One || Two |
+-----++-----+
With margin
+-----+ +-----+
| One | | Two |
+-----+ +-----+
Use margin to separate panels, cards and sections.
Margin
┌──────────────────────────┐
│ Border │
│ ┌──────────────────────┐ │
│ │ Padding │ │
│ │ ┌──────────────────┐ │ │
│ │ │ Content │ │ │
│ │ └──────────────────┘ │ │
│ └──────────────────────┘ │
└──────────────────────────┘
Padding adds space inside the border.
Margin adds space outside the border.
Align controls how children are positioned across the cross axis.
| Value | Description |
|---|---|
AlignStart |
Beginning |
AlignCenter |
Center |
AlignEnd |
End |
AlignStretch |
Fill available space |
Example
Align: retui.AlignCenterJustify controls how children are distributed along the main axis.
| Value | Description |
|---|---|
JustifyStart |
Pack at the beginning |
JustifyCenter |
Center together |
JustifyEnd |
Pack at the end |
JustifySpaceBetween |
Equal space between children |
JustifySpaceAround |
Equal space around children |
Example
MyApp v1.0.0
This layout uses
Justify: retui.JustifySpaceBetweenA complete application is simply many boxes combined together.
App
│
├── Header
├── Body
│ ├── Sidebar
│ └── Content
└── Footer
Every part of the screen is just another Box.
✅ Build layouts by nesting boxes.
✅ Prefer Grow() instead of fixed widths whenever possible.
✅ Use Fixed() only when a component should never resize.
✅ Add padding to improve readability.
✅ Use gap to separate related items.
✅ Use margin to separate sections.
✅ Keep layouts simple.
| Property | Purpose |
|---|---|
Direction |
Row or Column |
Width |
Fixed, Grow or Fit |
Height |
Fixed, Grow or Fit |
Gap |
Space between children |
Padding |
Space inside the box |
Margin |
Space outside the box |
Align |
Cross-axis alignment |
Justify |
Main-axis distribution |
Every layout in RetUI is built with a single component: Box.
By combining a few simple properties—
- Direction
- Width
- Height
- Gap
- Padding
- Margin
- Align
- Justify
—you can build everything from a simple form to a full-screen dashboard without manually calculating positions.