randrew/layout
FreeSingle-file library for calculating 2D UI layouts using stacking boxes. Compiles as C99 or C++.
About randrew/layout
Layout is a single-file C library for calculating 2D user interface layouts using a stacking box model. It compiles as both C99 and C++, has no external dependencies (by default uses standard library functions that can be replaced via preprocessor definitions), and supports integer (int16) or floating-point (float) coordinates. Based on the oui library, Layout focuses solely on layout calculation and does not handle user input, focus, or UI state. It is tested with GCC, Clang/LLVM, and MSVC (MSVC requires C++ compilation). The library is designed to be easily integrated into any project by copying one header file and defining LAY_IMPLEMENTATION in a single translation unit.
Key Features
Pros & Cons
- Extremely easy to integrate: one header file, no build system required
- No external dependencies – self-contained and portable
- Supports both integer and floating-point coordinate systems
- Compiles as both C and C++ for broad compatibility
- Customizable memory functions allow use in constrained environments
- Fast and lightweight; suitable for real-time use
- Limited to stacking box layout; no flexbox or grid support
- Does not handle user input, focus, or UI state (must be integrated with other code)
- MSVC requires C++ compilation due to lack of vector_size extension
- No built-in support for advanced layout features like scrolling or constraints