Enum Node

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

Source

pub fn leaf(tab: Tab) -> Self

Constructs a leaf node with a given tab.

Source

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)

Source

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)

Source

pub const fn leaf_with(tabs: Vec<Tab>) -> Self

Constructs a leaf node with a given list of tabs.

Source

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.

Source

pub fn rect(&self) -> Option<Rect>

Get a Rect occupied by the node, could be used e.g. to draw a highlight rect around a node.

Returns None if node is of the Empty variant.

Source

pub const fn is_empty(&self) -> bool

Returns true if the node is a Empty, otherwise false.

Source

pub const fn is_leaf(&self) -> bool

Returns true if the node is a Leaf, otherwise false.

Source

pub const fn is_horizontal(&self) -> bool

Returns true if the node is a Horizontal, otherwise false.

Source

pub const fn is_vertical(&self) -> bool

Returns true if the node is a Vertical, otherwise false.

Source

pub const fn is_parent(&self) -> bool

Returns true if the node is either Horizontal or Vertical, otherwise false.

Source

pub fn is_collapsed(&self) -> bool

Returns true if the node is collapsed, otherwise false.

Source

pub fn collapsed_leaf_count(&self) -> i32

Returns the number of layers of collapsed leaf subnodes.

Source

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.

Source

pub fn tabs(&self) -> Option<&[Tab]>

Provides an immutable slice of the tabs inside this node.

Returns None if the node is not a Leaf.

§Examples
let mut dock_state = DockState::new(vec![1, 2, 3, 4, 5, 6]);
assert!(dock_state.main_surface().root_node().unwrap().tabs().unwrap().contains(&4));
Source

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]);
Source

pub fn iter_tabs(&self) -> impl Iterator<Item = &Tab>

Returns an Iterator of tabs in this node.

If this node is not a Leaf, then the returned Iterator will be empty.

Source

pub fn iter_tabs_mut(&mut self) -> impl Iterator<Item = &mut Tab>

Returns a mutable Iterator of tabs in this node.

If this node is not a Leaf, then the returned Iterator will be empty.

Source

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);
Source

pub fn set_collapsed(&mut self, collapsed: bool)

Sets the collapsing state of the node.

§Panics

Panics if self is an Empty node.

Source

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.

Source

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

Source

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.

Source

pub fn tabs_count(&self) -> usize

Gets the number of tabs in the node.

Source

pub fn filter_map_tabs<F, NewTab>(&self, function: F) -> Node<NewTab>
where F: FnMut(&Tab) -> Option<NewTab>,

Returns a new Node while mapping and filtering the tab type. If this Node remains empty, it will change to Node::Empty.

Source

pub fn map_tabs<F, NewTab>(&self, function: F) -> Node<NewTab>
where F: FnMut(&Tab) -> NewTab,

Returns a new Node while mapping the tab type.

Source

pub fn filter_tabs<F>(&self, predicate: F) -> Node<Tab>
where F: FnMut(&Tab) -> bool, Tab: Clone,

Returns a new Node while filtering the tab type. If this Node remains empty, it will change to Node::Empty.

Source

pub fn retain_tabs<F>(&mut self, predicate: F)
where F: FnMut(&mut Tab) -> bool,

Removes all tabs for which predicate returns false. If this Node remains empty, it will change to Node::Empty.

Trait Implementations§

Source§

impl<Tab: Clone> Clone for Node<Tab>

Source§

fn clone(&self) -> Node<Tab>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<Tab: Debug> Debug for Node<Tab>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<Tab> Freeze for Node<Tab>

§

impl<Tab> RefUnwindSafe for Node<Tab>
where Tab: RefUnwindSafe,

§

impl<Tab> Send for Node<Tab>
where Tab: Send,

§

impl<Tab> Sync for Node<Tab>
where Tab: Sync,

§

impl<Tab> Unpin for Node<Tab>
where Tab: Unpin,

§

impl<Tab> UnwindSafe for Node<Tab>
where Tab: UnwindSafe,

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

impl<T> SerializableAny for T
where T: 'static + Any + Clone + for<'a> Send + Sync,