Skip to main content

Crate hjkl_layout

Crate hjkl_layout 

Source
Expand description

Renderer-agnostic window/split layout machinery for the hjkl editor stack.

A LayoutTree holds either a single Leaf (one window) or a Split that recursively divides space between two sub-trees. All geometry is expressed as LayoutRect — a plain u16 rectangle that TUI hosts convert from ratatui::layout::Rect and GUI hosts convert from their own coordinate types at the boundary.

§Quick start

use hjkl_layout::{LayoutTree, SplitDir, LayoutRect};

let mut tree = LayoutTree::Leaf(0);
assert_eq!(tree.leaves(), vec![0]);

// Split window 0 horizontally — window 1 below window 0.
tree.replace_leaf(0, |id| {
    LayoutTree::split(
        SplitDir::Horizontal,
        0.5,
        LayoutTree::Leaf(id),
        LayoutTree::Leaf(1),
    )
});
assert_eq!(tree.leaves(), vec![0, 1]);
assert_eq!(tree.neighbor_below(0), Some(1));
assert_eq!(tree.neighbor_below(1), None);

Structs§

LayoutRect
Renderer-agnostic rectangle used by the layout tree.
SplitGeometry
Where one split’s two children and its separator land inside a parent rect.
Tab
Per-tab layout + focus state.
Window
Per-window scroll + geometry state.

Enums§

Axis
Which geometric axis a split is oriented along.
Fixed
An exact size for one child of a Split, overriding that split’s ratio.
LayoutTree
A binary spatial tree that partitions the editor area into windows.
SplitDir
Direction of a split.

Functions§

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

Type Aliases§

WindowId
Stable id into the host window list. Never reused — new windows get the next value from the host’s next_window_id counter.