Add an eframe example app
This commit is contained in:
parent
d8d761aac7
commit
4202c4b6a9
3 changed files with 49 additions and 4 deletions
|
@ -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));
|
||||
```
|
||||
|
||||
<img src="media/demo-2020-10-24.png" width="40%">
|
||||
<img src="media/demo-2021-01-02.png" width="60%">
|
||||
|
||||
## 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:
|
||||
|
||||
|
|
45
eframe/examples/hello_world.rs
Normal file
45
eframe/examples/hello_world.rs
Normal file
|
@ -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()));
|
||||
}
|
BIN
media/demo-2021-01-02.png
Normal file
BIN
media/demo-2021-01-02.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 28 KiB |
Loading…
Reference in a new issue