1
0
mirror of https://github.com/emilk/egui.git synced 2026-06-26 22:53:14 -04:00

eframe: rename quit/exit to "close" (#1943)

Since https://github.com/emilk/egui/pull/1919 we can continue
the application after closing the native window. It therefore makes
more sense to call `frame.close()` to close the native window,
instead of `frame.quit()`.
This commit is contained in:
Emil Ernerfeldt
2022-08-20 16:08:59 +02:00
committed by GitHub
parent 2453756782
commit 127931ba45
8 changed files with 59 additions and 41 deletions

View File

@@ -13,14 +13,14 @@ fn main() {
#[derive(Default)]
struct MyApp {
can_exit: bool,
is_exiting: bool,
allowed_to_close: bool,
show_confirmation_dialog: bool,
}
impl eframe::App for MyApp {
fn on_exit_event(&mut self) -> bool {
self.is_exiting = true;
self.can_exit
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) {
@@ -28,19 +28,20 @@ impl eframe::App for MyApp {
ui.heading("Try to close the window");
});
if self.is_exiting {
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("Not yet").clicked() {
self.is_exiting = false;
if ui.button("Cancel").clicked() {
self.show_confirmation_dialog = false;
}
if ui.button("Yes!").clicked() {
self.can_exit = true;
frame.quit();
self.allowed_to_close = true;
frame.close();
}
});
});

View File

@@ -89,7 +89,7 @@ fn custon_window_frame(
Button::new(RichText::new("").size(height - 4.0)).frame(false),
);
if close_response.clicked() {
frame.quit();
frame.close();
}
// Interact with the title bar (drag to move window):

View File

@@ -46,7 +46,7 @@ impl eframe::App for MyApp {
egui::CentralPanel::default().show(ctx, |ui| {
if ui.button("Close").clicked() {
eprintln!("Pressed Close button");
frame.quit();
frame.close();
}
});
}