pub fn split_h_spaced(
area: Rect,
constraints: &[Constraint],
spacing: impl Into<Spacing>,
) -> (Vec<Rect>, Vec<Rect>)Expand description
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.
spacing’s cell count is reserved from (for Spacing::Space) or added back to (for
Spacing::Overlap) area before constraints are resolved, so
Fill/Percent panes share only what’s left
after every gap is reserved, or the full extra room an overlap frees up. No-op (falls back
to split_h, with an empty gap Vec) with fewer than two panes or zero spacing/overlap.
Returns (panes, gaps): gaps has one entry between every adjacent pair of panes (so
constraints.len() - 1 gaps, none leading or trailing), in the same left-to-right order as
panes. For Spacing::Space a gap rect is the empty cell(s) between the two panes it
separates; for Spacing::Overlap it is the shared cell(s) both adjacent panes draw over
(whichever pane is drawn last wins there), which is exactly the region a caller would want to
draw a shared border into.
§Examples
use retroglyph_core::grid::Rect;
use retroglyph_ui::{Constraint, Spacing, split_h_spaced};
let area = Rect::new(0, 0, 59, 6);
let (panes, gaps) = split_h_spaced(area, &[Constraint::Fill(1); 3], 1);
assert_eq!(panes.iter().map(Rect::width).collect::<Vec<_>>(), vec![19, 19, 19]);
assert_eq!(panes[1].left(), panes[0].right() + 1); // one gap cell between panes
assert_eq!(gaps.len(), 2); // one gap between each adjacent pair of panes
assert_eq!(gaps[0], Rect::new(19, 0, 1, 6));
let (panes, gaps) = split_h_spaced(area, &[Constraint::Fill(1); 2], Spacing::Overlap(1));
assert_eq!(panes[1].left(), panes[0].right() - 1); // panes share one border column
assert_eq!(gaps[0], Rect::new(panes[0].right() - 1, 0, 1, 6)); // the shared column