mirror of
https://github.com/emilk/egui.git
synced 2026-08-29 04:40:03 -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:
12
examples/confirm_exit/Cargo.toml
Normal file
12
examples/confirm_exit/Cargo.toml
Normal file
@@ -0,0 +1,12 @@
|
||||
[package]
|
||||
name = "confirm_exit"
|
||||
version = "0.1.0"
|
||||
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
|
||||
license = "MIT OR Apache-2.0"
|
||||
edition = "2021"
|
||||
rust-version = "1.60"
|
||||
publish = false
|
||||
|
||||
|
||||
[dependencies]
|
||||
eframe = { path = "../../eframe" }
|
||||
3
examples/confirm_exit/README.md
Normal file
3
examples/confirm_exit/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
```sh
|
||||
cargo run -p confirm_exit
|
||||
```
|
||||
49
examples/confirm_exit/src/main.rs
Normal file
49
examples/confirm_exit/src/main.rs
Normal file
@@ -0,0 +1,49 @@
|
||||
#![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(
|
||||
"Confirm exit",
|
||||
options,
|
||||
Box::new(|_cc| Box::new(MyApp::default())),
|
||||
);
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct MyApp {
|
||||
can_exit: bool,
|
||||
is_exiting: bool,
|
||||
}
|
||||
|
||||
impl eframe::App for MyApp {
|
||||
fn on_exit_event(&mut self) -> bool {
|
||||
self.is_exiting = true;
|
||||
self.can_exit
|
||||
}
|
||||
|
||||
fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) {
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
ui.heading("Try to close the window");
|
||||
});
|
||||
|
||||
if self.is_exiting {
|
||||
egui::Window::new("Do you want to quit?")
|
||||
.collapsible(false)
|
||||
.resizable(false)
|
||||
.show(ctx, |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
if ui.button("Not yet").clicked() {
|
||||
self.is_exiting = false;
|
||||
}
|
||||
|
||||
if ui.button("Yes!").clicked() {
|
||||
self.can_exit = true;
|
||||
frame.quit();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user