### Get Tabs from Node (Example) Source: https://docs.rs/egui_dock/latest/egui_dock/dock_state/tree/node/enum.Node.html Demonstrates how to check if a specific tab exists within the root node's leaf. ```rust 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)); ``` -------------------------------- ### Example: Accessing the root node Source: https://docs.rs/egui_dock/latest/src/egui_dock/dock_state/tree/mod.rs.html Shows how to get an immutable reference to the root node of a DockState and assert its contents. This is useful for verifying the initial state or reading information from the root. ```rust # use egui_dock::DockState; let mut dock_state = DockState::new(vec!["single tab"]); let root_node = dock_state.main_surface().root_node().unwrap(); assert_eq!(root_node.tabs(), Some(["single tab"].as_slice())); ``` -------------------------------- ### Basic egui_dock Usage Source: https://docs.rs/egui_dock/latest/egui_dock/index.html Demonstrates the fundamental setup for egui_dock, including defining a tab type, implementing the TabViewer trait, and integrating DockArea with a DockState. ```rust use egui_dock::{DockArea, DockState, NodeIndex, Style, TabViewer}; use egui::{Ui, WidgetText}; // First, let's pick a type that we'll use to attach some data to each tab. // It can be any type. type Tab = String; // To define the contents and properties of individual tabs, we implement the `TabViewer` // trait. Only three things are mandatory: the `Tab` associated type, and the `ui` and // `title` methods. There are more methods in `TabViewer` which you can also override. struct MyTabViewer; impl TabViewer for MyTabViewer { // This associated type is used to attach some data to each tab. type Tab = Tab; // Returns the current `tab`'s title. fn title(&mut self, tab: &mut Self::Tab) -> WidgetText { tab.as_str().into() } // Defines the contents of a given `tab`. fn ui(&mut self, ui: &mut Ui, tab: &mut Self::Tab) { ui.label(format!("Content of {tab}")); } } // Here is a simple example of how you can manage a `DockState` of your application. struct MyTabs { dock_state: DockState } impl MyTabs { pub fn new() -> Self { // Create a `DockState` with an initial tab "tab1" in the main `Surface`'s root node. let tabs = ["tab1", "tab2", "tab3"].map(str::to_string).into_iter().collect(); let dock_state = DockState::new(tabs); Self { dock_state } } fn ui(&mut self, ui: &mut Ui) { // Here we just display the `DockState` using a `DockArea`. // This is where egui handles rendering and all the integrations. // // We can specify a custom `Style` for the `DockArea`, or just inherit // all of it from egui. DockArea::new(&mut self.dock_state) .style(Style::from_egui(ui.style().as_ref())) .show_inside(ui, &mut MyTabViewer); } } ``` -------------------------------- ### Basic egui_dock Usage with TabViewer Source: https://docs.rs/egui_dock/latest/egui_dock Demonstrates the fundamental setup for egui_dock, including defining a tab type, implementing the TabViewer trait, and integrating DockArea with a DockState. ```rust use egui_dock::{DockArea, DockState, Style, TabViewer}; use egui::{Ui, WidgetText}; // First, let's pick a type that we'll use to attach some data to each tab. // It can be any type. type Tab = String; // To define the contents and properties of individual tabs, we implement the `TabViewer` // trait. Only three things are mandatory: the `Tab` associated type, and the `ui` and // `title` methods. There are more methods in `TabViewer` which you can also override. struct MyTabViewer; impl TabViewer for MyTabViewer { // This associated type is used to attach some data to each tab. type Tab = Tab; // Returns the current `tab`'s title. fn title(&mut self, tab: &mut Self::Tab) -> WidgetText { tab.as_str().into() } // Defines the contents of a given `tab`. fn ui(&mut self, ui: &mut Ui, tab: &mut Self::Tab) { ui.label(format!("Content of {tab}")); } } // Here is a simple example of how you can manage a `DockState` of your application. struct MyTabs { dock_state: DockState } impl MyTabs { pub fn new() -> Self { // Create a `DockState` with an initial tab "tab1" in the main `Surface`'s root node. let tabs = ["tab1", "tab2", "tab3"].map(str::to_string).into_iter().collect(); let dock_state = DockState::new(tabs); Self { dock_state } } fn ui(&mut self, ui: &mut Ui) { // Here we just display the `DockState` using a `DockArea`. // This is where egui handles rendering and all the integrations. // // We can specify a custom `Style` for the `DockArea`, or just inherit // all of it from egui. DockArea::new(&mut self.dock_state) .style(Style::from_egui(ui.style().as_ref())) .show_inside(ui, &mut MyTabViewer); } } ``` -------------------------------- ### DockArea::new Source: https://docs.rs/egui_dock/latest/egui_dock/widgets/dock_area/struct.DockArea.html Creates a new DockArea from a mutable reference to a DockState. This is the starting point for configuring and displaying a docking layout. ```APIDOC ## DockArea::new ### Description Creates a new `DockArea` from the provided `DockState`. ### Signature ```rust pub fn new(tree: &'tree mut DockState) -> DockArea<'tree, Tab> ``` ``` -------------------------------- ### Split Tree from Root Node Source: https://docs.rs/egui_dock/latest/egui_dock/dock_state/tree/node_index/struct.NodeIndex.html Demonstrates splitting the main surface of a DockState. This example shows how to use NodeIndex::root() to target the main node for splitting. ```rust let mut dock_state = DockState::new(vec!["tab 1", "tab 2"]); let _ = dock_state.main_surface_mut().split_left(NodeIndex::root(), 0.5, vec!["tab 3", "tab 4"]); ``` -------------------------------- ### Append Tab to Node (Example) Source: https://docs.rs/egui_dock/latest/egui_dock/dock_state/tree/node/enum.Node.html Demonstrates adding a new tab to an existing leaf node and verifying the updated tab count. ```rust 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); ``` -------------------------------- ### Create a new DockArea Source: https://docs.rs/egui_dock/latest/egui_dock/widgets/dock_area/struct.DockArea.html Instantiate a DockArea by providing a mutable reference to a DockState. This is the starting point for configuring and displaying the docking area. ```rust DockArea::new(tree: &'tree mut DockState) -> DockArea<'tree, Tab> ``` -------------------------------- ### Example: Modifying the root node Source: https://docs.rs/egui_dock/latest/src/egui_dock/dock_state/tree/mod.rs.html Demonstrates how to obtain a mutable reference to the root node and add a new tab to it. This allows for dynamic modification of the dock state's root. ```rust # use egui_dock::{DockState, LeafNode}; let mut dock_state = DockState::new(vec!["single tab"]); let root_node = dock_state.main_surface_mut().root_node_mut().unwrap(); let root_as_leaf = root_node.get_leaf_mut().unwrap(); root_as_leaf.tabs.push("partner tab"); assert_eq!(root_node.tabs(), Some(["single tab", "partner tab"].as_slice())); ``` -------------------------------- ### Customize egui-dock Translations Source: https://docs.rs/egui_dock/latest/src/egui_dock/lib.rs.html Provides an example of how to define custom translations for UI elements within egui-dock, such as tab context menus and leaf node tooltips, for different languages. ```rust # use egui_dock::{DockState, TabContextMenuTranslations, Translations, LeafTranslations}; # type Tab = (); let translations_pl = Translations { tab_context_menu: TabContextMenuTranslations { close_button: "Zamknij zakładkę".to_string(), eject_button: "Przenieś zakładkę do nowego okna".to_string(), }, leaf: LeafTranslations { close_button_disabled_tooltip: "Ten węzeł zawiera niezamykalne zakładki.".to_string(), close_all_button: "Zamknij okno".to_string(), close_all_button_menu_hint: "Kliknij prawym przyciskiem myszy, aby zamknąć to okno.".to_string(), close_all_button_modifier_hint: "Naciśnij klawisze modyfikujące (domyślnie Shift), aby zamknąć to okno.".to_string(), close_all_button_modifier_menu_hint: "Naciśnij klawisze modyfikujące (domyślnie Shift) lub kliknij prawym przyciskiem myszy, aby zamknąć to okno.".to_string(), close_all_button_disabled_tooltip: "To okno zawiera zakładki, których nie można zamknąć.".to_string(), minimize_button: "Zminimalizuj okno".to_string(), minimize_button_menu_hint: "Kliknij prawym przyciskiem myszy, aby zminimalizować to okno.".to_string(), minimize_button_modifier_hint: "Naciśnij klawisze modyfikujące (domyślnie Shift), aby zminimalizować to okno.".to_string(), }, }; ``` -------------------------------- ### Initialize and Customize egui_dock Style Source: https://docs.rs/egui_dock/latest/egui_dock/style/struct.Style.html Demonstrates how to initialize a Style by inheriting from egui's default style and then customizing specific fields before applying it to a DockArea. ```rust // Inherit the look and feel from egui. let mut style = Style::from_egui(ui.style()); // Modify a few fields. style.overlay.overlay_type = OverlayType::HighlightedAreas; style.buttons.add_tab_align = TabAddAlign::Left; // Use the style with the `DockArea`. DockArea::new(&mut dock_state) .style(style) .show_inside(ui, &mut MyTabViewer); ``` -------------------------------- ### Manage DockState Windows Source: https://docs.rs/egui_dock/latest/src/egui_dock/lib.rs.html Demonstrates how to add a new window surface with a tab and then access and modify its position and size. ```rust # use egui_dock::DockState; # use egui::{Pos2, Vec2}; # let mut dock_state = DockState::new(vec![]); // Create a new window `Surface` with one tab inside it. let mut surface_index = dock_state.add_window(vec!["Window Tab".to_string()]); // Access the window state by its surface index and then move and resize it. 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)); ``` -------------------------------- ### NodeIndex Root Node Access Source: https://docs.rs/egui_dock/latest/src/egui_dock/dock_state/tree/node_index.rs.html Provides a constant method to get the index of the root node, which is always 0. This is useful for operations starting from the top of the tree. ```rust impl NodeIndex { /// Returns the index of the root node. /// /// In the context of a [`Tree`](crate::Tree), this will be the node that contains all other nodes. /// /// # Examples /// /// Splitting the current tree in two. /// ```rust /// # use egui_dock::{DockState, NodeIndex}; /// let mut dock_state = DockState::new(vec!["tab 1", "tab 2"]); /// let _ = dock_state.main_surface_mut().split_left(NodeIndex::root(), 0.5, vec!["tab 3", "tab 4"]); /// ``` #[inline(always)] pub const fn root() -> Self { Self(0) } // ... other methods ``` -------------------------------- ### Handling File Metadata with `and_then` Source: https://docs.rs/egui_dock/latest/egui_dock/dock_state/type.Result.html Shows how to use `and_then` to chain operations that might fail, such as getting file metadata and then its modification time. This example highlights error propagation. ```rust use std::{io::ErrorKind, path::Path}; // Note: on Windows "/" maps to "C:\\" let root_modified_time = Path::new("/").metadata().and_then(|md| md.modified()); assert!(root_modified_time.is_ok()); let should_fail = Path::new("/bad/path").metadata().and_then(|md| md.modified()); assert!(should_fail.is_err()); assert_eq!(should_fail.unwrap_err().kind(), ErrorKind::NotFound); ``` -------------------------------- ### Managing egui_dock Surfaces Programmatically Source: https://docs.rs/egui_dock/latest/egui_dock/index.html Demonstrates programmatic control over egui_dock surfaces, specifically creating a new window surface with a tab and then manipulating its position and size. ```rust // Create a new window `Surface` with one tab inside it. let mut surface_index = dock_state.add_window(vec!["Window Tab".to_string()]); // Access the window state by its surface index and then move and resize it. 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)); ``` -------------------------------- ### Get immutable slice of tabs from a Leaf node Source: https://docs.rs/egui_dock/latest/src/egui_dock/dock_state/tree/node/mod.rs.html Use this method to get a read-only view of tabs within a Leaf node. Returns None if the node is not a Leaf. ```rust /// Provides an immutable slice of the tabs inside this node. /// /// Returns [`None`] if the node is not a [`Leaf`](Node::Leaf). /// /// # Examples /// /// ```rust /// # use egui_dock::{DockState, NodeIndex}; /// 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)); /// ``` #[inline] pub fn tabs(&self) -> Option<&[Tab]> { match self { Node::Leaf(leaf) => Some(leaf.tabs()), _ => None, } } ``` -------------------------------- ### Example: Counting and manipulating tabs Source: https://docs.rs/egui_dock/latest/src/egui_dock/dock_state/tree/mod.rs.html Demonstrates how to count the total number of tabs in a DockState, split panes to add new tabs, and remove leaf nodes to reduce the tab count. ```rust # use egui_dock::{DockState, NodeIndex, TabIndex}; let mut dock_state = DockState::new(vec!["node 1", "node 2", "node 3"]); assert_eq!(dock_state.main_surface().num_tabs(), 3); let [a, b] = dock_state.main_surface_mut().split_left(NodeIndex::root(), 0.5, vec!["tab 4", "tab 5"]); assert_eq!(dock_state.main_surface().num_tabs(), 5); dock_state.main_surface_mut().remove_leaf(a); assert_eq!(dock_state.main_surface().num_tabs(), 2); ``` -------------------------------- ### Get mutable slice of tabs from a Leaf node Source: https://docs.rs/egui_dock/latest/src/egui_dock/dock_state/tree/node/mod.rs.html Use this method to get a mutable view of tabs within a Leaf node, allowing modifications. Returns None if the node is not a Leaf. ```rust /// Provides an mutable slice of the tabs inside this node. /// /// Returns [`None`] if the node is not a [`Leaf`](Node::Leaf). /// /// # Examples /// /// Modifying tabs inside a node: /// ```rust /// # use egui_dock::{DockState, NodeIndex}; /// 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]); /// ``` #[inline] pub fn tabs_mut(&mut self) -> Option<&mut [Tab]> { match self { Node::Leaf(leaf) => Some(leaf.tabs_mut()), _ => None, } } ``` -------------------------------- ### type_id Source: https://docs.rs/egui_dock/latest/egui_dock/dock_state/tree/node/enum.Node.html Gets the TypeId of the Node. ```APIDOC ## fn type_id(&self) -> TypeId ### Description Gets the `TypeId` of `self`. ``` -------------------------------- ### Basic egui_dock Usage with TabViewer Source: https://docs.rs/egui_dock/latest/src/egui_dock/lib.rs.html Demonstrates the fundamental setup for egui_dock, including defining a custom tab type, implementing the TabViewer trait for tab content and titles, and integrating DockState and DockArea into an egui application. ```rust use egui_dock::{DockArea, DockState, NodeIndex, Style, TabViewer}; use egui::{Ui, WidgetText}; // First, let's pick a type that we'll use to attach some data to each tab. // It can be any type. type Tab = String; // To define the contents and properties of individual tabs, we implement the `TabViewer` // trait. Only three things are mandatory: the `Tab` associated type, and the `ui` and // `title` methods. There are more methods in `TabViewer` which you can also override. struct MyTabViewer; impl TabViewer for MyTabViewer { // This associated type is used to attach some data to each tab. type Tab = Tab; // Returns the current `tab`'s title. fn title(&mut self, tab: &mut Self::Tab) -> WidgetText { tab.as_str().into() } // Defines the contents of a given `tab`. fn ui(&mut self, ui: &mut Ui, tab: &mut Self::Tab) { ui.label(format!("Content of {tab}")); } } // Here is a simple example of how you can manage a `DockState` of your application. struct MyTabs { dock_state: DockState } impl MyTabs { pub fn new() -> Self { // Create a `DockState` with an initial tab "tab1" in the main `Surface`'s root node. let tabs = ["tab1", "tab2", "tab3"].map(str::to_string).into_iter().collect(); let dock_state = DockState::new(tabs); Self { dock_state } } fn ui(&mut self, ui: &mut Ui) { // Here we just display the `DockState` using a `DockArea`. // This is where egui handles rendering and all the integrations. // // We can specify a custom `Style` for the `DockArea`, or just inherit // all of it from egui. DockArea::new(&mut self.dock_state) .style(Style::from_egui(ui.style().as_ref())) .show_inside(ui, &mut MyTabViewer); } } # let mut my_tabs = MyTabs::new(); # egui::__run_test_ctx(|ctx| { # #[allow(deprecated)] # egui::CentralPanel::default().show(ctx, |ui| my_tabs.ui(ui)); # }); ``` -------------------------------- ### DockState::new Source: https://docs.rs/egui_dock/latest/src/egui_dock/dock_state/mod.rs.html Creates a new DockState with a single main surface initialized with the provided tabs. ```APIDOC ## DockState::new ### Description Create a new tree with given tabs at the main surface's root node. ### Signature ```rust pub fn new(tabs: Vec) -> Self ``` ### Parameters * `tabs` - A vector of `Tab` items to initialize the main surface with. ``` -------------------------------- ### SplitNode::rect Source: https://docs.rs/egui_dock/latest/src/egui_dock/dock_state/tree/node/split.rs.html Gets the bounding rectangle of the SplitNode. ```APIDOC ## SplitNode::rect ### Description Retrieves the current bounding rectangle area that this ``SplitNode`` occupies. ### Signature ```rust pub fn rect(&self) -> Rect ``` ### Returns * `Rect` - The bounding rectangle of the split node. ``` -------------------------------- ### tabs_count Source: https://docs.rs/egui_dock/latest/egui_dock/dock_state/tree/node/enum.Node.html Gets the number of tabs currently in the node. ```APIDOC ## pub fn tabs_count(&self) -> usize ### Description Gets the number of tabs in the node. ``` -------------------------------- ### Initialize DockState with Tabs Source: https://docs.rs/egui_dock/latest/src/egui_dock/dock_state/mod.rs.html Creates a new DockState with a single main surface initialized with the provided tabs. Use this to set up the initial layout of your dockable areas. ```rust pub fn new(tabs: Vec) -> Self { Self { surfaces: vec![Surface::Main(Tree::new(tabs))], focused_surface: None, translations: Translations::english(), } } ``` -------------------------------- ### get_surface Source: https://docs.rs/egui_dock/latest/src/egui_dock/dock_state/mod.rs.html Gets an immutable reference to the raw Surface from a SurfaceIndex. ```APIDOC ## get_surface ### Description Get an immutable borrow to the raw surface from a surface index. ### Signature ```rust #[inline] pub fn get_surface(&self, surface: SurfaceIndex) -> Option<&Surface> ``` ### Parameters - **surface** (`SurfaceIndex`): The index of the surface to retrieve. ### Returns - `Option<&Surface>`: An immutable reference to the `Surface` if it exists, otherwise `None`. ``` -------------------------------- ### get_surface_mut Source: https://docs.rs/egui_dock/latest/src/egui_dock/dock_state/mod.rs.html Gets a mutable reference to the raw Surface from a SurfaceIndex. ```APIDOC ## get_surface_mut ### Description Get a mutable borrow to the raw surface from a surface index. ### Signature ```rust #[inline] pub fn get_surface_mut(&mut self, surface: SurfaceIndex) -> Option<&mut Surface> ``` ### Parameters - **surface** (`SurfaceIndex`): The index of the surface to retrieve. ### Returns - `Option<&mut Surface>`: A mutable reference to the `Surface` if it exists, otherwise `None`. ``` -------------------------------- ### DockState::new Source: https://docs.rs/egui_dock/latest/egui_dock/dock_state/struct.DockState.html Creates a new DockState with a given vector of tabs, initializing the main surface's root node. ```APIDOC ## DockState::new ### Description Creates a new tree with given tabs at the main surface’s root node. ### Signature ```rust pub fn new(tabs: Vec) -> Self ``` ``` -------------------------------- ### node_tree_mut Source: https://docs.rs/egui_dock/latest/egui_dock/dock_state/surface/enum.Surface.html Gets mutable access to the node tree of this surface. ```APIDOC /// Get mutable access to the node tree of this surface. pub fn node_tree_mut(&mut self) -> Option<&mut Tree> ``` -------------------------------- ### Show Root Surface Inside Source: https://docs.rs/egui_dock/latest/src/egui_dock/widgets/dock_area/show/main_surface.rs.html Renders the main surface of the dock area. If the main surface is empty, it allocates space and records hover data. Otherwise, it calls `render_nodes` to display the content. ```rust use egui::{Sense, Ui}; use crate::{ dock_area::{ drag_and_drop::{HoverData, TreeComponent}, state::State, }, DockArea, SurfaceIndex, TabViewer, }; impl DockArea<'_, Tab> { pub(super) fn show_root_surface_inside( &mut self, ui: &mut Ui, tab_viewer: &mut impl TabViewer, state: &mut State, ) { let surf_index = SurfaceIndex::main(); if self.dock_state.main_surface().is_empty() { let rect = ui.available_rect_before_wrap(); let response = ui.allocate_rect(rect, Sense::hover()); if response.contains_pointer() { ui.memory_mut(|mem| { mem.data.insert_temp( self.id.with("hover_data"), Some(HoverData { rect, dst: TreeComponent::Surface(surf_index), tab: None, }), ); }); } return; } self.render_nodes(ui, tab_viewer, state, surf_index, None); } } ``` -------------------------------- ### Create egui::Window constructor Source: https://docs.rs/egui_dock/latest/src/egui_dock/dock_state/window_state.rs.html Constructs an `egui::Window` with the current state, applying position, size, and expanded height if set. Resets the 'new' flag after construction. This is an internal method. ```rust //the 'static in this case means that the `open` field is always `None` pub(crate) fn create_window(&mut self, id: Id, bounds: Rect) -> egui::Window<'static> { let new = self.new; let mut window_constructor = egui::Window::new("") .id(id) .constrain_to(bounds) .title_bar(false); if let Some(position) = self.next_position() { window_constructor = window_constructor.current_pos(position); } if let Some(size) = self.next_size() { window_constructor = window_constructor.fixed_size(size); } // Reset the height of the window if it is now expanded if new { if let Some(height) = self.expanded_height() { window_constructor = window_constructor.max_height(height).min_height(height); } } self.new = false; window_constructor } ``` -------------------------------- ### node_tree Source: https://docs.rs/egui_dock/latest/egui_dock/dock_state/surface/enum.Surface.html Gets immutable access to the node tree of this surface. ```APIDOC /// Get access to the node tree of this surface. pub fn node_tree(&self) -> Option<&Tree> ``` -------------------------------- ### Initialize new WindowState Source: https://docs.rs/egui_dock/latest/src/egui_dock/dock_state/window_state.rs.html Provides a constructor for creating a new WindowState, defaulting to the struct's default values. ```rust impl WindowState { /// Create a default window state. pub(crate) fn new() -> Self { Self::default() } // ... ``` -------------------------------- ### Get LeafNode Rectangle Source: https://docs.rs/egui_dock/latest/egui_dock/dock_state/tree/node/struct.LeafNode.html Retrieves the screen area occupied by the LeafNode. ```rust pub fn rect(&self) -> Rect> ``` -------------------------------- ### Customize Translations for egui_dock Source: https://docs.rs/egui_dock/latest/egui_dock Customize UI text elements like tab context menus and leaf node tooltips. This example shows how to define translations for Polish and Japanese. ```rust let translations_pl = Translations { tab_context_menu: TabContextMenuTranslations { close_button: "Zamknij zakładkę".to_string(), eject_button: "Przenieś zakładkę do nowego okna".to_string(), }, leaf: LeafTranslations { close_button_disabled_tooltip: "Ten węzeł zawiera niezamykalne zakładki.".to_string(), close_all_button: "Zamknij okno".to_string(), close_all_button_menu_hint: "Kliknij prawym przyciskiem myszy, aby zamknąć to okno.".to_string(), close_all_button_modifier_hint: "Naciśnij klawisze modyfikujące (domyślnie Shift), aby zamknąć to okno.".to_string(), close_all_button_modifier_menu_hint: "Naciśnij klawisze modyfikujące (domyślnie Shift) lub kliknij prawym przyciskiem myszy, aby zamknąć to okno.".to_string(), close_all_button_disabled_tooltip: "To okno zawiera zakładki, których nie można zamknąć.".to_string(), minimize_button: "Zminimalizuj okno".to_string(), minimize_button_menu_hint: "Kliknij prawym przyciskiem myszy, aby zminimalizować to okno.".to_string(), minimize_button_modifier_hint: "Naciśnij klawisze modyfikujące (domyślnie Shift), aby zminimalizować to okno.".to_string(), minimize_button_modifier_menu_hint: "Naciśnij klawisze modyfikujące (domyślnie Shift) lub kliknij prawym przyciskiem myszy, aby zminimalizować to okno.".to_string(), } }; let dock_state = DockState::::new(vec![]).with_translations(translations_pl); ``` ```rust let mut dock_state = DockState::::new(vec![]); dock_state.translations.tab_context_menu.close_button = "タブを閉じる".to_string(); dock_state.translations.tab_context_menu.eject_button = "タブを新しいウィンドウへ移動".to_string(); dock_state.translations.leaf.close_button_disabled_tooltip = "このノードは閉じられないタブがある".to_string(); dock_state.translations.leaf.close_all_button = "ウィンドウを閉じる".to_string(); dock_state.translations.leaf.close_all_button_menu_hint = "右クリックでこのウィンドウを閉じる".to_string(); dock_state.translations.leaf.close_all_button_modifier_hint = "修飾キー(デフォルトではShift)を押して、このウィンドウを閉じます".to_string(); dock_state.translations.leaf.close_all_button_modifier_menu_hint = "修飾キー(デフォルトではShift)を押すか、右クリックしてこのウィンドウを閉じます".to_string(); dock_state.translations.leaf.close_all_button_disabled_tooltip = "このウィンドウは閉じられないタブがある".to_string(); dock_state.translations.leaf.minimize_button = "ウィンドウを最小化する".to_string(); dock_state.translations.leaf.minimize_button_menu_hint = "右クリックでウィンドウを最小化する".to_string(); dock_state.translations.leaf.minimize_button_modifier_hint = "修飾キー(デフォルトではShift)を押すと、このウィンドウが最小化されます".to_string(); dock_state.translations.leaf.minimize_button_modifier_menu_hint = "修飾キー(デフォルトではShift)を押すか、右クリックしてこのウィンドウを最小化する".to_string(); ``` -------------------------------- ### Type ID Source: https://docs.rs/egui_dock/latest/egui_dock/widgets/dock_area/struct.DockArea.html Gets the `TypeId` of the `DockArea`. This is useful for runtime type identification. ```APIDOC ## fn type_id(&self) -> TypeId ### Description Gets the `TypeId` of `self`. ### Method `type_id` ### Parameters None ### Returns - `TypeId`: The unique identifier for the type of `self`. ``` -------------------------------- ### Inherit and Customize egui_dock Style Source: https://docs.rs/egui_dock/latest/src/egui_dock/style.rs.html Demonstrates how to inherit the default egui style and then customize specific properties like overlay type and tab add button alignment before applying it to a DockArea. ```rust use egui_dock::{DockArea, DockState, OverlayType, Style, TabAddAlign, TabViewer}; use egui::{Ui, WidgetText}; struct MyTabViewer; impl TabViewer for MyTabViewer { type Tab = (); fn title(&mut self, tab: &mut Self::Tab) -> WidgetText { WidgetText::default() } fn ui(&mut self, ui: &mut Ui, tab: &mut Self::Tab) {} } egui::__run_test_ctx(|ctx| { #[allow(deprecated)] egui::CentralPanel::default().show(ctx, |ui| { let mut dock_state = DockState::new(vec![]); // Inherit the look and feel from egui. let mut style = Style::from_egui(ui.style()); // Modify a few fields. style.overlay.overlay_type = OverlayType::HighlightedAreas; style.buttons.add_tab_align = TabAddAlign::Left; // Use the style with the `DockArea`. DockArea::new(&mut dock_state) .style(style) .show_inside(ui, &mut MyTabViewer); }); }); ``` -------------------------------- ### DockArea Configuration Methods Source: https://docs.rs/egui_dock/latest/src/egui_dock/widgets/dock_area/mod.rs.html A collection of builder methods for configuring the appearance and behavior of the `DockArea` widget. ```APIDOC ## DockArea Configuration Methods ### Description These methods allow for fine-grained control over the `DockArea`'s visual elements and interaction behaviors. They are typically chained after calling `DockArea::new()`. ### Methods #### `id(id: Id) -> Self` Sets the [`DockArea`] ID. Useful if you have more than one [`DockArea`] in your application to distinguish them. #### `style(style: Style) -> Self` Sets the look and feel of the [`DockArea`] using a provided `Style` object. #### `show_add_popup(show_add_popup: bool) -> Self` Shows or hides the add button popup. By default, it's `false`. #### `show_add_buttons(show_add_buttons: bool) -> Self` Shows or hides the tab add buttons. By default, it's `false`. #### `show_close_buttons(show_close_buttons: bool) -> Self` Shows or hides the tab close buttons. By default, it's `true`. #### `tab_context_menus(tab_context_menus: bool) -> Self` Determines whether tabs show a context menu when right-clicked. By default, it's `true`. #### `draggable_tabs(draggable_tabs: bool) -> Self` Enables or disables the dragging of tabs between nodes and reordering on the tab bar. By default, it's `true`. #### `show_tab_name_on_hover(show_tab_name_on_hover: bool) -> Self` Determines whether tabs display their names when hovered over. By default, it's `false`. #### `allowed_splits(allowed_splits: AllowedSplits) -> Self` Specifies the allowed directions for splitting nodes (left-right, top-bottom, all, or none). By default, all splits are allowed. ``` -------------------------------- ### Get the number of surfaces Source: https://docs.rs/egui_dock/latest/egui_dock/dock_state/struct.DockState.html Returns the current count of surfaces managed by the DockState. ```rust pub fn surfaces_count(&self) -> usize ``` -------------------------------- ### SurfaceIndex Conversions Source: https://docs.rs/egui_dock/latest/egui_dock/dock_state/surface_index/struct.SurfaceIndex.html Demonstrates how to convert between `usize` and `SurfaceIndex`, and how `SurfaceIndex` can be converted into a `TabDestination`. ```APIDOC ## From for SurfaceIndex ```rust fn from(index: usize) -> Self ``` Converts to this type from the input type. ## From for TabDestination ```rust fn from(value: SurfaceIndex) -> TabDestination ``` Converts to this type from the input type. ``` -------------------------------- ### Node::get_leaf_mut Source: https://docs.rs/egui_dock/latest/egui_dock/dock_state/tree/node/enum.Node.html Get mutable access to the leaf data of this node, if it contains any. ```APIDOC ## pub fn get_leaf_mut(&mut self) -> Option<&mut LeafNode> Get mutable access to the leaf data of this node, if it contains any (i.e is a leaf). ``` -------------------------------- ### Node::get_leaf Source: https://docs.rs/egui_dock/latest/egui_dock/dock_state/tree/node/enum.Node.html Get immutable access to the leaf data of this node, if it contains any. ```APIDOC ## pub fn get_leaf(&self) -> Option<&LeafNode> Get immutable access to the leaf data of this node, if it contains any (i.e is a leaf). ``` -------------------------------- ### Get SplitNode Rectangle Source: https://docs.rs/egui_dock/latest/egui_dock/dock_state/tree/node/struct.SplitNode.html Retrieves the current rectangular area occupied by this SplitNode. ```rust pub fn rect(&self) -> Rect ``` -------------------------------- ### Get Surfaces Count Source: https://docs.rs/egui_dock/latest/src/egui_dock/dock_state/mod.rs.html Returns the total number of surfaces currently managed by the DockState. ```rust pub fn surfaces_count(&self) -> usize { self.surfaces.len() } ``` -------------------------------- ### show Source: https://docs.rs/egui_dock/latest/src/egui_dock/widgets/dock_area/show/mod.rs.html Displays the `DockArea` at the top level. This method is deprecated and `show_inside` should be used instead, especially with eframe 0.34+ where `App::ui` provides direct access to `&mut Ui`. ```APIDOC ## show ### Description Shows the `DockArea` at the top level. This method is deprecated and `show_inside` should be used instead. ### Method Signature `pub fn show(self, ctx: &Context, tab_viewer: &mut impl TabViewer)` ### Parameters - `ctx`: The egui `Context` for the application. - `tab_viewer`: A mutable reference to a type implementing the `TabViewer` trait. ### Deprecated This method is deprecated. Use [`show_inside`](Self::show_inside) instead. ``` -------------------------------- ### Get LeafNode Tab Count Source: https://docs.rs/egui_dock/latest/egui_dock/dock_state/tree/node/struct.LeafNode.html Returns the number of tabs currently present in the LeafNode. ```rust pub fn len(&self) -> usize> ``` -------------------------------- ### Get Main Surface (Immutable) Source: https://docs.rs/egui_dock/latest/egui_dock/dock_state/struct.DockState.html Provides an immutable borrow to the tree structure of the main surface. ```rust pub fn main_surface(&self) -> &Tree ``` -------------------------------- ### DockArea Configuration Methods Source: https://docs.rs/egui_dock/latest/src/egui_dock/widgets/dock_area/mod.rs.html Methods for configuring the behavior of secondary buttons and window elements within the DockArea. ```APIDOC ## `show_secondary_button_hint` ### Description Sets whether tooltip hints are shown for secondary buttons on tab bars. ### Parameters - `show_secondary_button_hint` (bool) - Whether to show hints for secondary buttons. ### Returns `Self` - The modified DockArea instance. ``` ```APIDOC ## `secondary_button_modifiers` ### Description Sets the key combination used to activate secondary buttons on tab bars. ### Parameters - `secondary_button_modifiers` (Modifiers) - The modifier keys to activate secondary buttons. ### Returns `Self` - The modified DockArea instance. ``` ```APIDOC ## `secondary_button_on_modifier` ### Description Determines whether secondary buttons on tab bars are activated by the modifier key. ### Parameters - `secondary_button_on_modifier` (bool) - Whether to activate secondary buttons with a modifier key. ### Returns `Self` - The modified DockArea instance. ``` ```APIDOC ## `secondary_button_context_menu` ### Description Enables or disables the activation of secondary buttons on tab bars via a context menu by right-clicking primary buttons. ### Parameters - `secondary_button_context_menu` (bool) - Whether to use a context menu for secondary buttons. ### Returns `Self` - The modified DockArea instance. ``` ```APIDOC ## `window_bounds` ### Description Sets the bounds for any windows inside the `DockArea`. ### Parameters - `bounds` (Rect) - The rectangular bounds for windows. ### Returns `Self` - The modified DockArea instance. ``` ```APIDOC ## `show_window_close_buttons` ### Description Enables or disables the close button on windows. This method is deprecated and `show_leaf_close_buttons` should be considered instead. ### Parameters - `show_window_close_buttons` (bool) - Whether to show window close buttons. ### Returns `Self` - The modified DockArea instance. ``` ```APIDOC ## `show_window_collapse_buttons` ### Description Enables or disables the collapsing header on windows. This method is deprecated and `show_leaf_collapse_buttons` should be considered instead. ### Parameters - `show_window_collapse_buttons` (bool) - Whether to show window collapse buttons. ### Returns `Self` - The modified DockArea instance. ``` ```APIDOC ## `show_leaf_close_all_buttons` ### Description Enables or disables the close all tabs button on tab bars. ### Parameters - `show_leaf_close_all_buttons` (bool) - Whether to show the close all tabs button. ### Returns `Self` - The modified DockArea instance. ``` ```APIDOC ## `show_leaf_collapse_buttons` ### Description Enables or disables the collapse tabs button on tab bars. ### Parameters - `show_leaf_collapse_buttons` (bool) - Whether to show the collapse tabs button. ### Returns `Self` - The modified DockArea instance. ``` -------------------------------- ### Get Immutable Access to Tabs Source: https://docs.rs/egui_dock/latest/egui_dock/dock_state/tree/node/struct.LeafNode.html Provides read-only access to the list of tabs within the LeafNode. ```rust pub fn tabs(&self) -> &[Tab]> ``` -------------------------------- ### Get TypeId of Self Source: https://docs.rs/egui_dock/latest/egui_dock/dock_state/tree/enum.TabDestination.html Retrieves the unique TypeId for the current type. This is part of the Any trait implementation. ```rust fn type_id(&self) -> TypeId ``` -------------------------------- ### get_window_state Source: https://docs.rs/egui_dock/latest/src/egui_dock/dock_state/mod.rs.html Gets an immutable reference to the WindowState associated with a given SurfaceIndex. Returns None if the surface is not a window. ```APIDOC ## get_window_state ### Description Gets an immutable reference to the `WindowState` which corresponds to a `SurfaceIndex`. Returns `None` if the surface is an `Empty`, `Main`, or doesn't exist. ### Signature ```rust pub fn get_window_state(&mut self, surface: SurfaceIndex) -> Option<&WindowState> ``` ### Parameters - **surface** (`SurfaceIndex`): The index of the surface to get the window state from. ### Returns - `Option<&WindowState>`: An immutable reference to the `WindowState` if found, otherwise `None`. ``` -------------------------------- ### Split Node Right in egui_dock Source: https://docs.rs/egui_dock/latest/egui_dock/dock_state/tree/struct.Tree.html Creates two new nodes by splitting a parent node. The new node with provided tabs is placed to the right of the old node. Fraction determines the old node's area. Panics if fraction is out of range. ```rust pub fn split_right( &mut self, parent: NodeIndex, fraction: f32, tabs: Vec, ) -> [NodeIndex; 2] ``` -------------------------------- ### get_window_state_mut Source: https://docs.rs/egui_dock/latest/src/egui_dock/dock_state/mod.rs.html Gets a mutable reference to the WindowState associated with a given SurfaceIndex. Returns None if the surface is not a window. ```APIDOC ## get_window_state_mut ### Description Gets a mutable reference to the `WindowState` which corresponds to a `SurfaceIndex`. Returns `None` if the surface is an `Empty`, `Main`, or doesn't exist. ### Signature ```rust pub fn get_window_state_mut(&mut self, surface: SurfaceIndex) -> Option<&mut WindowState> ``` ### Parameters - **surface** (`SurfaceIndex`): The index of the surface to get the window state from. ### Returns - `Option<&mut WindowState>`: A mutable reference to the `WindowState` if found, otherwise `None`. ``` -------------------------------- ### Get and clear expanded height Source: https://docs.rs/egui_dock/latest/src/egui_dock/dock_state/window_state.rs.html Retrieves and clears the pending expanded height for the window. This is an internal method. ```rust #[inline(always)] pub(crate) fn expanded_height(&mut self) -> Option { self.expanded_height.take() } ``` -------------------------------- ### Initialize DockState with Tabs Source: https://docs.rs/egui_dock/latest/egui_dock/dock_state/struct.DockState.html Creates a new DockState with the provided tabs initialized at the main surface's root node. ```rust pub fn new(tabs: Vec) -> Self ``` -------------------------------- ### Get and clear next size Source: https://docs.rs/egui_dock/latest/src/egui_dock/dock_state/window_state.rs.html Retrieves and clears the pending next size for the window. This is an internal method. ```rust #[inline(always)] pub(crate) fn next_size(&mut self) -> Option { self.next_size.take() } ``` -------------------------------- ### fn from_output(output: as Try>::Output) -> Result Source: https://docs.rs/egui_dock/latest/egui_dock/dock_state/type.Result.html Constructs a `Result` from its `Output` type. ```APIDOC ## fn from_output(output: as Try>::Output) -> Result ### Description Constructs the type from its `Output` type. Read more ### Parameters * `output`: The output value to construct the Result from. ### Returns A `Result` constructed from the provided output. ``` -------------------------------- ### Get and clear next position Source: https://docs.rs/egui_dock/latest/src/egui_dock/dock_state/window_state.rs.html Retrieves and clears the pending next position for the window. This is an internal method. ```rust #[inline(always)] pub(crate) fn next_position(&mut self) -> Option { self.next_position.take() } ```