pub enum Node<Tab> {
Empty,
Leaf {
rect: Rect,
viewport: Rect,
tabs: Vec<Tab>,
active: TabIndex,
scroll: f32,
},
Vertical {
rect: Rect,
fraction: f32,
},
Horizontal {
rect: Rect,
fraction: f32,
},
}
Expand description
Represents an abstract node of a Tree
.
Variants§
Empty
Empty node.
Leaf
Contains the actual tabs.
Vertical
Fields
rect: Rect
The rectangle in which all children of this node are drawn.
Parent node in the vertical orientation.
Horizontal
Fields
rect: Rect
The rectangle in which all children of this node are drawn.
Parent node in the horizontal orientation.
Implementations§
source§impl<Tab> Node<Tab>
impl<Tab> Node<Tab>
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 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 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 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 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.