1
0
mirror of https://github.com/emilk/egui.git synced 2026-06-27 23:13:13 -04:00

[app] unify web and glium demo app

This commit is contained in:
Emil Ernerfeldt
2020-07-23 18:54:16 +02:00
parent b79c76b9ce
commit 554e6e7120
15 changed files with 445 additions and 442 deletions

View File

@@ -1,6 +1,4 @@
use egui_glium::{persistence::Persistence, RunMode, Runner};
const APP_KEY: &str = "app";
use egui_glium::{storage::FileStorage, RunMode};
/// We dervive Deserialize/Serialize so we can persist app state on shutdown.
#[derive(Default, serde::Deserialize, serde::Serialize)]
@@ -8,10 +6,10 @@ struct MyApp {
counter: u64,
}
impl egui_glium::App for MyApp {
impl egui::app::App for MyApp {
/// This function will be called whenever the Ui needs to be shown,
/// which may be many times per second.
fn ui(&mut self, ui: &mut egui::Ui, _: &mut Runner) {
fn ui(&mut self, ui: &mut egui::Ui, _: &mut dyn egui::app::Backend) {
if ui.button("Increment").clicked {
self.counter += 1;
}
@@ -21,14 +19,14 @@ impl egui_glium::App for MyApp {
ui.label(format!("Counter: {}", self.counter));
}
fn on_exit(&mut self, persistence: &mut Persistence) {
persistence.set_value(APP_KEY, self); // Save app state
fn on_exit(&mut self, storage: &mut dyn egui::app::Storage) {
egui::app::set_value(storage, egui::app::APP_KEY, self);
}
}
fn main() {
let title = "My Egui Window";
let persistence = Persistence::from_path(".egui_example_glium.json".into()); // Where to persist app state
let app: MyApp = persistence.get_value(APP_KEY).unwrap_or_default(); // Restore `MyApp` from file, or create new `MyApp`.
egui_glium::run(title, RunMode::Reactive, persistence, app);
let storage = FileStorage::from_path(".egui_example_glium.json".into()); // Where to persist app state
let app: MyApp = egui::app::get_value(&storage, egui::app::APP_KEY).unwrap_or_default(); // Restore `MyApp` from file, or create new `MyApp`.
egui_glium::run(title, RunMode::Reactive, storage, app);
}