Skip to main content

Module layout

Module layout 

Source
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 _spaced split: a fixed gap between them, or a shared, overlapping edge.

Functions§

anchored_rect
Place a size panel adjacent to anchor, preferring side, flipping to the opposite side when there isn’t room, and clamped to stay within bounds.
centered_rect
Compute a width×height Rect centered within screen.
split_h
Split area into columns left-to-right.
split_h_flex
Split area into columns left-to-right, like split_h, but with explicit control over how leftover space is placed via Flex.
split_h_n
Split area into columns left-to-right, like split_h, but sized to a compile-time pane count N: takes [Constraint; N] and returns [Rect; N] instead of allocating a Vec.
split_h_n_flex
Split area into columns left-to-right, like split_h_n, but with explicit control over how leftover space is placed via Flex, like split_h_flex.
split_h_n_spaced
Split area into columns left-to-right, like split_h_n, but with a spacing-cell gap or overlap between every adjacent pair of panes, like split_h_spaced; see Spacing.
split_h_spaced
Split area into columns left-to-right, like split_h, but with a spacing-cell gap or overlap between every adjacent pair of panes; see Spacing.
split_v
Split area into stacked rows top-to-bottom.
split_v_flex
Split area into stacked rows top-to-bottom, like split_v, but with explicit control over how leftover space is placed via Flex.
split_v_n
Split area into stacked rows top-to-bottom, like split_v, but sized to a compile-time pane count N: takes [Constraint; N] and returns [Rect; N] instead of allocating a Vec.
split_v_n_flex
Split area into stacked rows top-to-bottom, like split_v_n, but with explicit control over how leftover space is placed via Flex, like split_v_flex.
split_v_n_spaced
Split area into stacked rows top-to-bottom, like split_v_n, but with a spacing-cell gap or overlap between every adjacent pair of panes, like split_v_spaced; see Spacing.
split_v_spaced
Split area into stacked rows top-to-bottom, like split_v, but with a spacing-cell gap or overlap between every adjacent pair of panes; see Spacing.