file dispatch
This commit is contained in:
parent
a71e04f8d4
commit
b986200de1
3 changed files with 71 additions and 64 deletions
24
src/app.rs
Normal file
24
src/app.rs
Normal file
|
@ -0,0 +1,24 @@
|
|||
use eframe::egui;
|
||||
use egui_dock::{DockArea, DockState, Style};
|
||||
|
||||
use crate::tabs::{Tab, TabViewer};
|
||||
|
||||
pub(super) struct App {
|
||||
tree: DockState<Tab>,
|
||||
}
|
||||
|
||||
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 }
|
||||
}
|
||||
}
|
68
src/main.rs
68
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<Tab>,
|
||||
}
|
||||
|
||||
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::<Main>::default()),
|
||||
Box::new(|_cc| Box::<App>::default()),
|
||||
)
|
||||
}
|
||||
|
|
43
src/tabs.rs
Normal file
43
src/tabs.rs
Normal file
|
@ -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) {}
|
||||
}
|
Loading…
Reference in a new issue