menu bar (// tab template)

This commit is contained in:
Breval Ferrari 2024-05-02 00:03:34 +02:00
parent acc35f78fa
commit 1dc272097c
No known key found for this signature in database
GPG key ID: CEAB625B75A836B2
2 changed files with 38 additions and 8 deletions

View file

@ -1,20 +1,39 @@
use derive_new::new; use derive_new::new;
use eframe::egui; use eframe::egui::{self, menu, CentralPanel, Frame};
use egui_dock::{DockArea, DockState, Style}; use egui_dock::{DockArea, DockState};
mod tabs; mod tabs;
use tabs::{chefs_dish, Tab, TabViewer}; use tabs::{chefs_dish, Tab, TabViewer};
use self::tabs::TabKind;
#[derive(new)] #[derive(new)]
pub(super) struct App { pub(super) struct App {
tree: DockState<Tab>, tree: DockState<Tab>,
open_summary: bool,
} }
impl eframe::App for App { impl eframe::App for App {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
DockArea::new(&mut self.tree) CentralPanel::default()
.style(Style::from_egui(ctx.style().as_ref())) .frame(Frame::central_panel(&ctx.style()))
.show(ctx, &mut TabViewer::new()); .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 { fn default() -> Self {
let tree = DockState::new(chefs_dish()); let tree = DockState::new(chefs_dish());
Self::new(tree) Self::new(tree, false)
} }
} }

View file

@ -3,7 +3,7 @@ use eframe::egui::{Ui, WidgetText};
use strum::{AsRefStr, EnumIter, IntoEnumIterator}; use strum::{AsRefStr, EnumIter, IntoEnumIterator};
#[derive(Clone, AsRefStr, PartialEq, EnumIter)] #[derive(Clone, AsRefStr, PartialEq, EnumIter)]
enum TabKind { pub(super) enum TabKind {
Input, Input,
Decode, Decode,
Process, Process,
@ -13,7 +13,7 @@ enum TabKind {
Help, Help,
} }
#[derive(new)] #[derive(new, Clone)]
pub(super) struct Tab { pub(super) struct Tab {
#[allow(private_interfaces)] #[allow(private_interfaces)]
pub(super) kind: TabKind, 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) { fn ui(&mut self, ui: &mut Ui, tab: &mut Self::Tab) {
ui.heading(tab.kind.as_ref()); 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 { fn allowed_in_windows(&self, tab: &mut Self::Tab) -> bool {