Crate egui_dock

source ·
Expand description

egui_dock: docking support for egui

Originally created by @lain-dono, this library provides docking support for egui. It lets you open and close tabs, freely move them around, insert them in selected parts of the DockArea, and resize them.

Usage

The library is centered around the Tree. It stores the layout of Nodes which contains tabs.

Tree is generic (Tree<Tab>) so you can use any data to represent a tab. You show the tabs using DockArea and specify how they are shown by implementing TabViewer.

use egui_dock::{NodeIndex, Tree};

struct MyTabs {
    tree: Tree<String>
}

impl MyTabs {
    pub fn new() -> Self {
        let tab1 = "tab1".to_string();
        let tab2 = "tab2".to_string();

        let mut tree = Tree::new(vec![tab1]);
        tree.split_left(NodeIndex::root(), 0.20, vec![tab2]);

        Self { tree }
    }

    fn ui(&mut self, ui: &mut egui::Ui) {
        let style = egui_dock::Style::from_egui(ui.style().as_ref());
        egui_dock::DockArea::new(&mut self.tree)
            .style(style)
            .show_inside(ui, &mut TabViewer {});
    }
}

struct TabViewer {}

impl egui_dock::TabViewer for TabViewer {
    type Tab = String;

    fn ui(&mut self, ui: &mut egui::Ui, tab: &mut Self::Tab) {
        ui.label(format!("Content of {tab}"));
    }

    fn title(&mut self, tab: &mut Self::Tab) -> egui::WidgetText {
        (&*tab).into()
    }
}

Re-exports

Structs

Enums

  • Represents an abstract node of a Tree.
  • Direction in which a new node is created relatively to the parent node at which the split occurs.
  • Left or right alignment for tab add button.

Traits