egui/example_glium/src/main.rs

33 lines
1.1 KiB
Rust
Raw Normal View History

2020-07-23 16:54:16 +00:00
use egui_glium::{storage::FileStorage, RunMode};
2019-03-12 21:59:55 +00:00
/// We dervive Deserialize/Serialize so we can persist app state on shutdown.
2020-07-22 16:01:27 +00:00
#[derive(Default, serde::Deserialize, serde::Serialize)]
struct MyApp {
counter: u64,
2020-07-22 16:01:27 +00:00
}
2020-07-23 16:54:16 +00:00
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.
2020-07-23 16:54:16 +00:00
fn ui(&mut self, ui: &mut egui::Ui, _: &mut dyn egui::app::Backend) {
if ui.button("Increment").clicked {
self.counter += 1;
2020-07-22 16:01:27 +00:00
}
if ui.button("Reset").clicked {
self.counter = 0;
2020-07-22 20:26:49 +00:00
}
ui.label(format!("Counter: {}", self.counter));
2020-07-22 16:01:27 +00:00
}
2020-07-23 16:54:16 +00:00
fn on_exit(&mut self, storage: &mut dyn egui::app::Storage) {
egui::app::set_value(storage, egui::app::APP_KEY, self);
2020-07-22 16:01:27 +00:00
}
}
2019-03-12 21:59:55 +00:00
fn main() {
let title = "My Egui Window";
2020-07-23 16:54:16 +00:00
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);
2020-05-17 10:26:17 +00:00
}