egui_tiles

Struct Tree

source
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>

source

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::Uis (if you want).

source

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::Uis (if you want).

source

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::Uis (if you want).

source

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::Uis (if you want).

source

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::Uis (if you want).

source

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::Uis (if you want).

source

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::Uis (if you want).

source

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.

source

pub fn id(&self) -> Id

The globally unique id used by this Tree.

source

pub fn is_empty(&self) -> bool

Check if Self::root is None.

source

pub fn root(&self) -> Option<TileId>

source

pub fn is_root(&self, tile: TileId) -> bool

source

pub fn is_visible(&self, tile_id: TileId) -> bool

Tiles are visible by default.

Invisible tiles still retain their place in the tile hierarchy.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

pub fn simplify_children_of_tile( &mut self, tile_id: TileId, options: &SimplificationOptions, )

Simplify all of the children of the given container tile recursively.

source

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.

source

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
source

pub fn dragged_id(&self, ctx: &Context) -> Option<TileId>

Find the currently dragged tile, if any.

Trait Implementations§

source§

impl<Pane: Clone> Clone for Tree<Pane>

source§

fn clone(&self) -> Tree<Pane>

Returns a copy of the value. Read more
1.6.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<Pane: Debug> Debug for Tree<Pane>

source§

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

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

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>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<Pane: PartialEq> PartialEq for Tree<Pane>

source§

fn eq(&self, other: &Tree<Pane>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.6.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<Pane> Serialize for Tree<Pane>
where Pane: Serialize,

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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 T
where 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 T
where T: Clone,

source§

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 T
where U: Into<T>,

source§

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 T
where U: TryFrom<T>,

source§

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

source§

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