file picker bad

This commit is contained in:
Ponj 2024-05-05 22:51:39 +02:00
parent 1dc272097c
commit a9224ae3fc
Signed by: p6nj
GPG key ID: CEAB625B75A836B2
3 changed files with 51 additions and 16 deletions

View file

@ -11,6 +11,7 @@ anyhow = "1.0"
derive-new = "0.6.0"
eframe = "0.27"
egui_dock = "0.12"
egui_extras = "0.27.2"
rfd = "0.14"
strum = { version = "0.26", features = ["derive"] }

View file

@ -10,6 +10,7 @@ use self::tabs::TabKind;
#[derive(new)]
pub(super) struct App {
tree: DockState<Tab>,
tab_viewer: TabViewer,
open_summary: bool,
}
@ -32,7 +33,7 @@ impl eframe::App for App {
}
});
});
DockArea::new(&mut self.tree).show_inside(ui, &mut TabViewer::new());
DockArea::new(&mut self.tree).show_inside(ui, &mut self.tab_viewer);
});
}
}
@ -41,6 +42,6 @@ impl Default for App {
fn default() -> Self {
let tree = DockState::new(chefs_dish());
Self::new(tree, false)
Self::new(tree, TabViewer::default(), false)
}
}

View file

@ -1,5 +1,9 @@
use std::path::PathBuf;
use derive_new::new;
use eframe::egui::{Ui, WidgetText};
use eframe::egui::{Sense, Ui, WidgetText};
use egui_extras::{Column, TableBuilder};
use rfd::FileDialog;
use strum::{AsRefStr, EnumIter, IntoEnumIterator};
#[derive(Clone, AsRefStr, PartialEq, EnumIter)]
@ -38,8 +42,10 @@ pub(super) fn chefs_dish() -> Vec<Tab> {
TabKind::iter().take(5).map(|kind| Tab::new(kind)).collect()
}
#[derive(new)]
pub(super) struct TabViewer {}
#[derive(Default)]
pub(super) struct TabViewer {
input_files: Vec<PathBuf>,
}
impl egui_dock::TabViewer for TabViewer {
type Tab = Tab;
@ -50,17 +56,44 @@ 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!(),
// }
match tab.kind {
TabKind::Input => {
TableBuilder::new(ui)
.sense(Sense::click())
.column(Column::remainder())
.body(|body| {
body.rows(18.0, self.input_files.len(), |mut row| {
let index = row.index();
row.col(|ui| {
ui.label(
&self
.input_files
.get(index)
.map(|buf| {
buf.to_str().unwrap_or("[invalid UTF-8]").to_string()
})
.unwrap_or("???".to_string()),
);
});
});
});
if ui.button("Clear").clicked() {
self.input_files.clear();
}
if ui.button("Add").clicked() {
if let Some(mut paths) = FileDialog::new().pick_files() {
self.input_files.append(&mut paths);
}
}
// https://github.com/emilk/egui/blob/master/examples/file_dialog/src/main.rs
}
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 {