Adding egui directly and log

This commit is contained in:
Pcornat 2025-09-15 19:43:16 +02:00
commit 7f8c215227
Signed by: Pcornat
GPG key ID: E0326CC678A00BDD
2 changed files with 19 additions and 2 deletions

View file

@ -6,7 +6,10 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
egui = {version = "0.32.3", features = ["log"]}
eframe = { version = "0.32.3" } eframe = { version = "0.32.3" }
log = "0.4.28"
colog = "1.4.0"
rfd = "*" rfd = "*"
json = "*" json = "*"
serde = { version = "*", features = ["derive"] } serde = { version = "*", features = ["derive"] }

View file

@ -2,10 +2,12 @@ use std::path::PathBuf;
use eframe::egui; use eframe::egui;
use eframe::egui::KeyboardShortcut; use eframe::egui::KeyboardShortcut;
use log::{info, warn, error};
use billy_sheet::gui::SheetGui; use billy_sheet::gui::SheetGui;
fn main() -> eframe::Result { fn main() -> eframe::Result {
colog::init();
let options = eframe::NativeOptions { let options = eframe::NativeOptions {
viewport: egui::ViewportBuilder::default().with_drag_and_drop(true), viewport: egui::ViewportBuilder::default().with_drag_and_drop(true),
..Default::default() ..Default::default()
@ -54,7 +56,7 @@ impl eframe::App for Gui {
if ui.button("Save in json").clicked() { if ui.button("Save in json").clicked() {
let path = std::path::Path::new("./sheet.json"); let path = std::path::Path::new("./sheet.json");
if let Err(error) = billy_sheet::sheet::write_sheet(path, &self.sheet) { 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 { 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; self.picked_path = None;
} }
} }