Skip to main content

split_h_n_spaced

Function split_h_n_spaced 

Source
pub fn split_h_n_spaced<const N: usize>(
    area: Rect,
    constraints: [Constraint; N],
    spacing: impl Into<Spacing>,
) -> ([Rect; N], Vec<Rect>)
Expand description

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.

Reserves or hands back spacing.cells() * (N - 1) cells up front (equivalent to split_h_spaced) and solves the remaining panes against what’s left, so Fill/Percent panes share only the space after every gap is reserved, same as split_h_spaced. No-op (falls back to split_h_n, with an empty gap Vec) with fewer than two panes or zero spacing/overlap.

Returns (panes, gaps), same meaning as split_h_spaced’s return value: panes is the array of N content panes (never allocates, unlike the Vec-returning split_h_spaced), and gaps is a Vec of the N - 1 gap rects between them. gaps is a Vec rather than a second const-generic array because its length (N - 1) is not expressible as a fixed-size array tied to N on stable Rust.

§Examples

use retroglyph_core::grid::Rect;
use retroglyph_ui::{Constraint, split_h_n_spaced};

let area = Rect::new(0, 0, 59, 6);
let ([a, b, c], gaps) = split_h_n_spaced(area, [Constraint::Fill(1); 3], 1);
assert_eq!((a.width(), b.width(), c.width()), (19, 19, 19));
assert_eq!(b.left(), a.right() + 1);
assert_eq!(gaps.len(), 2);