pub struct Tree<Pane> {
pub root: Option<TileId>,
pub tiles: Tiles<Pane>,
/* private fields */
}
Expand description
The top level type. Contains all persistent state, including layouts and sizes.
You’ll usually construct this once and then store it, calling Tree::ui
each frame.
See the crate-level documentation for a complete example.
§How to construct a Tree
use egui_tiles::{Tiles, TileId, Tree};
struct Pane { } // put some state here
let mut tiles = Tiles::default();
let tabs: Vec<TileId> = vec![tiles.insert_pane(Pane { }), tiles.insert_pane(Pane { })];
let root: TileId = tiles.insert_tab_tile(tabs);
let tree = Tree::new("my_tree", root, tiles);
Fields§
§root: Option<TileId>
None = empty tree
tiles: Tiles<Pane>
All the tiles in the tree.
Implementations§
source§impl<Pane> Tree<Pane>
impl<Pane> Tree<Pane>
sourcepub fn empty(id: impl Into<Id>) -> Self
pub fn empty(id: impl Into<Id>) -> Self
Construct an empty tree.
The id
must be globally unique (!).
This is so that the same tree can be added to different egui::Ui
s (if you want).
sourcepub fn new(id: impl Into<Id>, root: TileId, tiles: Tiles<Pane>) -> Self
pub fn new(id: impl Into<Id>, root: TileId, tiles: Tiles<Pane>) -> Self
The most flexible constructor, allowing you to set up the tiles however you want.
The id
must be globally unique (!).
This is so that the same tree can be added to different egui::Ui
s (if you want).
sourcepub fn new_tabs(id: impl Into<Id>, panes: Vec<Pane>) -> Self
pub fn new_tabs(id: impl Into<Id>, panes: Vec<Pane>) -> Self
Create a top-level crate::Tabs
container with the given panes.
The id
must be globally unique (!).
This is so that the same tree can be added to different egui::Ui
s (if you want).
sourcepub fn new_horizontal(id: impl Into<Id>, panes: Vec<Pane>) -> Self
pub fn new_horizontal(id: impl Into<Id>, panes: Vec<Pane>) -> Self
Create a top-level horizontal crate::Linear
container with the given panes.
The id
must be globally unique (!).
This is so that the same tree can be added to different egui::Ui
s (if you want).
sourcepub fn new_vertical(id: impl Into<Id>, panes: Vec<Pane>) -> Self
pub fn new_vertical(id: impl Into<Id>, panes: Vec<Pane>) -> Self
Create a top-level vertical crate::Linear
container with the given panes.
The id
must be globally unique (!).
This is so that the same tree can be added to different egui::Ui
s (if you want).
sourcepub fn new_grid(id: impl Into<Id>, panes: Vec<Pane>) -> Self
pub fn new_grid(id: impl Into<Id>, panes: Vec<Pane>) -> Self
Create a top-level crate::Grid
container with the given panes.
The id
must be globally unique (!).
This is so that the same tree can be added to different egui::Ui
s (if you want).
sourcepub fn new_container(
id: impl Into<Id>,
kind: ContainerKind,
panes: Vec<Pane>,
) -> Self
pub fn new_container( id: impl Into<Id>, kind: ContainerKind, panes: Vec<Pane>, ) -> Self
Create a top-level container with the given panes.
The id
must be globally unique (!).
This is so that the same tree can be added to different egui::Ui
s (if you want).
sourcepub fn remove_recursively(&mut self, id: TileId) -> Vec<Tile<Pane>>
pub fn remove_recursively(&mut self, id: TileId) -> Vec<Tile<Pane>>
Remove the given tile and all child tiles, recursively.
This also removes the tile id from the parent’s list of children.
All removed tiles are returned in unspecified order.
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Check if Self::root
is None
.
pub fn root(&self) -> Option<TileId>
pub fn is_root(&self, tile: TileId) -> bool
sourcepub fn is_visible(&self, tile_id: TileId) -> bool
pub fn is_visible(&self, tile_id: TileId) -> bool
Tiles are visible by default.
Invisible tiles still retain their place in the tile hierarchy.
sourcepub fn set_visible(&mut self, tile_id: TileId, visible: bool)
pub fn set_visible(&mut self, tile_id: TileId, visible: bool)
Tiles are visible by default.
Invisible tiles still retain their place in the tile hierarchy.
sourcepub fn active_tiles(&self) -> Vec<TileId>
pub fn active_tiles(&self) -> Vec<TileId>
All visible tiles.
This excludes all tiles that invisible or are inactive tabs, recursively.
The order of the returned tiles is arbitrary.
sourcepub fn ui(&mut self, behavior: &mut dyn Behavior<Pane>, ui: &mut Ui)
pub fn ui(&mut self, behavior: &mut dyn Behavior<Pane>, ui: &mut Ui)
Show the tree in the given Ui
.
The tree will use upp all the available space - nothing more, nothing less.
sourcepub fn set_height(&mut self, height: f32)
pub fn set_height(&mut self, height: f32)
Sets the exact height that can be used by the tree.
Determines the height that will be used by the tree component. By default, the tree occupies all the available space in the parent container.
sourcepub fn set_width(&mut self, width: f32)
pub fn set_width(&mut self, width: f32)
Sets the exact width that can be used by the tree.
Determines the width that will be used by the tree component. By default, the tree occupies all the available space in the parent container.
sourcepub fn make_active(
&mut self,
should_activate: impl FnMut(TileId, &Tile<Pane>) -> bool,
) -> bool
pub fn make_active( &mut self, should_activate: impl FnMut(TileId, &Tile<Pane>) -> bool, ) -> bool
Recursively “activate” the ancestors of the tiles that matches the given predicate.
This means making the matching tiles and its ancestors the active tab in any tab layout.
Returns true
if a tab was made active.
sourcepub fn simplify(&mut self, options: &SimplificationOptions)
pub fn simplify(&mut self, options: &SimplificationOptions)
Simplify and normalize the tree using the given options.
This is also called at the start of Self::ui
.
sourcepub fn simplify_children_of_tile(
&mut self,
tile_id: TileId,
options: &SimplificationOptions,
)
pub fn simplify_children_of_tile( &mut self, tile_id: TileId, options: &SimplificationOptions, )
Simplify all of the children of the given container tile recursively.
sourcepub fn gc(&mut self, behavior: &mut dyn Behavior<Pane>)
pub fn gc(&mut self, behavior: &mut dyn Behavior<Pane>)
Garbage-collect tiles that are no longer reachable from the root tile.
This is also called by Self::ui
, so usually you don’t need to call this yourself.
sourcepub fn move_tile_to_container(
&mut self,
moved_tile_id: TileId,
destination_container: TileId,
insertion_index: usize,
reflow_grid: bool,
)
pub fn move_tile_to_container( &mut self, moved_tile_id: TileId, destination_container: TileId, insertion_index: usize, reflow_grid: bool, )
Move a tile to a new container, at the specified insertion index.
If the insertion index is greater than the current number of children, the tile is appended at the end.
The grid layout needs a special treatment because it can have holes. When dragging a tile away from a grid, it
leaves behind it a hole. As a result, if the tile is the dropped in the same grid, it there is no need to account
for an insertion index shift (the hole can still occupy the original place of the dragged tile). However, if the
tiles are reordered in a separate, linear representation of the grid (such as the Rerun blueprint tree), the
expectation is that the grid is properly reordered and thus the insertion index must be shifted in case the tile
is moved inside the same grid. The reflow_grid
parameter controls this behavior.
TL;DR:
- when drag-and-dropping from a 2D representation of the grid, set
reflow_grid = false
- when drag-and-dropping from a 1D representation of the grid, set
reflow_grid = true
sourcepub fn dragged_id(&self, ctx: &Context) -> Option<TileId>
pub fn dragged_id(&self, ctx: &Context) -> Option<TileId>
Find the currently dragged tile, if any.
Trait Implementations§
source§impl<'de, Pane> Deserialize<'de> for Tree<Pane>where
Pane: Deserialize<'de>,
impl<'de, Pane> Deserialize<'de> for Tree<Pane>where
Pane: Deserialize<'de>,
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl<Pane> StructuralPartialEq for Tree<Pane>
Auto Trait Implementations§
impl<Pane> Freeze for Tree<Pane>
impl<Pane> RefUnwindSafe for Tree<Pane>where
Pane: RefUnwindSafe,
impl<Pane> Send for Tree<Pane>where
Pane: Send,
impl<Pane> Sync for Tree<Pane>where
Pane: Sync,
impl<Pane> Unpin for Tree<Pane>where
Pane: Unpin,
impl<Pane> UnwindSafe for Tree<Pane>where
Pane: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)