Compare commits

...

2 Commits

Author SHA1 Message Date
David Holland a537ddb2f8
Add RON support and make it the preferred file format 2023-02-10 11:17:11 +01:00
David Holland c5e597bbea
Correct modal layout 2023-02-10 09:48:29 +01:00
4 changed files with 34 additions and 12 deletions

12
Cargo.lock generated
View File

@ -2456,6 +2456,17 @@ dependencies = [
"windows 0.37.0",
]
[[package]]
name = "ron"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "300a51053b1cb55c80b7a9fde4120726ddf25ca241a1cbb926626f62fb136bff"
dependencies = [
"base64",
"bitflags",
"serde",
]
[[package]]
name = "rustybeans"
version = "0.5.0"
@ -2473,6 +2484,7 @@ dependencies = [
"palette",
"plotly",
"rfd",
"ron",
"serde",
"serde_json",
"toml",

View File

@ -24,6 +24,7 @@ rfd = "0.10.0"
egui = { git = "https://github.com/emilk/egui", branch = "master" }
eframe = { git = "https://github.com/emilk/egui", branch = "master" }
ron = "0.8.0"
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
tracing-subscriber = "0.3"

View File

@ -1,9 +1,9 @@
use serde::Deserialize;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::fs;
#[derive(Deserialize, Debug, Default)]
#[derive(Deserialize, Debug, Default, Serialize)]
pub struct Shot {
pub filename: Option<String>,
pub json: Option<String>,
@ -12,7 +12,7 @@ pub struct Shot {
pub disable: Option<bool>,
}
#[derive(Deserialize, Debug, Default)]
#[derive(Deserialize, Debug, Default, Serialize)]
pub struct Chart {
pub title: String,
pub shots: Vec<u64>,
@ -22,7 +22,7 @@ pub struct Chart {
pub max_flow: u64,
}
#[derive(Deserialize, Debug, Default)]
#[derive(Deserialize, Debug, Default, Serialize)]
pub struct Config {
pub shots: HashMap<String, Shot>,
pub charts: HashMap<String, Chart>,
@ -50,12 +50,19 @@ pub struct Data {
}
impl Config {
pub fn from_file(path: &str) -> Self {
pub fn from_toml(path: &str) -> Self {
let config_file = fs::read_to_string(&path).expect("Can't read config.toml");
toml::from_str(&config_file).expect("Can't deserialize config.toml")
}
pub fn from_ron(path: &str) -> Self {
let config_file = fs::read_to_string(&path).expect("Can't read config.ron");
let ron: Self = ron::from_str(&config_file).expect("Can't deserialize config.ron");
println!("{}", ron::to_string(&ron).unwrap());
ron
}
pub fn from_default() -> Self {
Self::from_file("config.toml")
Self::from_ron("config.ron")
}
}

View File

@ -105,7 +105,7 @@ impl eframe::App for Ui {
ctx.request_repaint();
}
self.allowed_to_close = true;
// self.allowed_to_close = true;
egui::TopBottomPanel::bottom("status_bar").show(ctx, |ui| {
ui.columns(2, |_columns| {});
});
@ -166,10 +166,8 @@ impl eframe::App for Ui {
if self.show_confirmation_dialog {
// Show confirmation dialog:
ui.separator();
ui.vertical(|ui| {
ui.with_layout(Layout::top_down_justified(Align::Center).with_main_align(Align::Center).with_cross_align(Align::Center), |ui| {
ui.label("Really quit?");
ui.horizontal(|ui| {
if ui.button("Yes").clicked() {
self.allowed_to_close = true;
frame.close();
@ -179,7 +177,6 @@ impl eframe::App for Ui {
self.modal = false;
self.show_confirmation_dialog = false;
}
});
});
}
});
@ -346,7 +343,7 @@ impl eframe::App for Ui {
let mut loading_data = LoadingData::default();
loading_data.config = Config::from_file(&picked_path_owned);
loading_data.config = Config::from_ron(&picked_path_owned);
loading_data.database =
Database::from_config(&loading_data.config);
@ -430,6 +427,7 @@ impl eframe::App for Ui {
if ui.button("Open file").clicked() {
if let Some(path) = FileDialog::new()
.add_filter("ron", &["ron"])
.add_filter("toml", &["toml"])
.set_directory(
match &env::current_dir() {
@ -444,6 +442,10 @@ impl eframe::App for Ui {
}
}
if ui.button("Open default config.ron").clicked() {
self.picked_path = Some(String::from("config.ron"));
}
if ui.button("Open default config.toml").clicked() {
self.picked_path = Some(String::from("config.toml"));
}