pub struct Tree<Tab> { /* private fields */ }
Expand description
Binary tree representing the relationships between Node
s.
Implementation details
The binary tree is stored in a Vec
indexed by NodeIndex
.
The root is always at index 0.
For a given node n:
- left child of n will be at index n * 2 + 1.
- right child of n will be at index n * 2 + 2.
Implementations§
source§impl<Tab> Tree<Tab>
impl<Tab> Tree<Tab>
sourcepub fn find_active(&mut self) -> Option<(Rect, &mut Tab)>
pub fn find_active(&mut self) -> Option<(Rect, &mut Tab)>
Returns the viewport Rect
and the Tab
inside the first leaf node, or None
of no leaf exists in the Tree
.
sourcepub fn find_active_focused(&mut self) -> Option<(Rect, &mut Tab)>
pub fn find_active_focused(&mut self) -> Option<(Rect, &mut Tab)>
Returns the viewport Rect
and the Tab
inside the focused leaf node or None
if it does not exist.
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true
if the number of nodes in the tree is 0, false
otherwise.
sourcepub fn iter_mut(&mut self) -> IterMut<'_, Node<Tab>>
pub fn iter_mut(&mut self) -> IterMut<'_, Node<Tab>>
Returns IterMut
of the underlying collection of nodes.
sourcepub fn split_tabs(
&mut self,
parent: NodeIndex,
split: Split,
fraction: f32,
tabs: Vec<Tab>
) -> [NodeIndex; 2]
pub fn split_tabs( &mut self, parent: NodeIndex, split: Split, fraction: f32, tabs: Vec<Tab> ) -> [NodeIndex; 2]
Creates two new nodes by splitting a given parent
node and assigns them as its children. The first (old) node
inherits content of the parent
from before the split, and the second (new) has tabs
.
fraction
(in range 0..=1) specifies how much of the parent
node’s area the old node is will occupy after the
split.
The new node is placed relatively to the old node, in the direction specified by split
.
Returns the indices of the old node and the new node.
sourcepub fn split_above(
&mut self,
parent: NodeIndex,
fraction: f32,
tabs: Vec<Tab>
) -> [NodeIndex; 2]
pub fn split_above( &mut self, parent: NodeIndex, fraction: f32, tabs: Vec<Tab> ) -> [NodeIndex; 2]
Creates two new nodes by splitting a given parent
node and assigns them as its children. The first (old) node
inherits content of the parent
from before the split, and the second (new) has tabs
.
fraction
(in range 0..=1) specifies how much of the parent
node’s area the old node is will occupy after the
split.
The new node is placed above the old node.
Returns the indices of the old node and the new node.
sourcepub fn split_below(
&mut self,
parent: NodeIndex,
fraction: f32,
tabs: Vec<Tab>
) -> [NodeIndex; 2]
pub fn split_below( &mut self, parent: NodeIndex, fraction: f32, tabs: Vec<Tab> ) -> [NodeIndex; 2]
Creates two new nodes by splitting a given parent
node and assigns them as its children. The first (old) node
inherits content of the parent
from before the split, and the second (new) has tabs
.
fraction
(in range 0..=1) specifies how much of the parent
node’s area the old node is will occupy after the
split.
The new node is placed below the old node.
Returns the indices of the old node and the new node.
sourcepub fn split_left(
&mut self,
parent: NodeIndex,
fraction: f32,
tabs: Vec<Tab>
) -> [NodeIndex; 2]
pub fn split_left( &mut self, parent: NodeIndex, fraction: f32, tabs: Vec<Tab> ) -> [NodeIndex; 2]
Creates two new nodes by splitting a given parent
node and assigns them as its children. The first (old) node
inherits content of the parent
from before the split, and the second (new) has tabs
.
fraction
(in range 0..=1) specifies how much of the parent
node’s area the old node is will occupy after the
split.
The new node is placed to the left of the old node.
Returns the indices of the old node and the new node.
sourcepub fn split_right(
&mut self,
parent: NodeIndex,
fraction: f32,
tabs: Vec<Tab>
) -> [NodeIndex; 2]
pub fn split_right( &mut self, parent: NodeIndex, fraction: f32, tabs: Vec<Tab> ) -> [NodeIndex; 2]
Creates two new nodes by splitting a given parent
node and assigns them as its children. The first (old) node
inherits content of the parent
from before the split, and the second (new) has tabs
.
fraction
(in range 0..=1) specifies how much of the parent
node’s area the old node is will occupy after the
split.
The new node is placed to the right of the old node.
Returns the indices of the old node and the new node.
sourcepub fn split(
&mut self,
parent: NodeIndex,
split: Split,
fraction: f32,
new: Node<Tab>
) -> [NodeIndex; 2]
pub fn split( &mut self, parent: NodeIndex, split: Split, fraction: f32, new: Node<Tab> ) -> [NodeIndex; 2]
Creates two new nodes by splitting a given parent
node and assigns them as its children. The first (old) node
inherits content of the parent
from before the split, and the second (new) has tabs
.
fraction
(in range 0..=1) specifies how much of the parent
node’s area the old node is will occupy after the
split.
The new node is placed relatively to the old node, in the direction specified by split
.
Returns the indices of the old node and the new node.
sourcepub fn remove_empty_leaf(&mut self)
pub fn remove_empty_leaf(&mut self)
Removes the first node containing 0 tabs.
sourcepub fn push_to_first_leaf(&mut self, tab: Tab)
pub fn push_to_first_leaf(&mut self, tab: Tab)
Push a tab to the first leaf it finds or creates a leaf if an empty spot is encountered.
sourcepub fn focused_leaf(&self) -> Option<NodeIndex>
pub fn focused_leaf(&self) -> Option<NodeIndex>
Currently focused leaf.
sourcepub fn set_focused_node(&mut self, node_index: NodeIndex)
pub fn set_focused_node(&mut self, node_index: NodeIndex)
Sets the currently focused leaf to node_index
if the node at node_index
is a leaf.
sourcepub fn set_active_tab(&mut self, node_index: NodeIndex, tab_index: TabIndex)
pub fn set_active_tab(&mut self, node_index: NodeIndex, tab_index: TabIndex)
Sets which is the active tab within a specific node.
sourcepub fn push_to_focused_leaf(&mut self, tab: Tab)
pub fn push_to_focused_leaf(&mut self, tab: Tab)
Pushes tab
to the currently focused leaf.
If no leaf is focused it will be pushed to the first available leaf.
If no leaf is available then a new leaf will be created.