Skip to main content

Module layout

Module layout 

Source
Expand description

Constraint-based Rect splitter for multi-panel UIs.

split_v/split_h split a Rect into stacked rows or side-by-side columns from a slice of Constraints; that pair plus Constraint is the whole entry point for the plain case. Spacing and leftover-space placement are opt-in knobs on Layout instead of separate named functions:

use retroglyph_core::grid::Rect;
use retroglyph_ui::layout::{Constraint, Flex, Layout};

let area = Rect::new(0, 0, 20, 10);
let panes = Layout::vertical([Constraint::Fixed(1), Constraint::Fill(1)])
    .spacing(1)
    .flex(Flex::Center)
    .split(area);
assert_eq!(panes.len(), 2);

Layout::spacing carves a fixed-cell gap (or Spacing::Overlap) between every adjacent pair of panes, without the caller having to interleave Constraint::Fixed(spacing) gap constraints and filter them back out by hand; Layout::split_with_gaps returns those gap rects alongside the content panes so a caller can draw dividers in them without recomputing the gap positions. Layout::flex controls where leftover space goes once constraints are resolved; see Flex.

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).

Structs§

Layout
Builder for split_v/split_h with optional spacing and leftover-space placement.

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_v
Split area into stacked rows top-to-bottom.