diff --git a/README.md b/README.md index 820bcdbe..40ae194a 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ If you have questions, use [Discussions](https://github.com/emilk/egui/discussio ui.heading("My Egui Application"); ui.horizontal(|ui| { ui.label("Your name: "); - ui.text_edit(&mut name); + ui.text_edit_singleline(&mut name); }); ui.add(egui::Slider::u32(&mut age, 0..=120).text("age")); if ui.button("Click each year").clicked { @@ -54,7 +54,7 @@ if ui.button("Click each year").clicked { ui.label(format!("Hello '{}', age {}", name, age)); ``` - + ## Goals @@ -66,7 +66,7 @@ ui.label(format!("Hello '{}', age {}", name, age)); * A simple 2D graphics API for custom painting * No callbacks * Pure immediate mode -* Extensible: [easy to write your own widgets for Egui](https://github.com/emilk/egui/blob/master/egui/src/demos/toggle_switch.rs) +* Extensible: [easy to write your own widgets for Egui](https://github.com/emilk/egui/blob/master/egui_demo_lib/src/apps/demo/toggle_switch.rs) * Modular: You should be able to use small parts of Egui and combine them in new ways * Safe: there is no `unsafe` code in Egui * Minimal dependencies @@ -97,7 +97,7 @@ The obvious alternative to Egui is [`imgui-rs`](https://github.com/Gekkio/imgui- * Egui is pure Rust * Egui is easily compiled to WASM * Egui lets you use native Rust String types (`imgui-rs` forces you to use annoying macros and wrappers for zero-terminated strings) -* [Writing your own widgets in Egui is simple](https://github.com/emilk/egui/blob/master/egui/src/demos/toggle_switch.rs) +* [Writing your own widgets in Egui is simple](https://github.com/emilk/egui/blob/master/egui_demo_lib/src/apps/demo/toggle_switch.rs) Egui also tries to improve your experience in other small ways: diff --git a/eframe/examples/hello_world.rs b/eframe/examples/hello_world.rs new file mode 100644 index 00000000..fd8b36fd --- /dev/null +++ b/eframe/examples/hello_world.rs @@ -0,0 +1,45 @@ +use eframe::{egui, epi}; + +struct MyApp { + name: String, + age: u32, +} + +impl Default for MyApp { + fn default() -> Self { + Self { + name: "Arthur".to_owned(), + age: 42, + } + } +} + +impl epi::App for MyApp { + fn name(&self) -> &str { + "My Egui App" + } + + fn update(&mut self, ctx: &egui::CtxRef, frame: &mut epi::Frame<'_>) { + let Self { name, age } = self; + + egui::CentralPanel::default().show(ctx, |ui| { + ui.heading("My Egui Application"); + ui.horizontal(|ui| { + ui.label("Your name: "); + ui.text_edit_singleline(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)); + }); + + // Resize the native window to be just the size we need it to be: + frame.set_window_size(ctx.used_size()); + } +} + +fn main() { + eframe::run_native(Box::new(MyApp::default())); +} diff --git a/media/demo-2021-01-02.png b/media/demo-2021-01-02.png new file mode 100644 index 00000000..d6aff2e6 Binary files /dev/null and b/media/demo-2021-01-02.png differ