Struct egui_dock::Tree

source ·
pub struct Tree<Tab> { /* private fields */ }
Expand description

Binary tree representing the relationships between Nodes.

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>

source

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

Creates a new Tree with given Vec of Tabs in its root node.

source

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.

source

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.

source

pub fn len(&self) -> usize

Returns the number of nodes in the Tree.

source

pub fn is_empty(&self) -> bool

Returns true if the number of nodes in the tree is 0, false otherwise.

source

pub fn iter(&self) -> Iter<'_, Node<Tab>>

Returns Iter of the underlying collection of nodes.

source

pub fn iter_mut(&mut self) -> IterMut<'_, Node<Tab>>

Returns IterMut of the underlying collection of nodes.

source

pub fn tabs(&self) -> TabIter<'_, Tab>

Returns an iterator over all tabs in arbitrary order

source

pub fn num_tabs(&self) -> usize

Number of tabs

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

pub fn remove_empty_leaf(&mut self)

Removes the first node containing 0 tabs.

source

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.

source

pub fn focused_leaf(&self) -> Option<NodeIndex>

Currently focused leaf.

source

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.

source

pub fn set_active_tab(&mut self, node_index: NodeIndex, tab_index: TabIndex)

Sets which is the active tab within a specific node.

source

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.

source

pub fn remove_tab(&mut self, remove: (NodeIndex, TabIndex)) -> Option<Tab>

Removes the tab at the given (NodeIndex, TabIndex) pair.

If the node is emptied after the tab is removed, the node will also be removed.

Returns the removed tab if it exists, or None otherwise.

source§

impl<Tab> Tree<Tab>where Tab: PartialEq,

source

pub fn find_tab(&self, needle_tab: &Tab) -> Option<(NodeIndex, TabIndex)>

Find the given tab.

Returns which node the tab is in, and where in that node the tab is in.

The returned NodeIndex will always point to a Node::Leaf.

In case there are several hits, only the first is returned.

Trait Implementations§

source§

impl<Tab: Clone> Clone for Tree<Tab>

source§

fn clone(&self) -> Tree<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 for Tree<Tab>

source§

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

Formats the value using the given formatter. Read more
source§

impl<Tab> Default for Tree<Tab>

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<Tab> Index<NodeIndex> for Tree<Tab>

§

type Output = Node<Tab>

The returned type after indexing.
source§

fn index(&self, index: NodeIndex) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
source§

impl<Tab> IndexMut<NodeIndex> for Tree<Tab>

source§

fn index_mut(&mut self, index: NodeIndex) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · 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 Twhere 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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

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