Compare commits
No commits in common. "0e65343712e16e742fa83ee62f1674f2ba93e30d" and "fa6aca08efa54ef42a0bf9672874a5be42350690" have entirely different histories.
0e65343712
...
fa6aca08ef
3 changed files with 6 additions and 23 deletions
|
|
@ -6,10 +6,7 @@ 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.33.3" }
|
eframe = { version = "*" }
|
||||||
eframe = { version = "0.33.3" }
|
|
||||||
log = "0.4.28"
|
|
||||||
colog = "1.4.0"
|
|
||||||
rfd = "*"
|
rfd = "*"
|
||||||
json = "*"
|
json = "*"
|
||||||
serde = { version = "*", features = ["derive"] }
|
serde = { version = "*", features = ["derive"] }
|
||||||
|
|
|
||||||
22
src/main.rs
22
src/main.rs
|
|
@ -2,12 +2,10 @@ 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()
|
||||||
|
|
@ -38,8 +36,8 @@ impl Default for Gui {
|
||||||
impl eframe::App for Gui {
|
impl eframe::App for Gui {
|
||||||
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
||||||
egui::TopBottomPanel::top("menu").show(ctx, |ui| {
|
egui::TopBottomPanel::top("menu").show(ctx, |ui| {
|
||||||
egui::MenuBar::new().ui(ui, |ui| {
|
egui::menu::bar(ui, |ui| {
|
||||||
egui::widgets::global_theme_preference_buttons(ui);
|
egui::widgets::global_dark_light_mode_buttons(ui);
|
||||||
ui.menu_button("File", |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()
|
if let Some(path) = rfd::FileDialog::new()
|
||||||
|
|
@ -56,7 +54,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) {
|
||||||
error!("{error}");
|
println!("{error}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -101,19 +99,7 @@ impl eframe::App for Gui {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if let Some(file_path) = &self.picked_path {
|
if let Some(file_path) = &self.picked_path {
|
||||||
if let Some(extension) = file_path.extension() {
|
println!("{}", file_path.to_str().unwrap_or_default());
|
||||||
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ pub struct CharacterSheet {
|
||||||
pub fn write_sheet(path: &std::path::Path, sheet: &CharacterSheet) -> std::io::Result<()> {
|
pub fn write_sheet(path: &std::path::Path, sheet: &CharacterSheet) -> std::io::Result<()> {
|
||||||
let sheet_str = serde_json::to_string_pretty(&sheet)?;
|
let sheet_str = serde_json::to_string_pretty(&sheet)?;
|
||||||
let mut file = std::fs::File::create(path)?;
|
let mut file = std::fs::File::create(path)?;
|
||||||
write!(file, "{sheet_str}")
|
write!(file, "{}", sheet_str)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CharacterSheet {
|
impl CharacterSheet {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue