diff --git a/README.md b/README.md index 46c00a7c..1e56a9f6 100644 --- a/README.md +++ b/README.md @@ -32,17 +32,19 @@ Sections: ### Example ``` rust -Window::new("Debug").show(ui.ctx(), |ui| { - ui.label(format!("Hello, world {}", 123)); - if ui.button("Save").clicked { - my_save_function(); - } - ui.text_edit(&mut my_string); - ui.add(Slider::f32(&mut value, 0.0..=1.0).text("float")); +ui.heading("My Egui Application"); +ui.horizontal(|ui| { + ui.label("Your name: "); + ui.text_edit(&mut name); }); +ui.add(egui::Slider::u32(&mut age, 0..=120).text("age")); +if ui.button("Click each year").clicked { + age += 1; +} +ui.label(format!("Hello '{}', age {}", name, age)); ``` - + ## Goals diff --git a/example_glium/src/main.rs b/example_glium/src/main.rs index 4a548324..159a70d3 100644 --- a/example_glium/src/main.rs +++ b/example_glium/src/main.rs @@ -4,10 +4,19 @@ #![warn(clippy::all)] /// We derive Deserialize/Serialize so we can persist app state on shutdown. -#[derive(Default, serde::Deserialize, serde::Serialize)] +#[derive(serde::Deserialize, serde::Serialize)] struct MyApp { - my_string: String, - value: f32, + name: String, + age: u32, +} + +impl Default for MyApp { + fn default() -> Self { + Self { + name: "Arthur".to_owned(), + age: 42, + } + } } impl egui::app::App for MyApp { @@ -16,19 +25,33 @@ impl egui::app::App for MyApp { fn ui( &mut self, ctx: &std::sync::Arc, - _integration_context: &mut egui::app::IntegrationContext, + integration_context: &mut egui::app::IntegrationContext, ) { - let MyApp { my_string, value } = self; + let MyApp { name, age } = self; // Example used in `README.md`. - egui::Window::new("Debug").show(ctx, |ui| { - ui.label(format!("Hello, world {}", 123)); - if ui.button("Save").clicked { - my_save_function(); + egui::CentralPanel::default().show(ctx, |ui| { + ui.heading("My Egui Application"); + + ui.horizontal(|ui| { + ui.label("Your name: "); + ui.text_edit(name); + }); + + ui.add(egui::Slider::u32(age, 0..=120).text("age")); + if ui.button("Click each year").clicked { + *age += 1; + } + + ui.label(format!("Hello '{}', age {}", name, age)); + + ui.advance_cursor(16.0); + if ui.button("Quit").clicked { + integration_context.output.quit = true; } - ui.text_edit(my_string); - ui.add(egui::Slider::f32(value, 0.0..=1.0).text("float")); }); + + integration_context.output.window_size = Some(ctx.used_size()); // resize the window to be just the size we need it to be } fn on_exit(&mut self, storage: &mut dyn egui::app::Storage) { @@ -48,7 +71,3 @@ 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, Box::new(storage), app); } - -fn my_save_function() { - // dummy -} diff --git a/media/demo-2020-10-24.png b/media/demo-2020-10-24.png new file mode 100644 index 00000000..96282a70 Binary files /dev/null and b/media/demo-2020-10-24.png differ