Struct egui_dock::dock_state::DockState
source · 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>
impl<Tab> DockState<Tab>
sourcepub fn new(tabs: Vec<Tab>) -> Self
pub fn new(tabs: Vec<Tab>) -> Self
Create a new tree with given tabs at the main surface’s root node.
sourcepub fn with_translations(self, translations: Translations) -> Self
pub fn with_translations(self, translations: Translations) -> Self
Sets translations of text later displayed in DockArea
.
sourcepub fn main_surface(&self) -> &Tree<Tab>
pub fn main_surface(&self) -> &Tree<Tab>
Get an immutable borrow to the tree at the main surface.
sourcepub fn main_surface_mut(&mut self) -> &mut Tree<Tab>
pub fn main_surface_mut(&mut self) -> &mut Tree<Tab>
Get a mutable borrow to the tree at the main surface.
sourcepub fn get_window_state_mut(
&mut self,
surface: SurfaceIndex
) -> Option<&mut WindowState>
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));
sourcepub fn get_window_state(
&mut self,
surface: SurfaceIndex
) -> Option<&WindowState>
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.
sourcepub fn find_active_focused(&mut self) -> Option<(Rect, &mut Tab)>
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.
sourcepub fn get_surface_mut(
&mut self,
surface: SurfaceIndex
) -> Option<&mut Surface<Tab>>
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.
sourcepub fn get_surface(&self, surface: SurfaceIndex) -> Option<&Surface<Tab>>
pub fn get_surface(&self, surface: SurfaceIndex) -> Option<&Surface<Tab>>
Get an immutable borrow to the raw surface from a surface index.
sourcepub fn is_surface_valid(&self, surface_index: SurfaceIndex) -> bool
pub fn is_surface_valid(&self, surface_index: SurfaceIndex) -> bool
Returns true if the specified surface exists and isn’t Empty
.
sourcepub fn remove_surface(
&mut self,
surface_index: SurfaceIndex
) -> Option<Surface<Tab>>
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()
.
sourcepub fn set_active_tab(
&mut self,
(surface_index, node_index, tab_index): (SurfaceIndex, NodeIndex, TabIndex)
)
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.
sourcepub fn set_focused_node_and_surface(
&mut self,
(surface_index, node_index): (SurfaceIndex, NodeIndex)
)
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.
sourcepub fn move_tab(
&mut self,
(src_surface, src_node, src_tab): (SurfaceIndex, NodeIndex, TabIndex),
dst_tab: impl Into<TabDestination>
)
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.
sourcepub fn detach_tab(
&mut self,
(src_surface, src_node, src_tab): (SurfaceIndex, NodeIndex, TabIndex),
window_rect: Rect
) -> SurfaceIndex
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.
sourcepub fn focused_leaf(&self) -> Option<(SurfaceIndex, NodeIndex)>
pub fn focused_leaf(&self) -> Option<(SurfaceIndex, NodeIndex)>
Currently focused leaf.
sourcepub fn remove_tab(
&mut self,
(surface_index, node_index, tab_index): (SurfaceIndex, NodeIndex, TabIndex)
) -> Option<Tab>
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.
sourcepub fn split(
&mut self,
(surface, parent): (SurfaceIndex, NodeIndex),
split: Split,
fraction: f32,
new: Node<Tab>
) -> [NodeIndex; 2]
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.
sourcepub fn add_window(&mut self, tabs: Vec<Tab>) -> SurfaceIndex
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.
sourcepub fn push_to_focused_leaf(&mut self, tab: Tab)
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.
sourcepub fn push_to_first_leaf(&mut self, tab: Tab)
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.
sourcepub fn surfaces_count(&self) -> usize
pub fn surfaces_count(&self) -> usize
Returns the current number of surfaces.
sourcepub fn iter_surfaces(&self) -> impl Iterator<Item = &Surface<Tab>>
pub fn iter_surfaces(&self) -> impl Iterator<Item = &Surface<Tab>>
Returns an Iterator
over all surfaces.
sourcepub fn iter_surfaces_mut(&mut self) -> impl Iterator<Item = &mut Surface<Tab>>
pub fn iter_surfaces_mut(&mut self) -> impl Iterator<Item = &mut Surface<Tab>>
Returns a mutable Iterator
over all surfaces.
sourcepub fn iter_all_nodes(&self) -> impl Iterator<Item = (SurfaceIndex, &Node<Tab>)>
pub fn iter_all_nodes(&self) -> impl Iterator<Item = (SurfaceIndex, &Node<Tab>)>
Returns an Iterator
of all underlying nodes in the dock state,
and the indices of containing surfaces.
sourcepub fn iter_all_nodes_mut(
&mut self
) -> impl Iterator<Item = (SurfaceIndex, &mut Node<Tab>)>
pub fn iter_all_nodes_mut( &mut self ) -> impl Iterator<Item = (SurfaceIndex, &mut Node<Tab>)>
Returns a mutable Iterator
of all underlying nodes in the dock state,
and the indices of containing surfaces.
sourcepub fn iter_all_tabs(
&self
) -> impl Iterator<Item = ((SurfaceIndex, NodeIndex), &Tab)>
pub fn iter_all_tabs( &self ) -> impl Iterator<Item = ((SurfaceIndex, NodeIndex), &Tab)>
Returns an Iterator
of all tabs in the dock state,
and the indices of containing surfaces and nodes.
sourcepub fn iter_all_tabs_mut(
&mut self
) -> impl Iterator<Item = ((SurfaceIndex, NodeIndex), &mut Tab)>
pub fn iter_all_tabs_mut( &mut self ) -> impl Iterator<Item = ((SurfaceIndex, NodeIndex), &mut Tab)>
Returns a mutable Iterator
of all tabs in the dock state,
and the indices of containing surfaces and nodes.
sourcepub fn iter_main_surface_nodes(&self) -> impl Iterator<Item = &Node<Tab>>
👎Deprecated: Use dock_state.main_surface().iter()
instead
pub fn iter_main_surface_nodes(&self) -> impl Iterator<Item = &Node<Tab>>
dock_state.main_surface().iter()
insteadReturns an Iterator
of the underlying collection of nodes on the main surface.
sourcepub fn iter_main_surface_nodes_mut(
&mut self
) -> impl Iterator<Item = &mut Node<Tab>>
👎Deprecated: Use dock_state.main_surface_mut().iter_mut()
instead
pub fn iter_main_surface_nodes_mut( &mut self ) -> impl Iterator<Item = &mut Node<Tab>>
dock_state.main_surface_mut().iter_mut()
insteadReturns a mutable Iterator
of the underlying collection of nodes on the main surface.
sourcepub fn iter_nodes(&self) -> impl Iterator<Item = &Node<Tab>>
👎Deprecated: Use iter_all_nodes
instead
pub fn iter_nodes(&self) -> impl Iterator<Item = &Node<Tab>>
iter_all_nodes
insteadReturns an Iterator
of all underlying nodes in the dock state and all subsequent trees.
source§impl<Tab> DockState<Tab>where
Tab: PartialEq,
impl<Tab> DockState<Tab>where
Tab: PartialEq,
sourcepub fn find_tab(
&self,
needle_tab: &Tab
) -> Option<(SurfaceIndex, NodeIndex, TabIndex)>
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
sourcepub fn find_main_surface_tab(
&self,
needle_tab: &Tab
) -> Option<(NodeIndex, TabIndex)>
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.