diff --git a/Cargo.toml b/Cargo.toml index b8e8ae4..48e4aa6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,10 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -eframe = { version = "*" } +egui = { version = "0.33.3" } +eframe = { version = "0.33.3" } +log = "0.4.28" +colog = "1.4.0" rfd = "*" json = "*" serde = { version = "*", features = ["derive"] } diff --git a/src/main.rs b/src/main.rs index a64ee48..0c905d7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,10 +2,12 @@ use std::path::PathBuf; use eframe::egui; use eframe::egui::KeyboardShortcut; +use log::{info, warn, error}; use billy_sheet::gui::SheetGui; fn main() -> eframe::Result { + colog::init(); let options = eframe::NativeOptions { viewport: egui::ViewportBuilder::default().with_drag_and_drop(true), ..Default::default() @@ -36,8 +38,8 @@ impl Default for Gui { impl eframe::App for Gui { fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { egui::TopBottomPanel::top("menu").show(ctx, |ui| { - egui::menu::bar(ui, |ui| { - egui::widgets::global_dark_light_mode_buttons(ui); + egui::MenuBar::new().ui(ui, |ui| { + egui::widgets::global_theme_preference_buttons(ui); ui.menu_button("File", |ui| { if ui.button("Open (Ctrl + O)").clicked() { if let Some(path) = rfd::FileDialog::new() @@ -54,7 +56,7 @@ impl eframe::App for Gui { if ui.button("Save in json").clicked() { let path = std::path::Path::new("./sheet.json"); if let Err(error) = billy_sheet::sheet::write_sheet(path, &self.sheet) { - println!("{error}"); + error!("{error}"); } } }); @@ -99,7 +101,19 @@ impl eframe::App for Gui { } }); if let Some(file_path) = &self.picked_path { - println!("{}", file_path.to_str().unwrap_or_default()); + if let Some(extension) = file_path.extension() { + info!("File selected : {}", file_path.display()); + if extension == "json" { + info!("File has json extension"); + } else { + warn!( + "File has not .json: {}", + extension.to_str().unwrap_or_default() + ); + } + } else { + error!("No extension for the file."); + } self.picked_path = None; } } diff --git a/src/sheet.rs b/src/sheet.rs index 0021891..ac177f8 100644 --- a/src/sheet.rs +++ b/src/sheet.rs @@ -40,7 +40,7 @@ pub struct CharacterSheet { pub fn write_sheet(path: &std::path::Path, sheet: &CharacterSheet) -> std::io::Result<()> { let sheet_str = serde_json::to_string_pretty(&sheet)?; let mut file = std::fs::File::create(path)?; - write!(file, "{}", sheet_str) + write!(file, "{sheet_str}") } impl CharacterSheet {