2019-04-21 08:13:05 +00:00
|
|
|
#![deny(warnings)]
|
2020-05-10 17:04:10 +00:00
|
|
|
#![warn(clippy::all)]
|
|
|
|
|
2020-07-22 20:26:49 +00:00
|
|
|
use egui_glium::{persistence::Persistence, RunMode, Runner};
|
2019-11-18 19:06:41 +00:00
|
|
|
|
2020-07-22 16:46:12 +00:00
|
|
|
const APP_KEY: &str = "app";
|
2019-03-12 21:59:55 +00:00
|
|
|
|
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-07-22 16:01:27 +00:00
|
|
|
egui_example_app: egui::ExampleApp,
|
2020-07-22 20:26:49 +00:00
|
|
|
frames_painted: u64,
|
2020-07-22 16:01:27 +00:00
|
|
|
}
|
|
|
|
|
2020-07-22 16:46:12 +00:00
|
|
|
impl egui_glium::App for MyApp {
|
|
|
|
fn ui(&mut self, ui: &mut egui::Ui, runner: &mut Runner) {
|
2020-07-22 16:01:27 +00:00
|
|
|
self.egui_example_app.ui(ui, "");
|
|
|
|
|
|
|
|
use egui::*;
|
|
|
|
let mut ui = ui.centered_column(ui.available().width().min(480.0));
|
|
|
|
ui.set_layout(Layout::vertical(Align::Min));
|
2020-07-22 16:46:12 +00:00
|
|
|
ui.add(label!("Egui inside of Glium").text_style(TextStyle::Heading));
|
2020-07-22 16:01:27 +00:00
|
|
|
if ui.add(Button::new("Quit")).clicked {
|
|
|
|
runner.quit();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ui.add(
|
|
|
|
label!(
|
2020-07-22 20:26:49 +00:00
|
|
|
"CPU usage: {:.2} ms / frame (excludes painting)",
|
|
|
|
1e3 * runner.cpu_time()
|
2020-07-22 16:01:27 +00:00
|
|
|
)
|
|
|
|
.text_style(TextStyle::Monospace),
|
|
|
|
);
|
2020-07-22 20:26:49 +00:00
|
|
|
|
|
|
|
ui.separator();
|
|
|
|
|
|
|
|
ui.horizontal(|ui| {
|
|
|
|
let mut run_mode = runner.run_mode();
|
|
|
|
ui.label("Run mode:");
|
|
|
|
ui.radio_value("Continuous", &mut run_mode, RunMode::Continuous)
|
|
|
|
.tooltip_text("Repaint everything each frame");
|
|
|
|
ui.radio_value("Reactive", &mut run_mode, RunMode::Reactive)
|
|
|
|
.tooltip_text("Repaint when there are animations or input (e.g. mouse movement)");
|
|
|
|
runner.set_run_mode(run_mode);
|
|
|
|
});
|
|
|
|
|
|
|
|
if runner.run_mode() == RunMode::Continuous {
|
|
|
|
ui.add(
|
|
|
|
label!("Repainting the UI each frame. FPS: {:.1}", runner.fps())
|
|
|
|
.text_style(TextStyle::Monospace),
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
ui.label("Only running UI code when there are animations or input");
|
|
|
|
}
|
|
|
|
|
|
|
|
self.frames_painted += 1;
|
|
|
|
ui.label(format!("Total frames painted: {}", self.frames_painted));
|
2020-07-22 16:01:27 +00:00
|
|
|
}
|
|
|
|
|
2020-07-22 16:46:12 +00:00
|
|
|
fn on_exit(&mut self, persistence: &mut Persistence) {
|
|
|
|
persistence.set_value(APP_KEY, self);
|
2020-07-22 16:01:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-12 21:59:55 +00:00
|
|
|
fn main() {
|
2020-07-22 16:46:12 +00:00
|
|
|
let title = "Egui glium example";
|
|
|
|
let persistence = Persistence::from_path(".egui_example_glium.json".into());
|
|
|
|
let app: MyApp = persistence.get_value(APP_KEY).unwrap_or_default();
|
2020-07-22 20:26:49 +00:00
|
|
|
egui_glium::run(title, RunMode::Reactive, persistence, app);
|
2020-05-17 10:26:17 +00:00
|
|
|
}
|