Skip to main content

split_geometry

Function split_geometry 

Source
pub fn split_geometry(
    area: LayoutRect,
    dir: SplitDir,
    ratio: f32,
    fixed: Option<Fixed>,
) -> SplitGeometry
Expand description

Divide area between one split’s two children, carving out the separator.

This is the single source of truth for split geometry: the headless LayoutTree::window_rects walk, the TUI renderer (which also needs the separator rect to draw it) and the mouse border hit-test all call it, so a border the user can see is always a border they can grab.

§Separator rules

Vertical (side-by-side, Axis::Col): separator is the rightmost cell of a’s allocation. Applied only when that allocation is >= 2 columns AND b gets > 0; a shrinks by 1 column, b position/size are unchanged.

Horizontal (stacked, Axis::Row): separator is the bottom cell of a’s allocation. Applied only when that allocation is >= 2 rows AND b gets > 0; a shrinks by 1 row, b position/size are unchanged.

§Fixed sizes

fixed replaces the round(len * ratio) term with the allocation that makes the named child render exactly the requested number of cells (see Fixed and first_child_cells). It goes through the identical clamp, so an oversized request can never underflow u16 or leave the sibling with zero cells in an area that could hold both.

§Examples

use hjkl_layout::{Fixed, LayoutRect, SplitDir, split_geometry};

let geo = split_geometry(
    LayoutRect::new(0, 0, 80, 24),
    SplitDir::Vertical,
    0.5,
    Some(Fixed::First(30)),
);
assert_eq!(geo.a.w, 30);
assert_eq!(geo.separator.map(|s| s.x), Some(30));
assert_eq!((geo.b.x, geo.b.w), (31, 49));