1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-30 13:20:05 -04:00

Move examples out of eframe/examples into examples/ (#1486)

* Move examples out of eframe/examples into examples/

Give each example a `Cargo.toml` and `src/main.rs`.
This makes it easier for people to use as templates.

* Update README.md with more deps needed on vanilla Ubuntu
* Install libgtk-3-dev on CI, hoping that will fix something
This commit is contained in:
Emil Ernerfeldt
2022-04-13 16:13:24 +02:00
committed by GitHub
parent 170b21b63e
commit 2ae93c40ab
46 changed files with 317 additions and 71 deletions

View File

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