Single-header C library for high-performance, flexbox-like 2D UI layout that works with any renderer
open sourceZlibfree
Clay (short for C Layout) is a zlib-licensed 2D UI layout library by Nic Barker, shipped as a single clay.h header of about 4,800 lines with no dependencies, not even the C standard library. It lays out interfaces in microseconds with a flexbox-like model that handles text wrapping, scrolling containers and aspect ratio scaling, using a React-like nested declarative syntax written as plain C macros, static arena memory with no malloc or free, and a transition API for layout animations. It doesn't draw anything itself: it outputs a sorted list of rendering primitives for any renderer, with examples in its repository such as raylib and the web, including compiling to a 15 KB WebAssembly file or HTML. It works from C99 and C++20, with Odin and Rust bindings. It isn't the Clay data enrichment product.
Problems it solves
- lay out a game or tool UI in C without pulling in a big GUI framework
- a flexbox-style layout engine I can plug into my own renderer
- build a UI in C that also runs in the browser through WebAssembly
Features
- microsecond layout performance
- flexbox-like layout with text wrapping, scrolling and aspect ratio scaling
- single header with zero dependencies
- static arena memory, no malloc or free
- renderer agnostic output of render commands
- compiles to a 15 KB WebAssembly file
- transition API for layout animations
- built-in debug inspector
- Odin and Rust bindings
Alternatives
The same job
These do what Clay does.
- Dear ImGui Bloat-free graphical user interface library for C++ with minimal dependencies
