cleanup & closing app on window close
This commit is contained in:
parent
7dc2089baf
commit
dc40fbff7b
57
src/main.rs
57
src/main.rs
|
@ -6,11 +6,10 @@ mod widgets;
|
|||
use crate::ui::menu::MenuScene;
|
||||
|
||||
use gtk::glib::closure_local;
|
||||
use gtk::prelude::*;
|
||||
use gtk::{prelude::*, Window};
|
||||
use gtk::{gio, glib, Application, Button};
|
||||
use ui::cards::edit::MemoryCardsEditScene;
|
||||
use ui::cards::game::MemoryCardsGameScene;
|
||||
use ui::cards::new::MemoryCardsNewScene;
|
||||
use ui::cards::setup::MemoryCardsSetupScene;
|
||||
use ui::guessing::game::GuessingScene;
|
||||
use ui::guessing::setup::GuessingSetupScene;
|
||||
|
@ -24,7 +23,6 @@ enum AppWindow {
|
|||
MemoryCardsSetupScene = 4,
|
||||
MemoryCardsEditScene = 5,
|
||||
MemoryCardsGameScene = 6,
|
||||
// MemoryCardsNewScene = 7,
|
||||
}
|
||||
|
||||
const APP_ID: &str = "org.foxarmy.learn-hieroglyph";
|
||||
|
@ -59,7 +57,6 @@ fn build_ui(app: &Application) {
|
|||
let memory_cards_setup: MemoryCardsSetupScene = MemoryCardsSetupScene::new(app); // 4
|
||||
let memory_cards_edit: MemoryCardsEditScene = MemoryCardsEditScene::new(app); // 5
|
||||
let memory_cards_game: MemoryCardsGameScene = MemoryCardsGameScene::new(app); // 6
|
||||
let _memory_cards_new: MemoryCardsNewScene = MemoryCardsNewScene::new(app); //7
|
||||
|
||||
menu.get_guessing_button().connect_closure(
|
||||
"clicked",
|
||||
|
@ -102,8 +99,17 @@ fn build_ui(app: &Application) {
|
|||
}
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
|
||||
guessing_scene.get_back_button().connect_closure(
|
||||
"clicked",
|
||||
false,
|
||||
closure_local!(
|
||||
@strong app => move |_b: &Button| {
|
||||
switch_to(&app, AppWindow::GuessingSetupScene);
|
||||
}
|
||||
),
|
||||
);
|
||||
|
||||
memory_cards_setup.get_edit_button().connect_closure(
|
||||
"clicked",
|
||||
false,
|
||||
|
@ -156,32 +162,19 @@ fn build_ui(app: &Application) {
|
|||
);
|
||||
|
||||
|
||||
guessing_scene.get_back_button().connect_closure(
|
||||
"clicked",
|
||||
false,
|
||||
closure_local!(
|
||||
@strong app => move |_b: &Button| {
|
||||
switch_to(&app, AppWindow::GuessingSetupScene);
|
||||
}
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
// memory_cards_edit.get_add_button().connect_closure(
|
||||
// "clicked",
|
||||
// false,
|
||||
// closure_local!(
|
||||
// @strong app => move |_b: &Button| {
|
||||
// switch_to(&app, AppWindow::MemoryCardsNewScene);
|
||||
// hide_all_windows(&app);
|
||||
// app.window_by_id(7).unwrap().set_visible(true); // to memory card new scene
|
||||
// }
|
||||
// ),
|
||||
// );
|
||||
|
||||
|
||||
connect_close_requrest(app, menu.upcast_ref::<Window>());
|
||||
connect_close_requrest(app, guessing_setup.upcast_ref::<Window>());
|
||||
connect_close_requrest(app, guessing_scene.upcast_ref::<Window>());
|
||||
connect_close_requrest(app, memory_cards_setup.upcast_ref::<Window>());
|
||||
connect_close_requrest(app, memory_cards_edit.upcast_ref::<Window>());
|
||||
connect_close_requrest(app, memory_cards_game.upcast_ref::<Window>());
|
||||
|
||||
menu.present();
|
||||
}
|
||||
|
||||
fn connect_close_requrest<W: IsA<Window>>(app: &Application, w: &W) {
|
||||
w.connect_closure("close-request", false, closure_local!(@strong app => move |_w: &Window| {
|
||||
app.quit();
|
||||
true
|
||||
}));
|
||||
}
|
Loading…
Reference in New Issue