In the previous KitLab articles, we explored drawing, controls, and handling input.
But real applications also need responsive, flexible user interfaces.
Hardcoding rectangles is not sustainable.
Haiku provides layout builders to declare UI structure in a clean, concise way.
The modern BLayoutBuilder class lets you nest vertical, horizontal, and grid layouts without the boilerplate.
We’ll build a simple form with:
A label at the top.
A grid of fields (name + email).
A horizontal row of OK/Cancel buttons.
Padding and glue for spacing.
BLayoutBuilder::Group<>(this, B_VERTICAL, B_USE_DEFAULT_SPACING)
Declares the window’s root layout: a vertical stack with 10px spacing (ie B_USE_DEFAULT_SPACING).
.AddGrid(10, 10)
Starts a grid with 10px spacing in rows/columns. Perfect for aligning labels and text fields.
.AddGroup(B_HORIZONTAL, 10)
Declares a horizontal group, used here for the OK/Cancel button row.
.AddGlue()
Flexible space that expands and pushes items apart.
.SetInsets(5, 5, 5, 5)
Adds padding around the window edges.
Please note it's better to use constants for the spacing and insets from InterfaceDefs.h for the BLayoutBuilder.
For instance, use B_USE_DEFAULT_SPACING instead of the hardcoded value of 10 pixels.
Here’s a simplified view of the layout hierarchy:
Then launch the application:
As you can see the initial form is as below:

Now, resize the window:

Automatic Resizing
One of the biggest advantages of using BLayoutBuilder is that resizing works nicely.
In our example, notice how the text fields expand when you resize the window, while the buttons remain neatly aligned at the bottom.
You don’t need to write any extra code — this behavior comes for free from Haiku’s layout system.
Really great:)
Clean code: LayoutBuilder reduces boilerplate.
Responsive UIs: resizing just works.
Consistency: your apps feel native on Haiku.
In the next KitLab entries, we’ll cover:
Stay tuned :)