Working OK
This commit is contained in:
parent
09c02c8783
commit
fa6aca08ef
@ -6,9 +6,8 @@ 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]
|
||||||
eframe = { version = "*", features = ["dark-light"] }
|
eframe = { version = "*" }
|
||||||
egui = { version = "*", features = ["deadlock_detection"]}
|
rfd = "*"
|
||||||
egui_file = "*"
|
|
||||||
json = "*"
|
json = "*"
|
||||||
serde = { version = "*", features = ["derive"] }
|
serde = { version = "*", features = ["derive"] }
|
||||||
serde_json = "*"
|
serde_json = "*"
|
||||||
|
@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
@ -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);
|
|
||||||
}
|
|
@ -1,3 +1,2 @@
|
|||||||
pub mod gui;
|
pub mod gui;
|
||||||
pub mod sheet;
|
pub mod sheet;
|
||||||
pub mod dialog;
|
|
||||||
|
45
src/main.rs
45
src/main.rs
@ -1,20 +1,25 @@
|
|||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use eframe::egui;
|
use eframe::egui;
|
||||||
|
use eframe::egui::KeyboardShortcut;
|
||||||
|
|
||||||
use billy_sheet::gui::SheetGui;
|
use billy_sheet::gui::SheetGui;
|
||||||
|
|
||||||
fn main() {
|
fn main() -> eframe::Result {
|
||||||
let options = eframe::NativeOptions::default();
|
let options = eframe::NativeOptions {
|
||||||
|
viewport: egui::ViewportBuilder::default().with_drag_and_drop(true),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
eframe::run_native(
|
eframe::run_native(
|
||||||
"Billy Sheet editor",
|
"Billy Sheet editor",
|
||||||
options,
|
options,
|
||||||
Box::new(|_ctx| Box::<Gui>::default()),
|
Box::new(|_ctx| Ok(Box::<Gui>::default())),
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
struct Gui {
|
struct Gui {
|
||||||
sheet: billy_sheet::sheet::CharacterSheet,
|
sheet: billy_sheet::sheet::CharacterSheet,
|
||||||
dialogs: Vec<impl billy_sheet::dialog::Dialog>,
|
picked_path: Option<PathBuf>,
|
||||||
edit_mode: bool,
|
edit_mode: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -22,7 +27,7 @@ impl Default for Gui {
|
|||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
sheet: billy_sheet::sheet::CharacterSheet::default(),
|
sheet: billy_sheet::sheet::CharacterSheet::default(),
|
||||||
dialogs: Vec::new(),
|
picked_path: None,
|
||||||
edit_mode: true,
|
edit_mode: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -34,9 +39,17 @@ impl eframe::App for Gui {
|
|||||||
egui::menu::bar(ui, |ui| {
|
egui::menu::bar(ui, |ui| {
|
||||||
egui::widgets::global_dark_light_mode_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()
|
||||||
|
.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() {
|
if ui.button("Quit (Ctrl + Q)").clicked() {
|
||||||
_frame.close();
|
ui.ctx().send_viewport_cmd(egui::ViewportCommand::Close);
|
||||||
}
|
}
|
||||||
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");
|
||||||
@ -79,11 +92,15 @@ impl eframe::App for Gui {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
if ctx
|
ctx.input_mut(|i_state| {
|
||||||
.input_mut()
|
let shortcut = KeyboardShortcut::new(egui::Modifiers::CTRL, egui::Key::Q);
|
||||||
.consume_key(egui::Modifiers::CTRL, egui::Key::Q)
|
if i_state.consume_shortcut(&shortcut) {
|
||||||
{
|
i_state.viewport().close_requested();
|
||||||
_frame.close();
|
}
|
||||||
|
});
|
||||||
|
if let Some(file_path) = &self.picked_path {
|
||||||
|
println!("{}", file_path.to_str().unwrap_or_default());
|
||||||
|
self.picked_path = None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user