Compare commits
5 commits
fa6aca08ef
...
0e65343712
| Author | SHA1 | Date | |
|---|---|---|---|
|
0e65343712 |
|||
|
ccd9039080 |
|||
|
7f8c215227 |
|||
|
ef751e5cb8 |
|||
|
9d5f7d2fb2 |
3 changed files with 23 additions and 6 deletions
|
|
@ -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"] }
|
||||
|
|
|
|||
22
src/main.rs
22
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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue