How widgets work
Every widget call declares its own element and reads or writes plain state you already own. There is no widget object and nothing to keep in sync.
Ids and keys
Each element gets an id from its position among its siblings, and the context remembers every id across frames. That memory is how interaction reads last frame's rectangle and how scroll offsets survive. In a loop, call ui::key before each item so that rows keep their state when others are added above them. A second key before the same element mixes into the first, so widgets that key themselves by label stay distinct.
ui::next_id and ui::last_id return the id the next element will get and the id of the one just declared. ui::rect_of returns where an id landed last frame, or an empty box on its first frame. ui::frame_of counts frames from one, and ui::busy is true while something is still easing, which is what keeps an idle app awake.
The element just declared
A few calls act on whatever the previous call put into the tree, widget or plain box: interact, tooltip and ease. Call them right after ui::open, or right after the widget, before anything else is declared. canvas is different: it declares its own box from the style you pass.
#include "isolenui/ui/ui.h"
#include "isolenui/kit/kit.h"
// every element gets an id from its position among its siblings, a loop body
// keys each row so a row keeps its state when rows are added above it
static void track_list(ui::ctx* u, const char* const* titles, const bool* live,
uint32_t count)
{
ui_box(u, ui::col().gap(4.0f))
{
for (uint32_t i = 0; i < count; ++i) {
ui::key(u, titles[i]);
ui_box(u, ui::row().gap(8.0f).items(lay_align_centre))
{
ui::dot(u, live[i] ? 0xff6ec864u : 0xff555555u, live[i]);
ui::text(u, titles[i], ui::body(u));
}
}
}
}
// rect_of answers from last frame's solve, so a box can size a sibling to
// what it measured, the first frame an id exists it is empty
static void measured_header(ui::ctx* u)
{
ui::key(u, "title");
const uint64_t title_id = ui::next_id(u);
ui_box(u, ui::row()) { ui::text(u, "a title of any width", ui::head(u)); }
const lay_box r = ui::rect_of(u, title_id);
ui_box(u, ui::col().width(r.w > 0.0f ? r.w : 1.0f).height(2.0f).bg(0xffe5648au)) {}
ui::textf(u, ui::caption(u), "frame %u, %s", ui::frame_of(u),
ui::busy(u) ? "animating" : "idle");
}
// a host that drives the ui itself, what isolen_run does for you
static void host_frame(ui::ctx* u, const ui::input* in, gfx_list* out,
float w, float h, float dt, float time)
{
ui::begin(u, in, w, h, dt, time);
ui_box(u, ui::view().width(w).height(h).pad(24.0f))
{
ui::text(u, "declared, solved and painted by end", ui::body(u));
}
ui::end(u, out);
}Focus, looks and the kit
Every widget joins the tab order and takes its own keys while it has focus: arrows for a slider, enter and space for a button. A ring shows only when focus came from the keyboard. Widgets paint from the theme's looks, so hover, press, focus, checked, open and disabled all ease in from one table per role. See focus, scopes and modals and states and looks. Each widget is its own file in the component kit, so an app links only the widgets it calls.
The widget groups
Every widget





























































