Setup base eframe application + serialization + arg parsing and configuration
This commit is contained in:
+59
@@ -0,0 +1,59 @@
|
||||
use std::time::Duration;
|
||||
use eframe::{egui, Frame, Storage, CreationContext};
|
||||
use eframe::egui::{Context, Ui};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Default)]
|
||||
pub(crate) struct Application {
|
||||
settings: AppSettings,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Default)]
|
||||
struct AppSettings {
|
||||
serialization_test_string: String,
|
||||
}
|
||||
|
||||
impl Application {
|
||||
pub fn new(cc: &CreationContext) -> Self {
|
||||
let mut settings = AppSettings::default();
|
||||
if let Some(storage) = cc.storage {
|
||||
if let Some(stored_str) = storage.get_string("app_settings") {
|
||||
if let Ok(parsed) = serde_json::from_str(&stored_str) {
|
||||
settings = parsed;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Self { settings }
|
||||
}
|
||||
}
|
||||
|
||||
impl eframe::App for Application {
|
||||
|
||||
fn logic(&mut self, ctx: &Context, frame: &mut Frame) {
|
||||
|
||||
}
|
||||
|
||||
fn ui(&mut self, ui: &mut Ui, frame: &mut Frame) {
|
||||
egui::CentralPanel::default().show(ui, |ui| {
|
||||
ui.heading("Hello!");
|
||||
ui.text_edit_singleline(&mut self.settings.serialization_test_string);
|
||||
});
|
||||
}
|
||||
|
||||
fn save(&mut self, _storage: &mut dyn Storage) {
|
||||
if let Ok(serialized) = serde_json::to_string(&self.settings) {
|
||||
_storage.set_string("app_settings", serialized);
|
||||
}
|
||||
}
|
||||
|
||||
fn on_exit(&mut self) {
|
||||
|
||||
}
|
||||
|
||||
fn auto_save_interval(&self) -> Duration {
|
||||
Duration::from_secs(5)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user