pub enum Node<Tab> {
Empty,
Leaf(LeafNode<Tab>),
Vertical(SplitNode),
Horizontal(SplitNode),
}
Expand description
Represents an abstract node of a Tree
.
Variants§
Empty
Empty node.
Leaf(LeafNode<Tab>)
Contains the actual tabs.
Vertical(SplitNode)
Parent node in the vertical orientation.
Horizontal(SplitNode)
Parent node in the horizontal orientation.
Implementations§
Source§impl<Tab> Node<Tab>
impl<Tab> Node<Tab>
Sourcepub fn get_leaf(&self) -> Option<&LeafNode<Tab>>
pub fn get_leaf(&self) -> Option<&LeafNode<Tab>>
Get immutable access to the leaf data of this node, if it contains any (i.e is a leaf)
Sourcepub fn get_leaf_mut(&mut self) -> Option<&mut LeafNode<Tab>>
pub fn get_leaf_mut(&mut self) -> Option<&mut LeafNode<Tab>>
Get mutable access to the leaf data of this node, if it contains any (i.e is a leaf)
Sourcepub const fn leaf_with(tabs: Vec<Tab>) -> Self
pub const fn leaf_with(tabs: Vec<Tab>) -> Self
Constructs a leaf node with a given list of tabs
.
Sourcepub fn set_rect(&mut self, new_rect: Rect)
pub fn set_rect(&mut self, new_rect: Rect)
Sets the area occupied by the node.
If the node is a Node::Empty
, this will do nothing.
Sourcepub const fn is_horizontal(&self) -> bool
pub const fn is_horizontal(&self) -> bool
Returns true
if the node is a Horizontal
, otherwise false
.
Sourcepub const fn is_vertical(&self) -> bool
pub const fn is_vertical(&self) -> bool
Returns true
if the node is a Vertical
, otherwise false
.
Sourcepub const fn is_parent(&self) -> bool
pub const fn is_parent(&self) -> bool
Returns true
if the node is either Horizontal
or Vertical
,
otherwise false
.
Sourcepub fn is_collapsed(&self) -> bool
pub fn is_collapsed(&self) -> bool
Returns true
if the node is collapsed, otherwise false
.
Sourcepub fn collapsed_leaf_count(&self) -> i32
pub fn collapsed_leaf_count(&self) -> i32
Returns the number of layers of collapsed leaf subnodes.
Sourcepub fn split(&mut self, split: Split, fraction: f32) -> Self
pub fn split(&mut self, split: Split, fraction: f32) -> Self
Replaces the node with Horizontal
or Vertical
(depending on split
)
and assigns an empty rect to it.
§Panics
If fraction
isn’t in range 0..=1.
Sourcepub fn tabs_mut(&mut self) -> Option<&mut [Tab]>
pub fn tabs_mut(&mut self) -> Option<&mut [Tab]>
Provides an mutable slice of the tabs inside this node.
Returns None
if the node is not a Leaf
.
§Examples
Modifying tabs inside a node:
let mut dock_state = DockState::new(vec![1, 2, 3, 4, 5, 6]);
let mut tabs = dock_state
.main_surface_mut()
.root_node_mut()
.unwrap()
.tabs_mut()
.unwrap();
tabs[0] = 7;
tabs[5] = 8;
assert_eq!(&tabs, &[7, 2, 3, 4, 5, 8]);
Sourcepub fn iter_tabs_mut(&mut self) -> impl Iterator<Item = &mut Tab>
pub fn iter_tabs_mut(&mut self) -> impl Iterator<Item = &mut Tab>
Sourcepub fn append_tab(&mut self, tab: Tab)
pub fn append_tab(&mut self, tab: Tab)
Adds tab
to the node and sets it as the active tab.
§Panics
If the new capacity of tabs
exceeds isize::MAX
bytes.
If self
is not a Leaf
node.
§Examples
let mut dock_state = DockState::new(vec!["a tab"]);
assert_eq!(dock_state.main_surface().root_node().unwrap().tabs_count(), 1);
dock_state.main_surface_mut().root_node_mut().unwrap().append_tab("another tab");
assert_eq!(dock_state.main_surface().root_node().unwrap().tabs_count(), 2);
Sourcepub fn set_collapsed(&mut self, collapsed: bool)
pub fn set_collapsed(&mut self, collapsed: bool)
Sourcepub fn set_collapsed_leaf_count(&mut self, count: i32)
pub fn set_collapsed_leaf_count(&mut self, count: i32)
Sets the number of layers of collapsed leaf subnodes.
§Panics
Panics if self
is neither a Vertical
nor a Horizontal
node.
Sourcepub fn insert_tab(&mut self, index: TabIndex, tab: Tab)
pub fn insert_tab(&mut self, index: TabIndex, tab: Tab)
Adds a tab
to the node.
§Panics
Panics if the new capacity of tabs
exceeds isize::MAX
bytes, or index > tabs_count()
.
Sourcepub fn remove_tab(&mut self, tab_index: TabIndex) -> Option<Tab>
pub fn remove_tab(&mut self, tab_index: TabIndex) -> Option<Tab>
Removes a tab at given index
from the node.
Returns the removed tab if the node is a Leaf
, or None
otherwise.
§Panics
Panics if index
is out of bounds.
Sourcepub fn tabs_count(&self) -> usize
pub fn tabs_count(&self) -> usize
Gets the number of tabs in the node.
Sourcepub fn filter_map_tabs<F, NewTab>(&self, function: F) -> Node<NewTab>
pub fn filter_map_tabs<F, NewTab>(&self, function: F) -> Node<NewTab>
Returns a new Node
while mapping and filtering the tab type.
If this Node
remains empty, it will change to Node::Empty
.
Sourcepub fn map_tabs<F, NewTab>(&self, function: F) -> Node<NewTab>
pub fn map_tabs<F, NewTab>(&self, function: F) -> Node<NewTab>
Returns a new Node
while mapping the tab type.
Sourcepub fn filter_tabs<F>(&self, predicate: F) -> Node<Tab>
pub fn filter_tabs<F>(&self, predicate: F) -> Node<Tab>
Returns a new Node
while filtering the tab type.
If this Node
remains empty, it will change to Node::Empty
.
Sourcepub fn retain_tabs<F>(&mut self, predicate: F)
pub fn retain_tabs<F>(&mut self, predicate: F)
Removes all tabs for which predicate
returns false
.
If this Node
remains empty, it will change to Node::Empty
.