Skip to main content

LayoutNode

Enum LayoutNode 

Source
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.

Fields

§pane: PaneId
§

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

Source

pub fn leaf(pane: PaneId) -> Self

Convenience constructor for a leaf.

Source

pub fn split( orientation: SplitOrientation, a: LayoutNode, b: LayoutNode, ) -> Self

Convenience constructor for a balanced (ratio = 0.5) split.

Source

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”.

Source

pub fn pane_count(&self) -> usize

Number of leaves in the tree (= number of panes).

Source

pub fn contains_pane(&self, pane: PaneId) -> bool

True when pane is one of this subtree’s leaves.

Source

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.

Source

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.

Source

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.

Source

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

Source

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.

Source

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.

Source

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

Source§

fn clone(&self) -> LayoutNode

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 LayoutNode

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for LayoutNode

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for LayoutNode

Source§

fn eq(&self, other: &LayoutNode) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for LayoutNode

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for LayoutNode

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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.