diff --git a/CHANGELOG.md b/CHANGELOG.md index c4857f8..6bce92b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,16 @@ - `Tree::tabs`: an iterator over the tabs in a tree ([#53](https://github.com/Adanos020/egui_dock/pull/53)). - `Style` now includes an option to show the hoverd tab's name ([#56](https://github.com/Adanos020/egui_dock/pull/56)) +### Deprecated (will be deleted in the next release) +- `dynamic_tab::TabContent` +- `dynamic_tab::OnClose` +- `dynamic_tab::ForceClose` +- `dynamic_tab::TabBuilder` +- `dynamic_tab::Tab` +- `dynamic_tab::BuiltTab` +- `dynamic_tab::DynamicTree` +- `dynamic_tab::DynamicTabViewer` + ## 0.2.1 - 2022-09-09 ### Added diff --git a/examples/traits.rs b/examples/traits.rs deleted file mode 100644 index 0bc7233..0000000 --- a/examples/traits.rs +++ /dev/null @@ -1,183 +0,0 @@ -#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release - -use eframe::{egui, NativeOptions}; -use egui::{ - style::Margin, text::LayoutJob, Align, Color32, FontId, Frame, TextFormat, TopBottomPanel, Ui, - Window, -}; - -use egui_dock::{DockArea, DynamicTree, NodeIndex, Tab, TabBuilder}; - -fn main() { - let options = NativeOptions::default(); - eframe::run_native( - "My egui App", - options, - Box::new(|_cc| Box::new(MyApp::default())), - ); -} - -struct MyApp { - tree: DynamicTree, -} - -impl Default for MyApp { - fn default() -> Self { - let tab1 = Box::new(Editor::new("Text".into())); - - 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 = 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]); - let [_, _] = tree.split_below(a, 0.7, vec![tab4]); - let [_, _] = tree.split_below(b, 0.5, vec![tab5]); - - Self { tree } - } -} - -impl eframe::App for MyApp { - fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { - TopBottomPanel::top("top") - .frame(Frame::none().inner_margin(Margin::same(2.0))) - .show(ctx, |ui| { - if ui.button("Add Editor").clicked() { - self.tree - .push_to_focused_leaf(Box::new(Editor::new("New Text".into()))); - } - }); - DockArea::new(&mut self.tree).show(ctx, &mut egui_dock::DynamicTabViewer {}); - } -} - -struct Editor { - name: String, - modified: bool, - text: String, - show_save: bool, - exit: bool, -} - -impl Editor { - pub fn new(name: String) -> Self { - Self { - name, - modified: false, - text: "Important text to edit".into(), - show_save: false, - exit: false, - } - } - - fn save(&mut self) { - self.modified = false; - //save text to file or someplace else - } -} - -impl Tab for Editor { - fn ui(&mut self, ui: &mut Ui) { - if self.show_save { - Window::new("Save") - .collapsible(false) - .collapsible(false) - .show(ui.ctx(), |ui| { - ui.vertical(|ui| { - ui.label(format!( - "You have unsaved work on {} would you like to save", - self.name - )); - ui.horizontal(|ui| { - if ui.button("Save").clicked() { - self.save(); - self.exit = true; - self.show_save = false; - } - if ui.button("Don't Save").clicked() { - self.exit = true; - self.show_save = false; - } - if ui.button("Cancel").clicked() { - self.exit = false; - self.show_save = false; - } - }); - }); - }); - } - Frame::none() - .inner_margin(Margin::same(2.0)) - .show(ui, |ui| { - ui.vertical(|ui| { - ui.horizontal(|ui| { - if ui.button("Save").clicked() { - self.save(); - } - }); - if ui.code_editor(&mut self.text).changed() { - self.modified = true; - } - }); - }); - } - - fn title(&mut self) -> egui::WidgetText { - if self.modified { - let mut job = LayoutJob::default(); - job.append( - self.name.as_str(), - 0.0, - TextFormat::simple(FontId::default(), Color32::from_rgb(245, 245, 67)), - ); - - job.append( - " M", - 0.0, - TextFormat { - font_id: FontId::proportional(FontId::default().size / 1.5), - color: Color32::from_rgb(245, 245, 67), - valign: Align::Min, - ..Default::default() - }, - ); - - job.into() - } else { - self.name.clone().into() - } - } - - fn on_close(&mut self) -> bool { - self.show_save = true; - self.exit || !self.modified - } - - fn force_close(&mut self) -> bool { - self.exit - } -} diff --git a/src/dynamic_tab.rs b/src/dynamic_tab.rs index 55e95fe..e7426f2 100644 --- a/src/dynamic_tab.rs +++ b/src/dynamic_tab.rs @@ -1,10 +1,16 @@ +#![allow(deprecated, dead_code)] + use egui::style::Margin; use egui::{Ui, WidgetText}; +#[deprecated] pub type TabContent = Box; +#[deprecated] pub type OnClose = Box bool + 'static>; +#[deprecated] pub type ForceClose = Box bool + 'static>; +#[deprecated] pub struct TabBuilder { title: Option, inner_margin: Margin, @@ -15,6 +21,7 @@ pub struct TabBuilder { } /// Dockable tab that can be used in [`crate::Tree`]s. +#[deprecated] pub trait Tab { /// Actual tab content. fn ui(&mut self, ui: &mut Ui); @@ -54,6 +61,7 @@ pub trait Tab { } } +#[deprecated] pub struct BuiltTab { pub title: WidgetText, pub inner_margin: Margin, @@ -180,21 +188,23 @@ impl TabBuilder { // ---------------------------------------------------------------------------- /// A type-def for when using [`Tab`] or [`TabBuilder`]. +#[deprecated] pub type DynamicTree = crate::Tree>; /// For use with [`crate::DockArea::show`] when using [`DynamicTree`]. #[derive(Default)] +#[deprecated] pub struct DynamicTabViewer {} impl crate::TabViewer for DynamicTabViewer { type Tab = Box; - fn context_menu(&mut self, _ui: &mut Ui, _tab: &mut Self::Tab) {} - fn ui(&mut self, ui: &mut Ui, tab: &mut Self::Tab) { tab.ui(ui) } + fn context_menu(&mut self, _ui: &mut Ui, _tab: &mut Self::Tab) {} + fn title(&mut self, tab: &mut Self::Tab) -> WidgetText { tab.title() } diff --git a/src/lib.rs b/src/lib.rs index 9d8d582..d1710c2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -65,6 +65,7 @@ use egui::*; use tree::TabIndex; use utils::*; +#[allow(deprecated)] pub use crate::{ dynamic_tab::{DynamicTabViewer, DynamicTree, Tab, TabBuilder}, style::{Style, StyleBuilder},