named tabs
This commit is contained in:
parent
b986200de1
commit
acc35f78fa
5 changed files with 71 additions and 49 deletions
|
@ -8,10 +8,11 @@ license = "Unlicense"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1.0"
|
anyhow = "1.0"
|
||||||
derive-new = "0.6"
|
derive-new = "0.6.0"
|
||||||
eframe = "0.27"
|
eframe = "0.27"
|
||||||
egui_dock = "0.12"
|
egui_dock = "0.12"
|
||||||
rfd = "0.14"
|
rfd = "0.14"
|
||||||
|
strum = { version = "0.26", features = ["derive"] }
|
||||||
|
|
||||||
[workspace]
|
[workspace]
|
||||||
members = ["bingus"]
|
members = ["bingus"]
|
||||||
|
|
11
src/app.rs
11
src/app.rs
|
@ -1,8 +1,11 @@
|
||||||
|
use derive_new::new;
|
||||||
use eframe::egui;
|
use eframe::egui;
|
||||||
use egui_dock::{DockArea, DockState, Style};
|
use egui_dock::{DockArea, DockState, Style};
|
||||||
|
|
||||||
use crate::tabs::{Tab, TabViewer};
|
mod tabs;
|
||||||
|
use tabs::{chefs_dish, Tab, TabViewer};
|
||||||
|
|
||||||
|
#[derive(new)]
|
||||||
pub(super) struct App {
|
pub(super) struct App {
|
||||||
tree: DockState<Tab>,
|
tree: DockState<Tab>,
|
||||||
}
|
}
|
||||||
|
@ -11,14 +14,14 @@ 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)
|
DockArea::new(&mut self.tree)
|
||||||
.style(Style::from_egui(ctx.style().as_ref()))
|
.style(Style::from_egui(ctx.style().as_ref()))
|
||||||
.show(ctx, &mut TabViewer);
|
.show(ctx, &mut TabViewer::new());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for App {
|
impl Default for App {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
let tree = DockState::new(vec![Tab::new("dummy"), Tab::new("hi")]);
|
let tree = DockState::new(chefs_dish());
|
||||||
|
|
||||||
Self { tree }
|
Self::new(tree)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
62
src/app/tabs.rs
Normal file
62
src/app/tabs.rs
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
use derive_new::new;
|
||||||
|
use eframe::egui::{Ui, WidgetText};
|
||||||
|
use strum::{AsRefStr, EnumIter, IntoEnumIterator};
|
||||||
|
|
||||||
|
#[derive(Clone, AsRefStr, PartialEq, EnumIter)]
|
||||||
|
enum TabKind {
|
||||||
|
Input,
|
||||||
|
Decode,
|
||||||
|
Process,
|
||||||
|
Encode,
|
||||||
|
Output,
|
||||||
|
Summary,
|
||||||
|
Help,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(new)]
|
||||||
|
pub(super) struct Tab {
|
||||||
|
#[allow(private_interfaces)]
|
||||||
|
pub(super) kind: TabKind,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TabKind {
|
||||||
|
fn is_optional(&self) -> bool {
|
||||||
|
match self {
|
||||||
|
Self::Input | Self::Decode | Self::Process | Self::Encode | Self::Output => false,
|
||||||
|
_ => true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Tab {
|
||||||
|
fn is_optional(&self) -> bool {
|
||||||
|
self.kind.is_optional()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(super) fn chefs_dish() -> Vec<Tab> {
|
||||||
|
TabKind::iter().take(5).map(|kind| Tab::new(kind)).collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(new)]
|
||||||
|
pub(super) struct TabViewer {}
|
||||||
|
|
||||||
|
impl egui_dock::TabViewer for TabViewer {
|
||||||
|
type Tab = Tab;
|
||||||
|
|
||||||
|
fn title(&mut self, tab: &mut Self::Tab) -> WidgetText {
|
||||||
|
tab.kind.as_ref().into()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn ui(&mut self, ui: &mut Ui, tab: &mut Self::Tab) {
|
||||||
|
ui.heading(tab.kind.as_ref());
|
||||||
|
}
|
||||||
|
|
||||||
|
fn allowed_in_windows(&self, tab: &mut Self::Tab) -> bool {
|
||||||
|
tab.is_optional()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn closeable(&mut self, tab: &mut Self::Tab) -> bool {
|
||||||
|
tab.is_optional()
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,7 +3,6 @@ use eframe::egui;
|
||||||
|
|
||||||
mod app;
|
mod app;
|
||||||
use app::App;
|
use app::App;
|
||||||
mod tabs;
|
|
||||||
|
|
||||||
fn main() -> Result<(), eframe::Error> {
|
fn main() -> Result<(), eframe::Error> {
|
||||||
let options = eframe::NativeOptions {
|
let options = eframe::NativeOptions {
|
||||||
|
|
43
src/tabs.rs
43
src/tabs.rs
|
@ -1,43 +0,0 @@
|
||||||
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…
Add table
Add a link
Reference in a new issue