Clay Project Description
What is the project about?
Clay (C Layout) is a high-performance 2D UI layout library designed for creating complex and responsive user interfaces. It focuses on speed and efficiency, offering a flexbox-like layout model.
What problem does it solve?
Clay addresses the need for a fast, lightweight, and flexible UI layout system that can be easily integrated into various rendering environments, including game engines and web browsers (via WebAssembly). It avoids dependencies on large UI frameworks or the standard library, making it suitable for resource-constrained environments. It provides a declarative, React-like syntax for building UIs, simplifying the development process.
What are the features of the project?
- High Performance: Achieves microsecond layout performance.
- Flexbox-like Layout: Supports complex layouts with features like text wrapping, scrolling containers, and aspect ratio scaling.
- Minimal Dependencies: A single, small (~2k LOC) header file (
clay.h
) with zero dependencies (not even the standard library). - WebAssembly Support: Compiles to a small Wasm module for web use.
- Arena-Based Memory: Uses static arena allocation, avoiding dynamic memory allocation (malloc/free) and minimizing memory overhead.
- Declarative Syntax: Offers a React-like nested declarative syntax for defining UI hierarchies.
- Renderer Agnostic: Outputs a sorted list of rendering primitives, making it compatible with various rendering engines and even HTML.
- Mouse/Touch Interaction: Provides functions for handling mouse/touch events, including hover and click detection.
- Scrolling: Built-in support for scrollable containers.
- Floating Elements: Supports "absolute" positioning with floating elements (e.g., for tooltips and modals).
- Custom Elements: Allows defining and laying out custom UI elements.
- Visibility Culling: Built-in culling of invisible elements to improve rendering performance.
- Debug Tools: Includes integrated UI debugging tools similar to browser inspectors.
- Retained Mode Support: Can be integrated into retained-mode rendering systems.
- Multiple Instances: Supports running multiple Clay instances within a single program.
What are the technologies used in the project?
- C99/C++20: The core library is written in C, compatible with both C99 and C++20 (with designated initializer support).
- WebAssembly (Wasm): Can be compiled to Wasm for web deployment.
- Macro-based API: Uses C macros extensively for its declarative syntax.
- (Optional) Bindings: Has bindings for Odin and Rust.
What are the benefits of the project?
- Speed: Extremely fast layout calculations.
- Small Size: Minimal code footprint, ideal for embedded systems or web.
- Flexibility: Adaptable to different rendering backends.
- Ease of Use: Declarative syntax simplifies UI development.
- Low Memory Usage: Efficient memory management with arena allocation.
- Portability: Works on various platforms, including web browsers.
- Extensibility: Supports custom elements and renderers.
What are the use cases of the project?
- Game UI: Creating user interfaces within game engines.
- Embedded Systems: Developing UIs for devices with limited resources.
- Web Applications: Building fast and lightweight web UIs (via Wasm).
- GUI Applications: Developing desktop applications with custom rendering.
- Prototyping: Rapidly creating UI prototypes.
- Tools and Editors: Building internal tools with custom UIs.
- Any situation where a fast, flexible, and lightweight 2D layout engine is needed.
