2022-01-17 17:45:09 +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;
|
|
|
|
|
2022-12-14 16:29:54 +00:00
|
|
|
fn main() -> Result<(), eframe::Error> {
|
2022-12-04 16:27:40 +00:00
|
|
|
let options = eframe::NativeOptions {
|
|
|
|
initial_window_size: Some(egui::vec2(320.0, 240.0)),
|
|
|
|
..Default::default()
|
|
|
|
};
|
2022-03-18 13:23:07 +00:00
|
|
|
eframe::run_native(
|
|
|
|
"Confirm exit",
|
|
|
|
options,
|
|
|
|
Box::new(|_cc| Box::new(MyApp::default())),
|
2022-12-12 14:16:32 +00:00
|
|
|
)
|
2022-03-16 14:39:48 +00:00
|
|
|
}
|
2022-01-17 17:45:09 +00:00
|
|
|
|
|
|
|
#[derive(Default)]
|
|
|
|
struct MyApp {
|
2022-08-20 14:08:59 +00:00
|
|
|
allowed_to_close: bool,
|
|
|
|
show_confirmation_dialog: bool,
|
2022-01-17 17:45:09 +00:00
|
|
|
}
|
|
|
|
|
2022-03-16 14:39:48 +00:00
|
|
|
impl eframe::App for MyApp {
|
2022-08-20 14:08:59 +00:00
|
|
|
fn on_close_event(&mut self) -> bool {
|
|
|
|
self.show_confirmation_dialog = true;
|
|
|
|
self.allowed_to_close
|
2022-01-17 17:45:09 +00:00
|
|
|
}
|
|
|
|
|
2022-03-25 20:19:31 +00:00
|
|
|
fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) {
|
2022-01-17 17:45:09 +00:00
|
|
|
egui::CentralPanel::default().show(ctx, |ui| {
|
|
|
|
ui.heading("Try to close the window");
|
|
|
|
});
|
|
|
|
|
2022-08-20 14:08:59 +00:00
|
|
|
if self.show_confirmation_dialog {
|
|
|
|
// Show confirmation dialog:
|
2022-01-17 17:45:09 +00:00
|
|
|
egui::Window::new("Do you want to quit?")
|
|
|
|
.collapsible(false)
|
|
|
|
.resizable(false)
|
|
|
|
.show(ctx, |ui| {
|
|
|
|
ui.horizontal(|ui| {
|
2022-08-20 14:08:59 +00:00
|
|
|
if ui.button("Cancel").clicked() {
|
|
|
|
self.show_confirmation_dialog = false;
|
2022-04-13 14:13:24 +00:00
|
|
|
}
|
|
|
|
|
2022-01-17 17:45:09 +00:00
|
|
|
if ui.button("Yes!").clicked() {
|
2022-08-20 14:08:59 +00:00
|
|
|
self.allowed_to_close = true;
|
|
|
|
frame.close();
|
2022-01-17 17:45:09 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|