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

Fields

§rect: Rect

The full rectangle - tab bar plus tab body.

§viewport: Rect

The tab body rectangle.

§tabs: Vec<Tab>

All the tabs in this node.

§active: TabIndex

The opened tab.

§scroll: f32

Scroll amount of the tab bar.

Contains the actual tabs.

§

Vertical

Fields

§rect: Rect

The rectangle in which all children of this node are drawn.

§fraction: f32

The fraction taken by the top child of this node.

Parent node in the vertical orientation.

§

Horizontal

Fields

§rect: Rect

The rectangle in which all children of this node are drawn.

§fraction: f32

The fraction taken by the left child of this node.

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

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 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 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: Clone + 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: Clone + 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 copy 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> 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> 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,

§

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

§

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

§

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,