Skip to content

Commit

Permalink
Fix examples
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Sep 1, 2022
1 parent 122542f commit 809fff9
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 200 deletions.
10 changes: 6 additions & 4 deletions examples/hello.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use eframe::{egui, NativeOptions};
use egui::color_picker::{color_picker_color32, Alpha};
use egui::{Color32, RichText, Slider};

use egui_dock::{DockArea, NodeIndex, Style, TabBuilder, Tree};
use egui_dock::{DockArea, DynamicTree, NodeIndex, Style, TabBuilder};

fn main() {
let options = NativeOptions::default();
Expand All @@ -27,7 +27,7 @@ struct MyContext {
struct MyApp {
_context: Rc<RefCell<MyContext>>,
style: Rc<RefCell<Style>>,
tree: Tree,
tree: DynamicTree,
}

impl Default for MyApp {
Expand Down Expand Up @@ -164,7 +164,7 @@ impl Default for MyApp {
})
.build();

let mut tree = Tree::new(vec![node_tree, style_editor]);
let mut tree = DynamicTree::new(vec![node_tree, style_editor]);

let [a, b] = tree.split_left(NodeIndex::root(), 0.3, vec![inspector]);
let [_, _] = tree.split_below(a, 0.7, vec![files, assets]);
Expand All @@ -181,6 +181,8 @@ impl Default for MyApp {
impl eframe::App for MyApp {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
let style = self.style.borrow().clone();
DockArea::new(&mut self.tree).style(style).show(ctx);
DockArea::new(&mut self.tree)
.style(style)
.show(ctx, &mut egui_dock::DynamicTabViewer {});
}
}
59 changes: 21 additions & 38 deletions examples/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use eframe::{egui, NativeOptions};

use egui_dock::{DockArea, NodeIndex, Style, TabBuilder, Tree};
use egui_dock::{DockArea, NodeIndex, Style, Tree};

fn main() {
let options = NativeOptions::default();
Expand All @@ -13,49 +13,32 @@ fn main() {
);
}

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()
}
}

struct MyApp {
tree: Tree,
tree: Tree<String>,
}

impl Default for MyApp {
fn default() -> Self {
let tab1 = TabBuilder::default()
.title("Tab 1")
.content(|ui| {
ui.label("Tab 1");
})
.build();
let tab2 = TabBuilder::default()
.title("Tab 2")
.content(|ui| {
ui.label("Tab 2");
})
.build();
let tab3 = TabBuilder::default()
.title("Tab 3")
.content(|ui| {
ui.label("Tab 3");
})
.build();
let tab4 = TabBuilder::default()
.title("Tab 4")
.content(|ui| {
ui.label("Tab 4");
})
.build();
let tab5 = TabBuilder::default()
.title("Tab 5")
.content(|ui| {
ui.label("Tab 5");
})
.build();

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

// You can modify the tree before constructing the dock
let [a, b] = tree.split_left(NodeIndex::root(), 0.3, vec![tab3]);
let [_, _] = tree.split_below(a, 0.7, vec![tab4]);
let [_, _] = tree.split_below(b, 0.5, vec![tab5]);
let [a, b] = tree.split_left(NodeIndex::root(), 0.3, vec!["tab3".to_owned()]);
let [_, _] = tree.split_below(a, 0.7, vec!["tab4".to_owned()]);
let [_, _] = tree.split_below(b, 0.5, vec!["tab5".to_owned()]);

Self { tree }
}
Expand All @@ -65,6 +48,6 @@ 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);
.show(ctx, &mut TabViewer {});
}
}
10 changes: 5 additions & 5 deletions examples/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use egui::{
Window,
};

use egui_dock::{DockArea, NodeIndex, TabBuilder, TabTrait, Tree};
use egui_dock::{DockArea, DynamicTab, DynamicTree, NodeIndex, TabBuilder};

fn main() {
let options = NativeOptions::default();
Expand All @@ -18,7 +18,7 @@ fn main() {
}

struct MyApp {
tree: Tree,
tree: DynamicTree,
}

impl Default for MyApp {
Expand Down Expand Up @@ -50,7 +50,7 @@ impl Default for MyApp {
})
.build();

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

// You can modify the tree before constructing the dock
let [a, b] = tree.split_left(NodeIndex::root(), 0.3, vec![tab3]);
Expand All @@ -71,7 +71,7 @@ impl eframe::App for MyApp {
.push_to_focused_leaf(Box::new(Editor::new("New Text".into())));
}
});
DockArea::new(&mut self.tree).show(ctx);
DockArea::new(&mut self.tree).show(ctx, &mut egui_dock::DynamicTabViewer {});
}
}

Expand Down Expand Up @@ -100,7 +100,7 @@ impl Editor {
}
}

impl TabTrait for Editor {
impl DynamicTab for Editor {
fn ui(&mut self, ui: &mut Ui) {
if self.show_save {
Window::new("Save")
Expand Down
7 changes: 5 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,16 @@ pub use style::{Style, StyleBuilder};
use tree::TabIndex;
use utils::*;

pub use self::tab::{TabBuilder, TabTrait};
pub use self::dynamic_tab::{DynamicTab, DynamicTabViewer, DynamicTree, TabBuilder};
pub use self::tree::{Node, NodeIndex, Split, Tree};

mod dynamic_tab;
mod style;
mod tab;
mod tree;
mod utils;

// ----------------------------------------------------------------------------

struct HoverData {
rect: Rect,
tabs: Option<Rect>,
Expand Down Expand Up @@ -120,6 +122,7 @@ impl State {

// ----------------------------------------------------------------------------

/// How we view a tab when its in a [`Tree`].
pub trait TabViewer {
type Tab;

Expand Down
151 changes: 0 additions & 151 deletions src/tab.rs

This file was deleted.

0 comments on commit 809fff9

Please sign in to comment.