Skip to main content

Layout

Struct Layout 

Source
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

Source

pub fn vertical(constraints: impl Into<Vec<Constraint>>) -> Self

Split into stacked rows top-to-bottom, like split_v.

Source

pub fn horizontal(constraints: impl Into<Vec<Constraint>>) -> Self

Split into columns left-to-right, like split_h.

Source

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.

Source

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.

Source

pub fn split(&self, area: Rect) -> Vec<Rect> ⓘ

Split area into panes along vertical/horizontal per the builder’s constraints, spacing, and flex.

Never panics, for the same reason as split_v/split_h.

Source

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

Trait Implementations§

Source§

impl Clone for Layout

Source§

fn clone(&self) -> Layout

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Layout

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.