Joshua Manzer

kitui: one UI framework, five renderers, zero dependencies

The source is private. kitui is not open source and is not distributed. This post describes its design and what it does. It does not share its code.

kitui is the UI framework under spectre and the other native tools I build. It is written in C++20, draws everything itself on the GPU, and has no third-party runtime dependencies in its core. A complete tool built on it ships as a single executable of a few hundred kilobytes.

The kitui demo: sidebar navigation, group boxes, checkboxes, sliders, radio buttons, a text field, a hotkey binder, and a floating window

Why build a UI framework

Most of my tools are small utilities. Electron, a bundled browser, or a large widget toolkit would outweigh the actual program many times over, and they idle at a steady cost in memory and CPU. I wanted utilities that open instantly, look finished, and use nothing while they wait.

Existing immediate-mode libraries come close, but their rendering backends are examples to adapt rather than finished parts. Getting them right on every graphics API, with correct color and clean state handling, is where most of the work hides. kitui is designed and tested as one system instead of assembled from separate parts.

Immediate mode

kitui has no widget objects. There is nothing to create, wire up, or keep in sync. Each frame, the program calls functions in order, and each call lays out, draws, and handles input for one widget. The application’s own data is the state: a checkbox takes a reference to a bool and changes it directly, and a button returns true on the frame it was clicked.

Retained mode keeps a separate tree of widget objects in sync with your data. In kitui, UI calls read and write your data directly every frame and produce a draw list.

This is spectre’s entire download queue, a plain loop over its jobs:

if (kit::button(c, live ? "Cancel" : "Remove", c.px(56))) { /* ... */ }
c.same_line();
kit::text(c, it.title.empty() ? it.url : it.title);
if (it.st == St::Running) kit::progress(c, it.pct);

To hide a widget, you don’t call it. To switch pages, you call different code. The whole interface is ordinary control flow.

What’s included

Area Included
Widgets Buttons, checkboxes, radio buttons, sliders, dropdowns, text fields, keybind capture, progress bars, sidebar navigation, icons, images, tooltips
Containers Floating windows with drag, raise, and overlap; child panels; group boxes; scroll panels; columns
Input Full keyboard navigation with a focus ring, text selection, clipboard, word jumps, modal popups
Text Built-in fonts compiled into the binary (Latin and Cyrillic), runtime TTF loading, HiDPI scaling that follows the monitor
Rendering OpenGL 3.3, Direct3D 9, 11, and 12, and Vulkan, all drawing the same draw list
Color Correct output on standard, sRGB, and HDR targets (scRGB and HDR10)
Languages A plain C API, so it can be used from C, C#, Python, Rust, Zig, Go, Lua, or anything with a C FFI
Platforms Linux (SDL3 and OpenGL) and Windows (Win32 and Direct3D 11)

Design decisions

It sleeps. Most UI loops redraw continuously, 60 or more times a second, whether or not anything changed. kitui draws a frame only after input, an explicit redraw request, or a wake call from another thread. spectre’s download thread calls kit::wake() on each progress update, and that is the only reason it ever redraws on its own. An idle kitui app uses no measurable CPU.

Over one second, a typical loop redraws 60 times. kitui redraws only on a key press, a click, and three download progress updates, and sleeps in between.

One interface, five renderers. Every backend draws the same list of vertices and commands, so an interface looks identical, pixel for pixel, on OpenGL, Vulkan, and each version of Direct3D.

Input feeds your UI code, which produces one draw list that any of five renderers can draw: OpenGL 3.3, Direct3D 9, 11, and 12, and Vulkan.

It respects the frame it draws into. kitui can also run inside another program’s render loop, which is useful for in-app tools and test environments. There, its renderers save and restore every piece of graphics state they touch, synchronize with the host’s own work, and leave the host’s image intact. Wherever kitui hooks into a function in that case, it does so conservatively: when it doesn’t fully recognize the code it would modify, it refuses and logs why instead of guessing, and it unloads cleanly, waiting until nothing is still running inside it. This mode is for your own applications and test environments only. kitui makes no attempt to evade anti-cheat systems.

Color is encoded for the target. A UI drawn onto an HDR or sRGB surface with naive color math looks washed out or too bright. kitui detects the target’s color space and encodes its colors to match, so the panel color is the same everywhere.

It’s tested as a whole. Beyond unit tests, kitui has simulated-input tests that drive the UI like a user, and a test host for each graphics API. Each host verifies that the UI is drawn, that the underlying image is untouched, and that the rendered panel color matches to the exact byte.

The look

kitui aims to look like a well-made native utility: dense, flat, and precise, with 1-pixel borders, square checkboxes, thin sliders, titled group boxes, and a gradient window frame tinted from the desktop palette. A tool built on it looks finished without any extra styling work.

Status

kitui is in active use across my projects, including spectre on Linux and Windows. It is proprietary: the source is private, and using it in other software requires my written permission.