pub struct Layout { /* private fields */ }Expand description
Builder for split_v/split_h with optional spacing and leftover-space placement.
Layout::vertical/Layout::horizontal take the Constraints (anything that converts to
a Vec<Constraint>: an array literal, a Vec, or a Box<[Constraint]>); Layout::spacing
and Layout::flex are optional chained calls that default to no spacing and
Flex::Start, matching plain split_v/split_h. Layout::split
resolves the panes; Layout::split_with_gaps also returns the gap Rects a caller would
draw dividers into, the same pair split_h-with-spacing used to return.
§Examples
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);Implementations§
Source§impl Layout
impl Layout
Sourcepub fn vertical(constraints: impl Into<Vec<Constraint>>) -> Self
pub fn vertical(constraints: impl Into<Vec<Constraint>>) -> Self
Split into stacked rows top-to-bottom, like split_v.
Sourcepub fn horizontal(constraints: impl Into<Vec<Constraint>>) -> Self
pub fn horizontal(constraints: impl Into<Vec<Constraint>>) -> Self
Split into columns left-to-right, like split_h.
Sourcepub fn spacing(self, spacing: impl Into<Spacing>) -> Self
pub fn spacing(self, spacing: impl Into<Spacing>) -> Self
Carve a fixed-cell gap (or Spacing::Overlap) between every adjacent pair of panes; see
Spacing. Defaults to no spacing, matching plain split_v/split_h.
Sourcepub const fn flex(self, flex: Flex) -> Self
pub const fn flex(self, flex: Flex) -> Self
Control where leftover space is placed once constraints are resolved; see Flex.
Defaults to Flex::Start, matching plain split_v/split_h.
Sourcepub fn split(&self, area: Rect) -> Vec<Rect> ⓘ
pub fn split(&self, area: Rect) -> Vec<Rect> ⓘ
Split area into panes along vertical/horizontal
per the builder’s constraints, spacing, and flex.
Sourcepub fn split_with_gaps(&self, area: Rect) -> (Vec<Rect>, Vec<Rect>)
pub fn split_with_gaps(&self, area: Rect) -> (Vec<Rect>, Vec<Rect>)
Split area like split, and also return the gap Rects between every
adjacent pair of panes carved out by spacing.
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 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. gaps is empty with fewer than two panes or zero spacing/overlap.
§Examples
use retroglyph_core::grid::Rect;
use retroglyph_ui::layout::{Constraint, Layout};
let area = Rect::new(0, 0, 59, 6);
let (panes, gaps) = Layout::horizontal([Constraint::Fill(1); 3])
.spacing(1)
.split_with_gaps(area);
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));