mirror of
https://github.com/emilk/egui.git
synced 2026-08-30 13:20:05 -04:00
eframe: add a simplified native-only API for simple native apps (#2453)
* eframe: add a simplified native-only API for simple native apps * build-fix * Fix doc-test
This commit is contained in:
33
examples/hello_world_simple/src/main.rs
Normal file
33
examples/hello_world_simple/src/main.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
|
||||
|
||||
use eframe::egui;
|
||||
|
||||
fn main() -> Result<(), eframe::Error> {
|
||||
// Log to stdout (if you run with `RUST_LOG=debug`).
|
||||
tracing_subscriber::fmt::init();
|
||||
|
||||
let options = eframe::NativeOptions {
|
||||
initial_window_size: Some(egui::vec2(320.0, 240.0)),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
// Our application state:
|
||||
let mut name = "Arthur".to_owned();
|
||||
let mut age = 42;
|
||||
|
||||
eframe::run_simple_native("My egui App", options, move |ctx, _frame| {
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
ui.heading("My egui Application");
|
||||
ui.horizontal(|ui| {
|
||||
let name_label = ui.label("Your name: ");
|
||||
ui.text_edit_singleline(&mut name)
|
||||
.labelled_by(name_label.id);
|
||||
});
|
||||
ui.add(egui::Slider::new(&mut age, 0..=120).text("age"));
|
||||
if ui.button("Click each year").clicked() {
|
||||
age += 1;
|
||||
}
|
||||
ui.label(format!("Hello '{}', age {}", name, age));
|
||||
});
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user