On this page

Raw layout

The solver stands on its own. lay_begin, lay_open, lay_leaf, lay_close and lay_solve build and solve a tree with no text and no paint, for code that only wants rectangles.

Building and solving

A root has no parent to size it, so give it the extent lay_begin was opened with. A leaf reports its own size through two callbacks. The width callback is called twice, once for the longest unbreakable run and once for the natural width, so a grid can fit its longest word. The height callback is called once the width is final. After lay_solve, lay_rect, lay_clip_rect and lay_hit answer immediately. lay_id tags a node with your own 64 bit id. lay_scope and lay_grid_scope are brace scoped macros, like ui_box.

Scrolling raw boxes

A raw box scrolls only when it asks to, and scrolling needs children. Name an overflow on the axis, set scroll_y to the offset you keep, and read lay_scroll_y_info after the solve to clamp it and draw the bar. scrolls_y(offset) pins an offset and clips even when no bar is up, which is how the element api's virtual list feeds its sub-row offset.

raw_lay.cpp
#include "isolenui/ui/layout2.h"

#include <stdio.h>

// the raw solver underneath ui::ctx, for code that only wants rectangles.
// lay_ctx holds 2048 nodes plus the grid pools, so it lives static
static lay_ctx g_lay;
static float g_scroll_y = 0.0f;

static float row_height(void* user, float width)
{
    (void)user;
    (void)width;
    return 28.0f;
}

static void solve_three_panes(float width, float height, float wheel_y)
{
    lay_begin(&g_lay, width, height);

    const uint32_t root =
        lay_open(&g_lay, lay_row().spacing(8.0f).width(width).height(height));
    const uint32_t left = lay_leaf(&g_lay, lay_col().width(240.0f), nullptr,
                                   nullptr, nullptr);

    // a raw box scrolls only when it asks to, overflow auto brings up a bar
    // once the rows do not fit and scroll_y is the offset it rolls by
    lay_style list = lay_col().grow().overflow(lay_overflow_visible, lay_overflow_auto);
    list.scroll_y = g_scroll_y;
    const uint32_t centre = lay_open(&g_lay, list);
    for (uint32_t i = 0; i < 200; ++i) {
        lay_leaf(&g_lay, lay_row().height(28.0f), nullptr, row_height, nullptr);
    }
    lay_close(&g_lay);

    const uint32_t right = lay_leaf(&g_lay, lay_col().width(280.0f), nullptr,
                                    nullptr, nullptr);
    lay_close(&g_lay);

    lay_solve(&g_lay);

    // the solve reports how far the list can roll, the caller owns the offset
    const lay_scroll_info info = lay_scroll_y_info(&g_lay, centre);
    if (info.active) {
        g_scroll_y += wheel_y;
        g_scroll_y = g_scroll_y < 0.0f ? 0.0f : g_scroll_y;
        g_scroll_y = g_scroll_y > info.max_offset ? info.max_offset : g_scroll_y;
    }

    const lay_box l = lay_rect(&g_lay, left);
    const lay_box c = lay_rect(&g_lay, centre);
    const lay_box r = lay_rect(&g_lay, right);
    printf("left %.0fx%.0f centre %.0fx%.0f right %.0fx%.0f\n", l.w, l.h, c.w,
           c.h, r.w, r.h);
    printf("thumb at %.0f, %.0f of %.0f px rolled\n", info.thumb.y,
           info.offset, info.max_offset);
    (void)root;
}
lay_ctx holds 2048 nodes and the grid pools, 730,016 bytes in all. Keep it static or on the heap.

Rounded clips

A node with clip or wall set cuts its children to its box. Two style fields round that cut: inset is the border width, and round the corner radius of the box. The children are cut to the padding box, the box inset by inset on every side, with corners of round less inset. A radius that leaves nothing, or zero, keeps the plain rectangle.

After the solve, lay_clip_mask(c, node) returns the lay_mask a node is cut to, next to the rectangle lay_clip_rect returns. A lay_mask is a lay_box and four radii that run top left, top right, bottom right, bottom left, and all zero radii mean none. Nested rounded clips meet as one: the boxes intersect, a corner keeps the larger radius of the clips it is a corner of, and a corner of neither goes square. No radius is larger than half the shorter side. A float skips every wall on its way up and meets only the real clips, the same rule as its rectangle.

The element api fills both fields from the paint: round from the radius and inset from the border width, or the look's border when that is wider. A box with a fill, a border or a look is already a wall, so its children are cut to its rounded padding box with nothing to set. The ui hands the mask to the draw list as a gfx_mask, and scrollbars follow it.

Reaching the solver from the element api

ui::layout_of returns the lay_ctx under a context, and ui::last_node returns the node of the element just declared. That node is only valid until ui::end, and the tree is not solved until then. To read a solved rectangle from inside a view, use ui::rect_of. It answers from last frame's solve and is empty on the first frame an id exists.

Last updated 6 October 2026