pub struct DockState<Tab> {
    pub translations: Translations,
    /* private fields */
}
Expand description

The heart of egui_dock.

This structure holds a collection of surfaces, each of which stores a tree in which tabs are arranged.

Indexing it with a SurfaceIndex will yield a Tree which then contains nodes and tabs.

DockState is generic, so you can use any type of data to represent a tab.

Fields§

§translations: Translations

Contains translations of text shown in DockArea.

Implementations§

source§

impl<Tab> DockState<Tab>

source

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

Create a new tree with given tabs at the main surface’s root node.

source

pub fn with_translations(self, translations: Translations) -> Self

Sets translations of text later displayed in DockArea.

source

pub fn main_surface_mut(&mut self) -> &mut Tree<Tab>

Get a mutable borrow to the tree at the main surface.

source

pub fn main_surface(&self) -> &Tree<Tab>

Get an immutable borrow to the tree at the main surface.

source

pub fn get_window_state_mut( &mut self, surface: SurfaceIndex ) -> Option<&mut WindowState>

Get the WindowState which corresponds to a SurfaceIndex.

Returns None if the surface is Empty, Main, or doesn’t exist.

This can be used to modify properties of a window, e.g. size and position.

Examples
let mut dock_state = DockState::new(vec![]);
let mut surface_index = dock_state.add_window(vec!["Window Tab".to_string()]);
let window_state = dock_state.get_window_state_mut(surface_index).unwrap();

window_state.set_position(Pos2::ZERO);
window_state.set_size(Vec2::splat(100.0));
source

pub fn get_window_state( &mut self, surface: SurfaceIndex ) -> Option<&WindowState>

Get the WindowState which corresponds to a SurfaceIndex.

Returns None if the surface is an Empty, Main, or doesn’t exist.

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 no node is in focus.

source

pub fn get_surface_mut( &mut self, surface: SurfaceIndex ) -> Option<&mut Surface<Tab>>

Get a mutable borrow to the raw surface from a surface index.

source

pub fn get_surface(&self, surface: SurfaceIndex) -> Option<&Surface<Tab>>

Get an immutable borrow to the raw surface from a surface index.

source

pub fn is_surface_valid(&self, surface_index: SurfaceIndex) -> bool

Returns true if the specified surface exists and isn’t Empty.

source

pub fn remove_surface( &mut self, surface_index: SurfaceIndex ) -> Option<Surface<Tab>>

Remove a surface based on its SurfaceIndex

Returns the removed surface or None if it didn’t exist.

Panics

Panics if you try to remove the main surface: SurfaceIndex::main().

source

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

Sets which is the active tab within a specific node on a given surface.

source

pub fn set_focused_node_and_surface( &mut self, (surface_index, node_index): (SurfaceIndex, NodeIndex) )

Sets the currently focused leaf to node_index if the node at node_index is a leaf.

source

pub fn move_tab( &mut self, (src_surface, src_node, src_tab): (SurfaceIndex, NodeIndex, TabIndex), dst_tab: impl Into<TabDestination> )

Moves a tab from a node to another node. You need to specify with TabDestination how the tab should be moved.

source

pub fn detach_tab( &mut self, (src_surface, src_node, src_tab): (SurfaceIndex, NodeIndex, TabIndex), window_rect: Rect ) -> SurfaceIndex

Takes a tab out of its current surface and puts it in a new window. Returns the surface index of the new window.

source

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

Currently focused leaf.

source

pub fn remove_tab( &mut self, (surface_index, node_index, tab_index): (SurfaceIndex, NodeIndex, TabIndex) ) -> Option<Tab>

Remove a tab at the specified surface, node, and tab index. This method will yield the removed tab, or None if it doesn’t exist.

source

pub fn split( &mut self, (surface, parent): (SurfaceIndex, 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 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 add_window(&mut self, tabs: Vec<Tab>) -> SurfaceIndex

Adds a window with its own list of tabs.

Returns the SurfaceIndex of the new window, which will remain constant through the windows lifetime.

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 push_to_first_leaf(&mut self, tab: Tab)

Push a tab to the first available Leaf or create a new leaf if an Empty node is encountered.

source

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

👎Deprecated: Use iter_main_surface_nodes or iter_nodes instead

Returns an Iterator of the underlying collection of nodes on the main surface.

source

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

Returns an Iterator of the underlying collection of nodes on the main surface.

source

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

Returns an Iterator of all underlying nodes in the dock state and all subsequent trees.

source§

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

source

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

Find the given tab.

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

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

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

See also: find_main_surface_tab

source

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

Find the given tab on the main surface.

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

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 DockState<Tab>

source§

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

source§

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

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

impl<Tab> Index<SurfaceIndex> for DockState<Tab>

§

type Output = Tree<Tab>

The returned type after indexing.
source§

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

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

impl<Tab> IndexMut<SurfaceIndex> for DockState<Tab>

source§

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

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

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

impl<Tab> UnwindSafe for DockState<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,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 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.
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.
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 + for<'a> Send + Sync,