diff --git a/Cargo.toml b/Cargo.toml index c8866d9..b8e8ae4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,9 +6,8 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -eframe = { version = "*", features = ["dark-light"] } -egui = { version = "*", features = ["deadlock_detection"]} -egui_file = "*" +eframe = { version = "*" } +rfd = "*" json = "*" serde = { version = "*", features = ["derive"] } serde_json = "*" diff --git a/src/dialog/file_dialog.rs b/src/dialog/file_dialog.rs deleted file mode 100644 index 8520062..0000000 --- a/src/dialog/file_dialog.rs +++ /dev/null @@ -1,10 +0,0 @@ -pub struct FileDialog { - dialog: egui_file::FileDialog, -} - -impl super::Dialog for FileDialog { - fn open(&mut self) { - self.dialog = egui_file::FileDialog::open_file(None); - self.dialog.open(); - } -} diff --git a/src/dialog/mod.rs b/src/dialog/mod.rs deleted file mode 100644 index 1bb90e5..0000000 --- a/src/dialog/mod.rs +++ /dev/null @@ -1,9 +0,0 @@ -pub mod file_dialog; -pub trait View { - fn ui(&mut self, ui: &mut egui::Ui); -} - -pub trait Dialog { - fn open(&mut self); - fn show(&mut self, ctx: &egui::Context); -} diff --git a/src/lib.rs b/src/lib.rs index 003d105..8d3728f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,2 @@ pub mod gui; pub mod sheet; -pub mod dialog; diff --git a/src/main.rs b/src/main.rs index b03a55e..a64ee48 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,20 +1,25 @@ +use std::path::PathBuf; + use eframe::egui; +use eframe::egui::KeyboardShortcut; use billy_sheet::gui::SheetGui; -fn main() { - let options = eframe::NativeOptions::default(); +fn main() -> eframe::Result { + let options = eframe::NativeOptions { + viewport: egui::ViewportBuilder::default().with_drag_and_drop(true), + ..Default::default() + }; eframe::run_native( "Billy Sheet editor", options, - Box::new(|_ctx| Box::::default()), - ); + Box::new(|_ctx| Ok(Box::::default())), + ) } -#[derive(Debug)] struct Gui { sheet: billy_sheet::sheet::CharacterSheet, - dialogs: Vec, + picked_path: Option, edit_mode: bool, } @@ -22,7 +27,7 @@ impl Default for Gui { fn default() -> Self { Self { sheet: billy_sheet::sheet::CharacterSheet::default(), - dialogs: Vec::new(), + picked_path: None, edit_mode: true, } } @@ -34,9 +39,17 @@ impl eframe::App for Gui { egui::menu::bar(ui, |ui| { egui::widgets::global_dark_light_mode_buttons(ui); ui.menu_button("File", |ui| { - if ui.button("Open (Ctrl + O)").clicked() {} + if ui.button("Open (Ctrl + O)").clicked() { + if let Some(path) = rfd::FileDialog::new() + .set_directory(std::env::current_dir().unwrap_or_default()) + .add_filter(".json", &["json"]) + .pick_file() + { + self.picked_path = Some(path); + } + } if ui.button("Quit (Ctrl + Q)").clicked() { - _frame.close(); + ui.ctx().send_viewport_cmd(egui::ViewportCommand::Close); } if ui.button("Save in json").clicked() { let path = std::path::Path::new("./sheet.json"); @@ -79,11 +92,15 @@ impl eframe::App for Gui { }); }); }); - if ctx - .input_mut() - .consume_key(egui::Modifiers::CTRL, egui::Key::Q) - { - _frame.close(); + ctx.input_mut(|i_state| { + let shortcut = KeyboardShortcut::new(egui::Modifiers::CTRL, egui::Key::Q); + if i_state.consume_shortcut(&shortcut) { + i_state.viewport().close_requested(); + } + }); + if let Some(file_path) = &self.picked_path { + println!("{}", file_path.to_str().unwrap_or_default()); + self.picked_path = None; } } }