mirror of
https://github.com/emilk/egui.git
synced 2026-06-26 22:53:14 -04:00
[docs] Improve README.md and documentation
This commit is contained in:
@@ -1,25 +1,33 @@
|
||||
//! Example of how to use Egui
|
||||
|
||||
#![deny(warnings)]
|
||||
#![warn(clippy::all)]
|
||||
|
||||
use egui::{Slider, Window};
|
||||
use egui_glium::{storage::FileStorage, RunMode};
|
||||
|
||||
/// We derive Deserialize/Serialize so we can persist app state on shutdown.
|
||||
#[derive(Default, serde::Deserialize, serde::Serialize)]
|
||||
struct MyApp {
|
||||
counter: u64,
|
||||
my_string: String,
|
||||
value: f32,
|
||||
}
|
||||
|
||||
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 dyn egui::app::Backend) {
|
||||
if ui.button("Increment").clicked {
|
||||
self.counter += 1;
|
||||
}
|
||||
if ui.button("Reset").clicked {
|
||||
self.counter = 0;
|
||||
}
|
||||
ui.label(format!("Counter: {}", self.counter));
|
||||
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"));
|
||||
});
|
||||
}
|
||||
|
||||
fn on_exit(&mut self, storage: &mut dyn egui::app::Storage) {
|
||||
@@ -33,3 +41,7 @@ fn main() {
|
||||
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);
|
||||
}
|
||||
|
||||
fn my_save_function() {
|
||||
// dummy
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user