Adam Gąsior 346f97c84b Tab rewrite (#6)
* Rewrite `Tab` as a struct with a `TabBuilder`, remove the necessity of creating a context type.
* Update crate documentation.
* Update README and docs.
* Put tab content inside a scroll area.
* Tweaks to `egui_dock::Style, style editor in `hello` example.
* Allow all impls of `egui::WidgetText` (including `egui::RichText`) in tab titles.
* Fix scrollbars showing up within content margins.
2022-08-14 19:49:55 +01:00
2022-08-14 19:48:35 +01:00
2022-08-14 19:49:55 +01:00
2022-07-29 14:18:23 +01:00
2022-08-14 19:49:55 +01:00
2022-07-29 14:18:23 +01:00
2022-07-29 14:38:06 +01:00
2022-08-14 19:49:55 +01:00

egui_dock: docking support for egui

egui_ver Crates.io docs.rs

Credit goes to @Iain-dono for implementing the actual library.

This fork aims to provide documentation and further development if necessary.

Demo

demo

Usage

First, create your context type and your tab widget:

use egui::{Frame, Ui, style::Margin};
use egui_dock::Tab;

struct MyContext;

struct MyTab {
    text: String,
}

impl MyTab {
    fn new(text: impl ToString) -> Self {
        Self {
            text: text.to_string(),
        }
    }
}

impl Tab<MyContext> for MyTab {
    fn title(&self) -> &str {
        &self.title
    }

    fn ui(&mut self, ui: &mut Ui, _ctx: &mut MyContext) {
        let margin = Margin::same(4.0);

        Frame::none().inner_margin(margin).show(ui, |ui| {
            ui.label(&self.text);
        });
    }
}

Then construct the initial tree using your tab widget:

use egui::style::Margin;
use egui_dock::{TabBuilder, Tree};

let tab1 = TabBuilder::default()
    .title("Tab 1")
    .content(|ui| {
        ui.label("Tab 1");
    })
    .build();
let tab2 = TabBuilder::default()
    .title("Tab 2")
    .inner_margin(Margin::same(4.0))
    .content(|ui| {
        ui.label("Tab 2");
    })
    .build();

let mut tree = Tree::new(vec![tab1, tab2]);

Finally, you can show the tree.

let id = ui.id();
egui_dock::show(&mut ui, id, &style, &mut tree);

Contribution

Feel free to open issues and pull requests.

S
Description
No description provided
Readme MIT
1.5 MiB
Languages
Rust 100%