egui/eframe/examples/hello_world.rs
Emil Ernerfeldt d5673412dd
Put everything in Context behind the same Mutex (#1050)
* Move all interior mutability from Context to CtxRef and make it a handle
* Rename `CtxRef` to `Context`
* The old `Context` is now `ContextImpl` and is non-pub
* Add benchmark Painter::rect

Co-authored-by: Daniel Keller <dklr433@gmail.com>
2022-01-10 23:13:10 +01:00

48 lines
1.2 KiB
Rust

#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
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::Context, frame: &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::new(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() {
let options = eframe::NativeOptions::default();
eframe::run_native(Box::new(MyApp::default()), options);
}