ui_layout
A unified layout engine for Rust GUI development that treats Flexbox as a specialized form of Inline Block Flow layout.
This crate provides predictable layout system designed for custom GUI frameworks, editors, and experimental UI engines.
[!NOTE] This crate is under active development; patch releases may be frequent.
Features
Flexbox Support
- Flex layout (Row / Column direction, including
RowReverse/ColumnReverse) flex_growwith proportional space distributionflex_shrinkwith proportional space reduction when overflowingflex_basisfor initial sizing (supportsauto, pixel values, and percentages)justify_content(Start, Center, End, SpaceBetween, SpaceAround, SpaceEvenly)align_itemswith fullstretchsupport (Start, Center, End, Stretch)align_selffor individual item alignment override- Row and column gaps (
row_gap/column_gap) - Margin collapsing for block-level elements
Block, Inline & Flow Root
- Block layout with full CSS Box Model support (margin, padding, border,
box-sizing) - Inline layout with multi-line wrapping
display: flow-rootanddisplay: inline-block— establishes a new Block Formatting Context (margin collapsing isolation)BoxSizing: ContentBox and BorderBox
Extensibility
FlowLayoutertrait for custom inline flow layout delegationBlockLayoutertrait for custom block layout delegation (behindfeature = "unstable")
Values & Units
Lengthtypes:Px,Percent,Vw,Vhcalc()-style expressions:Add,Sub,Mul,Div,Min,Max,ClampLengthOrAutofor properties that supportautosizing- Min/max sizing (
min_width,max_width,min_height,max_height) line_heightsupport
Non-goals
- Full CSS compatibility
- Absolute / fixed positioning
- Web rendering or HTML/CSS parsing
Design goals
- Simple and explicit layout rules
- Easy to reason about and debug
- Suitable for custom renderers (wgpu, skia, etc.)
- No dependency on web standards or DOM
Example
use *;
// Create a flex container
let mut root = with_children;
// Layout with viewport size
layout;
// Access results
match &root.layout_box
For more examples and to understand the behavior of gaps, alignment, and sizing,
see the unit tests in the tests/ directory. They provide practical usage patterns and expected layouts.
Specification Compliance
This implementation follows CSS3 specifications with current focus on:
- ✅ CSS Box Model Module Level 3: Margin collapsing, padding, border, box-sizing support
- ✅ CSS Flexible Box Layout Module Level 1: Core flexbox algorithm including flex-grow, flex-shrink, flex-basis (flex-wrap not yet implemented)
- ✅ CSS Display Module Level 3: Block, Inline, Flex, FlowRoot, InlineBlock, and None display values
- ✅ CSS Values and Units Module Level 3: px, %, vw, vh, auto, and calc() support
Status
See CHANGELOG.md for a detailed list of changes.
- Version: 0.12.1
- API is evolving but now includes full Flexbox-like alignment, gaps, inline layout, and extensibility via traits
Future versions may add:
grid- Flex wrap support (
flex-wrap: wrap | nowrap | wrap-reverse) - Additional flex sizing rules (fr units, etc.)
- Absolute / fixed positioning
- Correct flex-basis priority over width/height in flex item sizing
License
MIT