2020-08-21 16:53:43 +00:00
|
|
|
//! Example of how to use Egui
|
|
|
|
|
2020-08-05 17:45:39 +00:00
|
|
|
#![deny(warnings)]
|
|
|
|
#![warn(clippy::all)]
|
|
|
|
|
2020-08-21 16:53:43 +00:00
|
|
|
use egui::{Slider, Window};
|
2020-09-16 06:03:40 +00:00
|
|
|
use egui_glium::storage::FileStorage;
|
2019-03-12 21:59:55 +00:00
|
|
|
|
2020-08-05 17:45:39 +00:00
|
|
|
/// We derive Deserialize/Serialize so we can persist app state on shutdown.
|
2020-07-22 16:01:27 +00:00
|
|
|
#[derive(Default, serde::Deserialize, serde::Serialize)]
|
2020-07-22 16:46:12 +00:00
|
|
|
struct MyApp {
|
2020-08-21 16:53:43 +00:00
|
|
|
my_string: String,
|
|
|
|
value: f32,
|
2020-07-22 16:01:27 +00:00
|
|
|
}
|
|
|
|
|
2020-07-23 16:54:16 +00:00
|
|
|
impl egui::app::App for MyApp {
|
2020-07-23 10:01:48 +00:00
|
|
|
/// This function will be called whenever the Ui needs to be shown,
|
|
|
|
/// which may be many times per second.
|
2020-10-17 10:33:30 +00:00
|
|
|
fn ui(
|
|
|
|
&mut self,
|
|
|
|
ui: &mut egui::Ui,
|
|
|
|
_info: &egui::app::BackendInfo,
|
|
|
|
_tex_allocator: Option<&mut dyn egui::app::TextureAllocator>,
|
|
|
|
) -> egui::app::AppOutput {
|
2020-08-21 16:53:43 +00:00
|
|
|
let MyApp { my_string, value } = self;
|
|
|
|
|
|
|
|
// Example used in `README.md`.
|
|
|
|
Window::new("Debug").show(ui.ctx(), |ui| {
|
|
|
|
ui.label(format!("Hello, world {}", 123));
|
|
|
|
if ui.button("Save").clicked {
|
|
|
|
my_save_function();
|
|
|
|
}
|
|
|
|
ui.text_edit(my_string);
|
|
|
|
ui.add(Slider::f32(value, 0.0..=1.0).text("float"));
|
|
|
|
});
|
2020-10-17 10:33:30 +00:00
|
|
|
|
|
|
|
Default::default()
|
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() {
|
2020-07-23 10:01:48 +00:00
|
|
|
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`.
|
2020-09-16 06:03:40 +00:00
|
|
|
egui_glium::run(title, storage, app);
|
2020-05-17 10:26:17 +00:00
|
|
|
}
|
2020-08-21 16:53:43 +00:00
|
|
|
|
|
|
|
fn my_save_function() {
|
|
|
|
// dummy
|
|
|
|
}
|