From 1dc272097c08d529bf2191cc5ea46df935926d28 Mon Sep 17 00:00:00 2001 From: p6nj Date: Thu, 2 May 2024 00:03:34 +0200 Subject: [PATCH] menu bar (// tab template) --- src/app.rs | 31 +++++++++++++++++++++++++------ src/app/tabs.rs | 15 +++++++++++++-- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/src/app.rs b/src/app.rs index 475d97d..ee38c8b 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1,20 +1,39 @@ use derive_new::new; -use eframe::egui; -use egui_dock::{DockArea, DockState, Style}; +use eframe::egui::{self, menu, CentralPanel, Frame}; +use egui_dock::{DockArea, DockState}; mod tabs; use tabs::{chefs_dish, Tab, TabViewer}; +use self::tabs::TabKind; + #[derive(new)] pub(super) struct App { tree: DockState, + open_summary: bool, } impl eframe::App for App { 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::new()); + CentralPanel::default() + .frame(Frame::central_panel(&ctx.style())) + .show(ctx, |ui| { + menu::bar(ui, |ui| { + ui.menu_button("Tabs", |ui| { + if ui.checkbox(&mut self.open_summary, "Summary").changed() { + match self.open_summary { + true => self.tree.push_to_focused_leaf(Tab::new(TabKind::Summary)), + false => { + self.tree = self + .tree + .filter_tabs(|tab| !matches!(tab.kind, TabKind::Summary)) + } + } + } + }); + }); + DockArea::new(&mut self.tree).show_inside(ui, &mut TabViewer::new()); + }); } } @@ -22,6 +41,6 @@ impl Default for App { fn default() -> Self { let tree = DockState::new(chefs_dish()); - Self::new(tree) + Self::new(tree, false) } } diff --git a/src/app/tabs.rs b/src/app/tabs.rs index f3c2729..5e5c8ce 100644 --- a/src/app/tabs.rs +++ b/src/app/tabs.rs @@ -3,7 +3,7 @@ use eframe::egui::{Ui, WidgetText}; use strum::{AsRefStr, EnumIter, IntoEnumIterator}; #[derive(Clone, AsRefStr, PartialEq, EnumIter)] -enum TabKind { +pub(super) enum TabKind { Input, Decode, Process, @@ -13,7 +13,7 @@ enum TabKind { Help, } -#[derive(new)] +#[derive(new, Clone)] pub(super) struct Tab { #[allow(private_interfaces)] pub(super) kind: TabKind, @@ -50,6 +50,17 @@ impl egui_dock::TabViewer for TabViewer { fn ui(&mut self, ui: &mut Ui, tab: &mut Self::Tab) { ui.heading(tab.kind.as_ref()); + // match tab.kind { + // TabKind::Input => { + // ui. + // }, + // TabKind::Decode => todo!(), + // TabKind::Process => todo!(), + // TabKind::Encode => todo!(), + // TabKind::Output => todo!(), + // TabKind::Summary => todo!(), + // TabKind::Help => todo!(), + // } } fn allowed_in_windows(&self, tab: &mut Self::Tab) -> bool {