Rust library implementing CSS Block, Flexbox, and Grid layout. Built as a dependency for UI and GUI toolkits with high-level and low-level APIs.
Overview
Taffy computes two-dimensional positions and sizes for trees of UI nodes from CSS-style inputs. It implements Block, Flexbox, and CSS Grid layout from the specification, with further paradigms planned on its public roadmap.
Each node carries style inputs and layout outputs (position and dimensions). Optional child lists and user context support measure functions when integrating text or other layout modes. Workflows build a node tree, run layout computation, then read per-node geometry.
The high-level TaffyTree API manages storage, caching, and algorithm dispatch. The low-level API exposes traits such as LayoutPartialTree and functions like compute_flexbox_layout for embedding inside existing widget trees. Feature flags toggle block, float, flexbox, grid, calc, and content-size behavior.
The crate targets collaboration across UI teams and compares benchmark times against Yoga on large trees. Work-in-progress C and WASM bindings are noted for other language consumers.
Key features
- CSS Flexbox layout
- CSS Grid layout
- Block and float layout
- High-level TaffyTree API
- Low-level trait integration
- Measure function hooks
- Optional serde on styles
- Layout caching support
Use cases
- GUI toolkit layout backend
- Cross-platform UI frameworks
- DOM-like node tree layout
- Embedding in custom renderers