From a9224ae3fc910f986a774badeca218e3014df21b Mon Sep 17 00:00:00 2001 From: p6nj Date: Sun, 5 May 2024 22:51:39 +0200 Subject: [PATCH] file picker bad --- Cargo.toml | 1 + src/app.rs | 5 ++-- src/app/tabs.rs | 61 +++++++++++++++++++++++++++++++++++++------------ 3 files changed, 51 insertions(+), 16 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index eb99195..7beec45 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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"] } diff --git a/src/app.rs b/src/app.rs index ee38c8b..6cfaca5 100644 --- a/src/app.rs +++ b/src/app.rs @@ -10,6 +10,7 @@ use self::tabs::TabKind; #[derive(new)] pub(super) struct App { tree: DockState, + 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) } } diff --git a/src/app/tabs.rs b/src/app/tabs.rs index 5e5c8ce..268ecc5 100644 --- a/src/app/tabs.rs +++ b/src/app/tabs.rs @@ -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 { 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, +} 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 {