Core concepts#
slikui is a retained-mode widget tree driven by a three-call frame loop. You build the tree once, keep it alive, and each frame the context routes input, relayouts, animates, and paints. There is no immediate-mode API, no per-frame widget construction, and no cached styled state to invalidate.
The frame loop#
Every application drives a slikui::Context with the same three calls:
ctx.handle(event); // 1. input - hit-test, focus, popups
ctx.tick({now, dt}); // 2. layout - attach -> measure -> arrange -> animation
ctx.render(); // 3. paint - DrawList -> your sink

The Python App shell wraps Target + Sink +
Context (plus font loading) and returns the framebuffer as a zero-copy
numpy array from render().
What each stage does#
1. Input (handle). Backend/window layers translate native events into
one slikui::Event vocabulary (see Input & events).
Context::handle hit-tests the deepest visible widget under the pointer, then
dispatches the event up the parent chain until some widget consumes it.
Key and text events go to the focused widget. Clicking outside a popup
dismisses it - popups are destroyed at the end of handle, never during
dispatch.
2. Tick (tick(Time{now, dt})). First attach_tree hands every widget a
Context* (fonts, theme) on first sight. Then the root is measured and
arranged top-down: every widget implements
Size measure(const Constraints&); // intrinsic size under bounds
void arrange(const Rect& abs); // assign own absolute frame + children
Frames are absolute framebuffer coordinates, which makes hit-testing,
painting and clipping trivial. Finally each widget's tick(Time) runs -
hover/press transitions and the Anim tween helper advance here.
3. Paint (render). paint_tree walks the tree; widgets append commands
to a flat DrawList through PaintEnv (draw list + theme + font). Containers
may provide clip_rect() to clip their subtree; hit-testing honors the same
clip, so content clipped out of view can't be clicked. The finished list goes to the
render sink; popups paint after the root, then toasts, then
dialogs on top.
Layout in one paragraph#
Flexbox-flavoured: Column/Row stack children along their main axis with a
gap and padding; cross-axis alignment is Stretch/Start/Center.
Children whose expands_main() is true (e.g. Spacer) split leftover
main-axis space. Layout is recomputed from scratch every tick, so window
resizes reflow automatically - see Layout and the full
architecture notes.
Ownership and lifetime#
- The tree is
std::unique_ptr-owned:ctx.set_root<T>(...)andwidget.add<T>(...)construct and own. You keep references, not owners. - Callbacks (
on_click,on_change, ...) capture app state by reference/pointer - keep captures valid for the tree's lifetime, or remove the widget first. widget.remove(child)/clear_children()destroy a subtree - immediately between frames, or at the end of the runninghandle()/tick()when called from a handler, so a widget may remove itself in its own callback.- Popup widgets are owned by the context until the end of the event that closes them. Menus are the exception: they are borrowed popups you build once and open many times.
- In Python the bindings are non-owning wrappers over the C++ tree;
App.close()(also run bywith App(...)) destroys the tree and releases the Python callbacks it holds. A widget you pass topush_popup,open_context_menuoropen_dialogis kept alive by the context while it is open, so a temporary is fine. AMenugiven toset_context_menuis not: keep that Python object alive yourself, typically as an attribute of the widget it belongs to.
Threading#
Single-threaded. One Context per thread; never touch a context from another
thread. Drive everything from the main thread (or the thread that owns the
window).
In Python, Context.tick, render and handle (and the App methods that
call them) release the GIL while the C++ work runs. Other Python threads,
such as an audio callback or a worker, keep running during a frame. Your
paint / on_event overrides, callbacks and a Python RenderSink still run
with the GIL, on the UI thread.
That also means the GIL no longer stops another thread from changing the
widget tree mid-frame, so the single-thread rule matters more. A worker
thread must not touch widgets. Send its results to the UI thread (a
queue.Queue you drain each frame, say) and update widgets there.
Where to go next#
- Getting started - C++ or Python for a runnable first window.
- Layout for the container set.
- Input & events for the event vocabulary, focus and shortcuts.
- Render backends to run on GL, raw pixels, or your own API.