Expand description
Constraint-based Rect splitter for multi-panel UIs.
Splits a Rect into stacked rows (split_v) or side-by-side columns
(split_h) according to a slice of Constraints. split_h_spaced/split_v_spaced
do the same but also carve a fixed-cell gap between every adjacent pair of panes, without the
caller having to interleave Constraint::Fixed(spacing) gap constraints and filter them back
out by hand; they return the gap rects alongside the content panes so a caller can draw
dividers in them without recomputing the gap positions.
Every split_* function has a const-generic split_*_n sibling (split_v_n/split_h_n,
plus the _flex/_spaced combinations) that takes [Constraint; N] and returns [Rect; N]
instead of allocating a Vec<Rect>: useful for a fixed pane count re-split every frame, and
the array return type lets a caller destructure (let [header, body] = split_v_n(area, [..]);)
instead of indexing into a Vec that can silently drift out of sync with the constraint list.
The solver sums the Fixed, Percent, and
Ratio amounts, then distributes whatever remains across the
Fill,
Min, and Max panes in proportion to their
weight: a Fill(w) pane claims a share proportional to w relative
to the other flexible panes, while Min and Max
panes always weigh 1. Fill(1) (equivalent to every pane weighing 1) reproduces plain
equal distribution. Sizes are clamped so the panes never spill past area. This is a
single sequential pass, not an iterative constraint solver: a Max
pane that is capped below its share does not redistribute the excess to other panes, so
leftover space can remain unclaimed (see Flex for how that leftover is placed via
split_v_flex/split_h_flex).
Enums§
- Constraint
- How a single pane claims space along the split axis.
- Flex
- How leftover space is placed along the split axis, once
Constraints are resolved. - Side
- Which side of an anchor rect a panel prefers to open on, for
anchored_rect. - Spacing
- How adjacent panes relate along the split axis in a
_spacedsplit: a fixed gap between them, or a shared, overlapping edge.
Functions§
- anchored_
rect - Place a
sizepanel adjacent toanchor, preferringside, flipping to the opposite side when there isn’t room, and clamped to stay withinbounds. - centered_
rect - Compute a
width×heightRectcentered withinscreen. - split_h
- Split
areainto columns left-to-right. - split_
h_ flex - Split
areainto columns left-to-right, likesplit_h, but with explicit control over how leftover space is placed viaFlex. - split_
h_ n - Split
areainto columns left-to-right, likesplit_h, but sized to a compile-time pane countN: takes[Constraint; N]and returns[Rect; N]instead of allocating aVec. - split_
h_ n_ flex - Split
areainto columns left-to-right, likesplit_h_n, but with explicit control over how leftover space is placed viaFlex, likesplit_h_flex. - split_
h_ n_ spaced - Split
areainto columns left-to-right, likesplit_h_n, but with aspacing-cell gap or overlap between every adjacent pair of panes, likesplit_h_spaced; seeSpacing. - split_
h_ spaced - Split
areainto columns left-to-right, likesplit_h, but with aspacing-cell gap or overlap between every adjacent pair of panes; seeSpacing. - split_v
- Split
areainto stacked rows top-to-bottom. - split_
v_ flex - Split
areainto stacked rows top-to-bottom, likesplit_v, but with explicit control over how leftover space is placed viaFlex. - split_
v_ n - Split
areainto stacked rows top-to-bottom, likesplit_v, but sized to a compile-time pane countN: takes[Constraint; N]and returns[Rect; N]instead of allocating aVec. - split_
v_ n_ flex - Split
areainto stacked rows top-to-bottom, likesplit_v_n, but with explicit control over how leftover space is placed viaFlex, likesplit_v_flex. - split_
v_ n_ spaced - Split
areainto stacked rows top-to-bottom, likesplit_v_n, but with aspacing-cell gap or overlap between every adjacent pair of panes, likesplit_v_spaced; seeSpacing. - split_
v_ spaced - Split
areainto stacked rows top-to-bottom, likesplit_v, but with aspacing-cell gap or overlap between every adjacent pair of panes; seeSpacing.