mirror of
https://github.com/emilk/egui.git
synced 2026-06-26 22:53:14 -04:00
Fix up some examples (#3614)
This commit is contained in:
@@ -17,33 +17,38 @@ fn main() -> Result<(), eframe::Error> {
|
||||
|
||||
#[derive(Default)]
|
||||
struct MyApp {
|
||||
allowed_to_close: bool,
|
||||
show_confirmation_dialog: bool,
|
||||
allowed_to_close: bool,
|
||||
}
|
||||
|
||||
impl eframe::App for MyApp {
|
||||
fn on_close_event(&mut self) -> bool {
|
||||
self.show_confirmation_dialog = true;
|
||||
self.allowed_to_close
|
||||
}
|
||||
|
||||
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 ctx.input(|i| i.viewport().close_requested()) {
|
||||
if self.allowed_to_close {
|
||||
// do nothing - we will close
|
||||
} else {
|
||||
ctx.send_viewport_cmd(egui::ViewportCommand::CancelClose);
|
||||
self.show_confirmation_dialog = true;
|
||||
}
|
||||
}
|
||||
|
||||
if self.show_confirmation_dialog {
|
||||
// Show confirmation dialog:
|
||||
egui::Window::new("Do you want to quit?")
|
||||
.collapsible(false)
|
||||
.resizable(false)
|
||||
.show(ctx, |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
if ui.button("Cancel").clicked() {
|
||||
if ui.button("No").clicked() {
|
||||
self.show_confirmation_dialog = false;
|
||||
self.allowed_to_close = false;
|
||||
}
|
||||
|
||||
if ui.button("Yes!").clicked() {
|
||||
if ui.button("Yes").clicked() {
|
||||
self.show_confirmation_dialog = false;
|
||||
self.allowed_to_close = true;
|
||||
ui.ctx().send_viewport_cmd(egui::ViewportCommand::Close);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user