nicbarker/clay logo

nicbarker/clay

Free

High performance UI layout library in C.

FreeFree tier
Type
Open Source

About nicbarker/clay

Clay (short for C Layout) is a high performance 2D UI layout library written in C. It provides a flex-box-like layout model for building complex, responsive user interfaces with support for text wrapping, scrolling containers, and aspect ratio scaling. Clay features a single-file header (clay.h) with zero dependencies, microsecond layout performance, and a static arena-based memory system that avoids malloc/free. It includes a declarative, React-like syntax, a transition API for animations, and is renderer agnostic: it outputs a sorted list of rendering primitives that can be composited in any 3D engine or compiled to HTML. Clay can be compiled to WebAssembly (15kb uncompressed) for browser use. The library is open source under the MIT license.

Key Features

Microsecond layout performance
Flex-box like layout model for complex, responsive layouts including text wrapping, scrolling containers and aspect ratio scaling
Transition API for easy layout animations
Single 4.8k LOC clay.h file with zero dependencies (including no standard library linking)
Wasm support: compile with Clang to a 15kb uncompressed .wasm file for browser use
Static arena based memory use with no malloc/free, and low total memory overhead (e.g., ~3.5mb for 8192 layout elements)
React-like nested declarative syntax
Renderer agnostic: outputs a sorted list of rendering primitives that can be composited in any 3D engine and compiled to HTML

Pros & Cons

Pros
  • Extremely high performance with microsecond layout times
  • Zero runtime dependencies, single header file
  • Suitable for resource-constrained environments (no malloc, low memory overhead)
  • Renderer agnostic, works with any graphics engine or HTML
  • Declarative, functional API inspired by modern frameworks
  • Supports responsive design with flex-box model
  • Built-in transition API for smooth animations
  • Open source with permissive MIT license
Cons
  • Limited to 2D UI layout; no built-in rendering or window management
  • Requires C/C++ development and manual integration with a renderer
  • Documentation and examples are primarily in the GitHub repository
  • Not an AI tool (though it can be used to build AI tool GUIs)

Best For

Building cross-platform GUI applicationsCreating WebAssembly-based UI components for browsersEmbedded systems UI where minimal dependencies are criticalPrototyping responsive layouts with declarative syntaxRapid development of custom UI toolkits or game interfaces

FAQ

What is Clay?
Clay (short for C Layout) is a high performance 2D UI layout library written in C. It provides a flex-box-like layout model, zero dependencies, and outputs a list of rendering primitives for any renderer.
How do I use Clay?
Download the single header file (clay.h), include it in your C project after defining CLAY_IMPLEMENTATION in one source file, and define your layout using the provided declarative macros and functions.
Does Clay support WebAssembly?
Yes, Clay can be compiled with Clang to a 15kb uncompressed WebAssembly module for use in the browser.
What are Clay's memory requirements?
Clay uses a static arena-based memory system with no dynamic allocation. For example, 8192 layout elements require approximately 3.5MB of memory.
Is Clay platform-independent?
Clay is written in C and has no platform-specific dependencies. It outputs abstract rendering primitives that can be used on any platform with a suitable renderer.