2021-12-30 21:43:53 +00:00
|
|
|
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
|
|
|
|
|
2022-03-16 14:39:48 +00:00
|
|
|
use eframe::egui;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let options = eframe::NativeOptions::default();
|
|
|
|
eframe::run_native("My egui App", options, |_cc| Box::new(MyApp::default()));
|
|
|
|
}
|
2021-01-02 12:18:21 +00:00
|
|
|
|
|
|
|
struct MyApp {
|
|
|
|
name: String,
|
|
|
|
age: u32,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for MyApp {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
|
|
|
name: "Arthur".to_owned(),
|
|
|
|
age: 42,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-16 14:39:48 +00:00
|
|
|
impl eframe::App for MyApp {
|
|
|
|
fn update(&mut self, ctx: &egui::Context, frame: &eframe::Frame) {
|
2021-01-02 12:18:21 +00:00
|
|
|
egui::CentralPanel::default().show(ctx, |ui| {
|
2021-01-17 13:48:59 +00:00
|
|
|
ui.heading("My egui Application");
|
2021-01-02 12:18:21 +00:00
|
|
|
ui.horizontal(|ui| {
|
|
|
|
ui.label("Your name: ");
|
2022-02-19 19:51:51 +00:00
|
|
|
ui.text_edit_singleline(&mut self.name);
|
2021-01-02 12:18:21 +00:00
|
|
|
});
|
2022-02-19 19:51:51 +00:00
|
|
|
ui.add(egui::Slider::new(&mut self.age, 0..=120).text("age"));
|
2021-01-25 17:50:19 +00:00
|
|
|
if ui.button("Click each year").clicked() {
|
2022-02-19 19:51:51 +00:00
|
|
|
self.age += 1;
|
2021-01-02 12:18:21 +00:00
|
|
|
}
|
2022-02-19 19:51:51 +00:00
|
|
|
ui.label(format!("Hello '{}', age {}", self.name, self.age));
|
2021-01-02 12:18:21 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// Resize the native window to be just the size we need it to be:
|
|
|
|
frame.set_window_size(ctx.used_size());
|
|
|
|
}
|
|
|
|
}
|