mirror of
https://github.com/hinto-janai/gupax.git
synced 2024-11-16 17:27:37 +00:00
main: fix closing
This commit is contained in:
parent
62865f7c41
commit
a51234d353
1 changed files with 13 additions and 4 deletions
17
src/main.rs
17
src/main.rs
|
@ -1191,26 +1191,35 @@ impl eframe::App for App {
|
|||
|
||||
// If closing.
|
||||
// Used to be `eframe::App::on_close_event(&mut self) -> bool`.
|
||||
ctx.input(|input| {
|
||||
let close_signal = ctx.input(|input| {
|
||||
use egui::viewport::ViewportCommand;
|
||||
|
||||
if !input.viewport().close_requested() {
|
||||
return;
|
||||
return None;
|
||||
}
|
||||
if self.state.gupax.ask_before_quit {
|
||||
// If we're already on the [ask_before_quit] screen and
|
||||
// the user tried to exit again, exit.
|
||||
if self.error_state.quit_twice {
|
||||
if self.state.gupax.save_before_quit { self.save_before_quit(); }
|
||||
ctx.send_viewport_cmd(egui::viewport::ViewportCommand::Close);
|
||||
return Some(ViewportCommand::Close);
|
||||
}
|
||||
// Else, set the error
|
||||
self.error_state.set("", ErrorFerris::Oops, ErrorButtons::StayQuit);
|
||||
self.error_state.quit_twice = true;
|
||||
Some(ViewportCommand::CancelClose)
|
||||
// Else, just quit.
|
||||
} else {
|
||||
if self.state.gupax.save_before_quit { self.save_before_quit(); }
|
||||
ctx.send_viewport_cmd(egui::viewport::ViewportCommand::Close);
|
||||
Some(ViewportCommand::Close)
|
||||
}
|
||||
});
|
||||
// This will either:
|
||||
// 1. Cancel a close signal
|
||||
// 2. Close the program
|
||||
if let Some(cmd) = close_signal {
|
||||
ctx.send_viewport_cmd(cmd);
|
||||
}
|
||||
|
||||
// If [F11] was pressed, reverse [fullscreen] bool
|
||||
let key: KeyPressed = ctx.input_mut(|input| {
|
||||
|
|
Loading…
Reference in a new issue