pub enum LayoutNode {
Leaf {
pane: PaneId,
},
Split {
orientation: SplitOrientation,
ratio: SplitRatio,
a: Box<LayoutNode>,
b: Box<LayoutNode>,
},
}Expand description
One node in a window’s layout tree.
Variants§
Leaf
A single pane filling its bounding box.
Split
A split that divides its area between LayoutNode::Split::a
(top/left) and LayoutNode::Split::b (bottom/right). ratio
is a in 0.0..=1.0 — the fraction of the parent area allotted
to side a.
Implementations§
Source§impl LayoutNode
impl LayoutNode
Sourcepub fn split(
orientation: SplitOrientation,
a: LayoutNode,
b: LayoutNode,
) -> Self
pub fn split( orientation: SplitOrientation, a: LayoutNode, b: LayoutNode, ) -> Self
Convenience constructor for a balanced (ratio = 0.5) split.
Sourcepub fn panes(&self) -> Vec<PaneId>
pub fn panes(&self) -> Vec<PaneId>
Collect every pane id reachable from this node, in left-to- right (then top-to-bottom) traversal order. Useful for rendering a status bar that wants “the active window’s panes in display order”.
Sourcepub fn pane_count(&self) -> usize
pub fn pane_count(&self) -> usize
Number of leaves in the tree (= number of panes).
Sourcepub fn contains_pane(&self, pane: PaneId) -> bool
pub fn contains_pane(&self, pane: PaneId) -> bool
True when pane is one of this subtree’s leaves.
Sourcepub fn from_kind(kind: LayoutKind, panes: &[PaneId]) -> Option<Self>
pub fn from_kind(kind: LayoutKind, panes: &[PaneId]) -> Option<Self>
Arrange an ordered slice of panes into a named LayoutKind
preset — the live-tree twin of crate::LayoutPlan::realize. The
result always validates and (by the shipped
tiling property) compute_rects tiles its bounds exactly. Even*
arrangements give every pane a 1/n share (ratio 1/(n-k) per
split level), so an even-3 row is three equal thirds, not a
balanced binary 0.5 split.
Returns None for an empty slice and for LayoutKind::Custom
(whose tree is its own source of truth — there is no canonical
arrangement to build). A single pane yields a leaf for any kind.
Sourcepub fn split_leaf(
&mut self,
target: PaneId,
new_pane: PaneId,
direction: Direction,
origin_ratio: f32,
) -> bool
pub fn split_leaf( &mut self, target: PaneId, new_pane: PaneId, direction: Direction, origin_ratio: f32, ) -> bool
Replace the leaf holding target with a split whose two children
are the original pane and a fresh new_pane, ordered by
direction. This is the correct split — it replaces only the
matched leaf, leaving every other pane’s position untouched
(unlike a whole-window re-wrap). origin_ratio is the fraction
the target keeps (clamped to [MIN_RATIO, 1 - MIN_RATIO]);
pass 0.5 for a balanced split.
Returns true if target was found and split. A Right/Below
split puts the new pane after the target (right/below); a
Left/Above split puts it before.
Sourcepub fn remove_leaf(&mut self, target: PaneId) -> LeafRemoval
pub fn remove_leaf(&mut self, target: PaneId) -> LeafRemoval
Remove the leaf holding target and collapse its parent split
into the surviving sibling — no dangling NULL leaf, no blank
hole. See LeafRemoval for the three outcomes.
Sourcepub fn resize_leaf(
&mut self,
target: PaneId,
direction: Direction,
delta_frac: f32,
) -> bool
pub fn resize_leaf( &mut self, target: PaneId, direction: Direction, delta_frac: f32, ) -> bool
Move the divider of the split governing target along direction
by delta_frac (a fraction of that split). Finds the deepest
ancestor split whose orientation matches the direction’s axis and
contains target, then slides its divider: Right/Below raise the
ratio (the upper/left side grows), Left/Above lower it. Returns
true if such a divider was found.
For the natural gesture — grow a left pane Right, a right pane
Left, a top pane Below, a bottom pane Above — this enlarges the
focused pane, because direction then points across the shared
divider toward target’s neighbour. The ratio is clamped to
[MIN_RATIO, 1 - MIN_RATIO], so a divider never pins a pane to
zero (cell rounding may still squeeze a too-small window).
Sourcepub fn compute_rects(&self, bounds: Rect) -> Vec<(PaneId, Rect)>
pub fn compute_rects(&self, bounds: Rect) -> Vec<(PaneId, Rect)>
Compute the pixel/cell rectangle of every pane, laying the tree
out within bounds. This is the layout renderer — mado draws
from it, tear-core sizes PTYs from it. Division is gap-free and
overlap-free: side b gets exactly the remainder side a left.
Sourcepub fn neighbor(
&self,
target: PaneId,
direction: Direction,
bounds: Rect,
) -> Option<PaneId>
pub fn neighbor( &self, target: PaneId, direction: Direction, bounds: Rect, ) -> Option<PaneId>
The pane the operator would land on by moving direction from
target, laid out within bounds (tmux select-pane -L/-R/-U/-D).
Among every pane on that side that shares perpendicular edge with
target, picks the nearest (smallest gap along the axis of
motion), tie-broken by the largest shared edge. The result is
independent of tree shape and traversal order. Returns None at
the window edge or for an unknown target.
Sourcepub fn validate(&self) -> Result<(), LayoutError>
pub fn validate(&self) -> Result<(), LayoutError>
Verify the tree’s structural invariants. A tree that validates is
safe to render; one that fails carries a typed LayoutError
naming the illegal shape instead of silently mis-drawing.
Trait Implementations§
Source§impl Clone for LayoutNode
impl Clone for LayoutNode
Source§fn clone(&self) -> LayoutNode
fn clone(&self) -> LayoutNode
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more