On this page

Sizing and minimums

Every box has a lay_size on each axis, plus a flex grow and shrink factor. The rules follow CSS closely enough that CSS intuition carries over.

The four kinds

ConstructorKindMeaning
lay_fit()lay_kind_fitThe default. The box is as big as its content.
lay_px(v)lay_kind_pxA fixed size in logical units. width(float) is shorthand for it.
lay_grow(w)lay_kind_growA zero base that takes a weighted share of the free space.
lay_pct(f)lay_kind_pctA fraction of the parent's content box. 0.25f means a quarter.

lay_min, lay_max and lay_clamp wrap any kind with a floor and a ceiling. Every resolved extent is also held under ISOLEN_LAY_MAX_EXTENT (one million units), so one bad measure cannot push coordinates into the rasteriser.

Grow from zero, or from content

There are two ways to grow, and they match the two common CSS flex shorthands. width(lay_grow(2)) starts from zero, so boxes split the free space exactly by weight, like flex: 2 1 0. The chain call grow() only sets the flex factor and keeps the fit size as the base, like flex: 1 1 auto. Each box then starts at its content width and shares out what is left.

Flex hands out space from the unclamped base and clamps to min and max afterwards, as CSS does. A box that hits its max is frozen and its excess goes back to the others. A box that hits its min takes what it needs from the rest.

Flex sizinginteractive illustration
case
long label herewidth(lay_grow(2))0 px
shortwidth(lay_grow(1))0 px
fixedwidth(120)0 px
lay_grow starts from a zero base, so free space splits exactly by weight whatever the labels say. The row is a browser flexbox with the same rules the solver uses.

CSS-like minimum sizes

These two rules decide what happens when a column runs out of height:

  • A visible box never shrinks below its content's minimum height. A plain column holding a heading and a paragraph stays tall enough for both and pushes its parent. Squashing it would make text overlap.
  • A box that scrolls or clips only contributes its own floor to its parent's minimum. Here that means an overflow other than lay_overflow_visible, or a pinned scroll. A bare clips() keeps the visible minimum. A nested ui::view() inside a column therefore shrinks to whatever room is left and scrolls. The page does not grow. The floor is the view's own lo, so lay_min(lay_grow(1), 120) keeps it at least 120 tall.

A minimum pushes its parent only while the parent can grow. When a parent with a visible overflow is still too small, its children shrink in proportion to fit it, px sizes and minimums included. The parent bound wins. See containment.

Rows behave differently on purpose. Across the horizontal axis a box only keeps its explicit lo, so a long label can still shrink and elide rather than force the row wider than the window.

sizing.cpp
#include "isolenui/ui/ui.h"
#include "isolenui/kit/kit.h"

// every size is one of four kinds, fit is the default, px is fixed, grow
// starts from zero and takes a weighted share of what is left, and pct is a
// fraction of the parent
static void size_kinds(ui::ctx* u)
{
    ui_box(u, ui::row().gap(8.0f).height(48.0f))
    {
        ui_box(u, ui::col().width(lay_px(120.0f))) { ui::text(u, "120 px", ui::caption(u)); }
        ui_box(u, ui::col().width(lay_pct(0.25f))) { ui::text(u, "25 %", ui::caption(u)); }
        ui_box(u, ui::col().width(lay_grow(2.0f))) { ui::text(u, "grow 2", ui::caption(u)); }
        ui_box(u, ui::col().width(lay_grow(1.0f))) { ui::text(u, "grow 1", ui::caption(u)); }
        ui_box(u, ui::col()) { ui::text(u, "fit", ui::caption(u)); }
    }
}

// style::grow only sets the flex factor, so that box grows from its content
// width, while lay_grow starts from zero, the css flex 1 1 auto against 1 1 0
static void grow_from_content(ui::ctx* u)
{
    ui_box(u, ui::row().grow().gap(8.0f))
    {
        ui_box(u, ui::row().grow()) { ui::text(u, "a long label grows from here", ui::body(u)); }
        ui_box(u, ui::row().grow()) { ui::text(u, "short", ui::body(u)); }
    }
}

// min and max wrap any kind, flex hands out space from the unclamped base
// and clamps afterwards, the way css does, so a capped box gives its share
// back to the others instead of swallowing it
static void clamped_columns(ui::ctx* u)
{
    ui_box(u, ui::row().grow().gap(12.0f))
    {
        ui_box(u, ui::col().width(lay_clamp(lay_grow(1.0f), 180.0f, 280.0f)))
        {
            ui::text(u, "sidebar, 180 to 280", ui::caption(u));
        }
        ui_box(u, ui::col().width(lay_min(lay_grow(3.0f), 320.0f)))
        {
            ui::text(u, "content, at least 320", ui::body(u));
        }
        ui_box(u, ui::col().width(lay_max(lay_grow(1.0f), 200.0f)))
        {
            ui::text(u, "inspector, at most 200", ui::caption(u));
        }
    }
}

// a visible column never squashes its content, it stays as tall as its
// children need and pushes the page, a view only gives its parent its own
// floor, so the nested view below shrinks and scrolls and the page stays put
static void page_with_nested_view(ui::ctx* u, const char* const* lines,
                                  uint32_t line_count)
{
    ui_box(u, ui::col().grow().pad(16.0f).gap(12.0f))
    {
        ui::text(u, "release notes", ui::head(u));
        ui::text(u, "this heading never shrinks below its own height",
                 ui::caption(u));

        ui_box(u, ui::view().height(lay_min(lay_grow(1.0f), 120.0f)))
        {
            for (uint32_t i = 0; i < line_count; ++i) {
                ui::key(u, uint64_t(i));
                ui::text(u, lines[i], ui::body(u));
            }
        }

        ui::button(u, "done");
    }
}
A box counts as scrolling when it has children and either names an overflow other than lay_overflow_visible on that axis or pins an offset with scrolls_y. See overflow and views.

Last updated 6 October 2026