cleanup & closing app on window close

This commit is contained in:
leca 2024-04-11 15:19:35 +03:00
parent 7dc2089baf
commit dc40fbff7b
1 changed files with 25 additions and 32 deletions

View File

@ -6,11 +6,10 @@ mod widgets;
use crate::ui::menu::MenuScene; use crate::ui::menu::MenuScene;
use gtk::glib::closure_local; use gtk::glib::closure_local;
use gtk::prelude::*; use gtk::{prelude::*, Window};
use gtk::{gio, glib, Application, Button}; use gtk::{gio, glib, Application, Button};
use ui::cards::edit::MemoryCardsEditScene; use ui::cards::edit::MemoryCardsEditScene;
use ui::cards::game::MemoryCardsGameScene; use ui::cards::game::MemoryCardsGameScene;
use ui::cards::new::MemoryCardsNewScene;
use ui::cards::setup::MemoryCardsSetupScene; use ui::cards::setup::MemoryCardsSetupScene;
use ui::guessing::game::GuessingScene; use ui::guessing::game::GuessingScene;
use ui::guessing::setup::GuessingSetupScene; use ui::guessing::setup::GuessingSetupScene;
@ -24,7 +23,6 @@ enum AppWindow {
MemoryCardsSetupScene = 4, MemoryCardsSetupScene = 4,
MemoryCardsEditScene = 5, MemoryCardsEditScene = 5,
MemoryCardsGameScene = 6, MemoryCardsGameScene = 6,
// MemoryCardsNewScene = 7,
} }
const APP_ID: &str = "org.foxarmy.learn-hieroglyph"; 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_setup: MemoryCardsSetupScene = MemoryCardsSetupScene::new(app); // 4
let memory_cards_edit: MemoryCardsEditScene = MemoryCardsEditScene::new(app); // 5 let memory_cards_edit: MemoryCardsEditScene = MemoryCardsEditScene::new(app); // 5
let memory_cards_game: MemoryCardsGameScene = MemoryCardsGameScene::new(app); // 6 let memory_cards_game: MemoryCardsGameScene = MemoryCardsGameScene::new(app); // 6
let _memory_cards_new: MemoryCardsNewScene = MemoryCardsNewScene::new(app); //7
menu.get_guessing_button().connect_closure( menu.get_guessing_button().connect_closure(
"clicked", "clicked",
@ -103,6 +100,15 @@ 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( memory_cards_setup.get_edit_button().connect_closure(
"clicked", "clicked",
@ -156,32 +162,19 @@ fn build_ui(app: &Application) {
); );
guessing_scene.get_back_button().connect_closure( connect_close_requrest(app, menu.upcast_ref::<Window>());
"clicked", connect_close_requrest(app, guessing_setup.upcast_ref::<Window>());
false, connect_close_requrest(app, guessing_scene.upcast_ref::<Window>());
closure_local!( connect_close_requrest(app, memory_cards_setup.upcast_ref::<Window>());
@strong app => move |_b: &Button| { connect_close_requrest(app, memory_cards_edit.upcast_ref::<Window>());
switch_to(&app, AppWindow::GuessingSetupScene); connect_close_requrest(app, memory_cards_game.upcast_ref::<Window>());
}
),
);
// 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
// }
// ),
// );
menu.present(); 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
}));
}