From b986200de1d535f3fe0197cd38d7087fc1f72298 Mon Sep 17 00:00:00 2001 From: p6nj Date: Wed, 1 May 2024 10:00:54 +0200 Subject: [PATCH] file dispatch --- src/app.rs | 24 +++++++++++++++++++ src/main.rs | 68 ++++------------------------------------------------- src/tabs.rs | 43 +++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+), 64 deletions(-) create mode 100644 src/app.rs create mode 100644 src/tabs.rs diff --git a/src/app.rs b/src/app.rs new file mode 100644 index 0000000..ea759ad --- /dev/null +++ b/src/app.rs @@ -0,0 +1,24 @@ +use eframe::egui; +use egui_dock::{DockArea, DockState, Style}; + +use crate::tabs::{Tab, TabViewer}; + +pub(super) struct App { + tree: DockState, +} + +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); + } +} + +impl Default for App { + fn default() -> Self { + let tree = DockState::new(vec![Tab::new("dummy"), Tab::new("hi")]); + + Self { tree } + } +} diff --git a/src/main.rs b/src/main.rs index 80fcb96..4890c9d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,69 +1,9 @@ #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] - -use std::fmt::Display; - -use derive_new::new; use eframe::egui; -use egui_dock::{DockArea, DockState, Style}; -struct Main { - tree: DockState, -} - -impl eframe::App for Main { - 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); - } -} - -impl Default for Main { - fn default() -> Self { - let tree = DockState::new(vec![Tab::new("dummy"), Tab::new("hi")]); - - Self { tree } - } -} - -#[derive(new)] -struct Tab { - name: &'static str, -} - -impl Display for Tab { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{}", self.name) - } -} - -struct TabViewer; - -impl egui_dock::TabViewer for TabViewer { - type Tab = Tab; - - fn title(&mut self, tab: &mut Self::Tab) -> egui::WidgetText { - format!("{tab}").into() - } - fn ui(&mut self, ui: &mut egui::Ui, tab: &mut Self::Tab) { - ui.label(format!("Content of {tab}")); - } - fn allowed_in_windows(&self, _tab: &mut Self::Tab) -> bool { - false - } - fn closeable(&mut self, _tab: &mut Self::Tab) -> bool { - false - } - fn context_menu( - &mut self, - _ui: &mut egui::Ui, - _tab: &mut Self::Tab, - _surface: egui_dock::SurfaceIndex, - _node: egui_dock::NodeIndex, - ) { - } - fn on_add(&mut self, _surface: egui_dock::SurfaceIndex, _node: egui_dock::NodeIndex) {} -} +mod app; +use app::App; +mod tabs; fn main() -> Result<(), eframe::Error> { let options = eframe::NativeOptions { @@ -75,6 +15,6 @@ fn main() -> Result<(), eframe::Error> { eframe::run_native( "Native file dialogs and drag-and-drop files", options, - Box::new(|_cc| Box::
::default()), + Box::new(|_cc| Box::::default()), ) } diff --git a/src/tabs.rs b/src/tabs.rs new file mode 100644 index 0000000..ffc98f7 --- /dev/null +++ b/src/tabs.rs @@ -0,0 +1,43 @@ +use std::fmt::Display; + +use derive_new::new; +use eframe::egui::{Ui, WidgetText}; + +#[derive(new)] +pub(crate) struct Tab { + name: &'static str, +} + +impl Display for Tab { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self.name) + } +} + +pub(crate) struct TabViewer; + +impl egui_dock::TabViewer for TabViewer { + type Tab = Tab; + + fn title(&mut self, tab: &mut Self::Tab) -> WidgetText { + format!("{tab}").into() + } + fn ui(&mut self, ui: &mut Ui, tab: &mut Self::Tab) { + ui.label(format!("Content of {tab}")); + } + fn allowed_in_windows(&self, _tab: &mut Self::Tab) -> bool { + false + } + fn closeable(&mut self, _tab: &mut Self::Tab) -> bool { + false + } + fn context_menu( + &mut self, + _ui: &mut Ui, + _tab: &mut Self::Tab, + _surface: egui_dock::SurfaceIndex, + _node: egui_dock::NodeIndex, + ) { + } + fn on_add(&mut self, _surface: egui_dock::SurfaceIndex, _node: egui_dock::NodeIndex) {} +}