-
Notifications
You must be signed in to change notification settings - Fork 77
/
simple.rs
59 lines (47 loc) · 1.58 KB
/
simple.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
use eframe::{egui, NativeOptions};
use egui_dock::{DockArea, DockState, NodeIndex, Style};
fn main() -> eframe::Result<()> {
let options = NativeOptions::default();
eframe::run_native(
"My egui App",
options,
Box::new(|_cc| Ok(Box::<MyApp>::default())),
)
}
struct TabViewer {}
impl egui_dock::TabViewer for TabViewer {
type Tab = String;
fn title(&mut self, tab: &mut Self::Tab) -> egui::WidgetText {
(&*tab).into()
}
fn ui(&mut self, ui: &mut egui::Ui, tab: &mut Self::Tab) {
ui.label(format!("Content of {tab}"));
}
}
struct MyApp {
tree: DockState<String>,
}
impl Default for MyApp {
fn default() -> Self {
let mut tree = DockState::new(vec!["tab1".to_owned(), "tab2".to_owned()]);
// You can modify the tree before constructing the dock
let [a, b] =
tree.main_surface_mut()
.split_left(NodeIndex::root(), 0.3, vec!["tab3".to_owned()]);
let [_, _] = tree
.main_surface_mut()
.split_below(a, 0.7, vec!["tab4".to_owned()]);
let [_, _] = tree
.main_surface_mut()
.split_below(b, 0.5, vec!["tab5".to_owned()]);
Self { tree }
}
}
impl eframe::App for MyApp {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
DockArea::new(&mut self.tree)
.style(Style::from_egui(ctx.style().as_ref()))
.show(ctx, &mut TabViewer {});
}
}