no new windows
This commit is contained in:
@@ -28,6 +28,8 @@ pub struct MemoryCardsEditScene {
|
||||
pub cards_container: TemplateChild<Box>,
|
||||
#[template_child]
|
||||
pub cards_scrolled_window: TemplateChild<ScrolledWindow>,
|
||||
#[template_child]
|
||||
pub back_button: TemplateChild<Button>,
|
||||
|
||||
displaying_cards: RefCell<Vec<CardEntry>>
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
mod imp;
|
||||
use glib::Object;
|
||||
use gtk::{gio, glib, Application};
|
||||
use gtk::{gio, glib::{self, subclass::types::ObjectSubclassIsExt}, Application, Button};
|
||||
|
||||
glib::wrapper! {
|
||||
pub struct MemoryCardsEditScene(ObjectSubclass<imp::MemoryCardsEditScene>)
|
||||
@@ -13,4 +13,12 @@ impl MemoryCardsEditScene {
|
||||
pub fn new(app: &Application) -> Self {
|
||||
Object::builder().property("application", app).build()
|
||||
}
|
||||
|
||||
pub fn get_add_button(&self) -> &Button {
|
||||
self.imp().add_button.as_ref()
|
||||
}
|
||||
|
||||
pub fn get_back_button(&self) -> &Button {
|
||||
self.imp().back_button.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@ use crate::widgets::card_display::*;
|
||||
use glib::subclass::InitializingObject;
|
||||
use gtk::glib::clone;
|
||||
use gtk::subclass::prelude::*;
|
||||
use gtk::{glib, Box, Button, CompositeTemplate, Label};
|
||||
use gtk::{prelude::*, Entry};
|
||||
use gtk::{glib, CompositeTemplate, Label, Box};
|
||||
|
||||
#[derive(CompositeTemplate, Default)]
|
||||
#[template(resource = "/org/foxarmy/learn-hieroglyph/cards/game/ui.xml")]
|
||||
@@ -17,9 +17,13 @@ pub struct MemoryCardsGameScene {
|
||||
pub stats_label: TemplateChild<Label>,
|
||||
#[template_child]
|
||||
pub content: TemplateChild<Box>,
|
||||
#[template_child]
|
||||
pub no_cards_label: TemplateChild<Label>,
|
||||
#[template_child]
|
||||
pub back_button: TemplateChild<Button>,
|
||||
|
||||
pub correct: RefCell<usize>,
|
||||
pub incorrect: RefCell<usize>
|
||||
pub incorrect: RefCell<usize>,
|
||||
}
|
||||
|
||||
#[glib::object_subclass]
|
||||
@@ -44,18 +48,9 @@ impl ObjectImpl for MemoryCardsGameScene {
|
||||
let card_display_binding = self.card_display.imp().obj();
|
||||
let self_binding = self.obj();
|
||||
|
||||
match card_display_binding.generate_card() {
|
||||
Some(_) => (),
|
||||
None => {
|
||||
while self.content.first_child() != None {
|
||||
self.content.remove(&self.content.first_child().unwrap());
|
||||
}
|
||||
self.content.append(&Label::builder().label("No cards found. Please, add some.").build());
|
||||
return
|
||||
}
|
||||
};
|
||||
|
||||
card_display_binding.get_answer_entry().connect_activate(clone!(@strong card_display_binding, @strong self_binding => move |e: &Entry| {
|
||||
self_binding.update_card_list();
|
||||
|
||||
card_display_binding.get_answer_entry().connect_activate(clone!(@strong card_display_binding, @strong self_binding => move |e: &Entry| {
|
||||
println!("{}", e.text());
|
||||
println!("{} = {}? -> {}", e.text(), card_display_binding.get_hieroglyph(), e.text().to_string() == *card_display_binding.get_hieroglyph());
|
||||
if e.text() == *card_display_binding.get_hieroglyph() {
|
||||
@@ -64,7 +59,7 @@ impl ObjectImpl for MemoryCardsGameScene {
|
||||
*self_binding.imp().incorrect.borrow_mut() +=1;
|
||||
}
|
||||
self_binding.update_stats();
|
||||
card_display_binding.generate_card();
|
||||
self_binding.update_card_list();
|
||||
e.set_text("");
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
|
||||
mod imp;
|
||||
|
||||
use glib::Object;
|
||||
use gtk::{gio, glib::{self, subclass::types::ObjectSubclassIsExt}, Application};
|
||||
use gtk::{
|
||||
gio, glib::{self, subclass::types::ObjectSubclassIsExt}, prelude::*, Application, Button
|
||||
};
|
||||
|
||||
glib::wrapper! {
|
||||
pub struct MemoryCardsGameScene(ObjectSubclass<imp::MemoryCardsGameScene>)
|
||||
@@ -21,15 +22,30 @@ impl MemoryCardsGameScene {
|
||||
// }
|
||||
|
||||
pub fn update_stats(&self) {
|
||||
self.imp().stats_label.set_text(&format!("Correct|Incorrect: {}|{}", self.imp().correct.borrow(), self.imp().incorrect.borrow()));
|
||||
self.imp().stats_label.set_text(&format!(
|
||||
"Correct|Incorrect: {}|{}",
|
||||
self.imp().correct.borrow(),
|
||||
self.imp().incorrect.borrow()
|
||||
));
|
||||
}
|
||||
|
||||
// pub fn get_stats(&self) -> (usize, usize) {
|
||||
// (self.imp().correct, self.imp().incorrect)
|
||||
// }
|
||||
pub fn get_back_button(&self) -> &Button {
|
||||
self.imp().back_button.as_ref()
|
||||
}
|
||||
|
||||
// pub fn set_stats(&self, correct: usize, incorrect: usize) {
|
||||
// self.imp().correct = correct;
|
||||
// self.imp().incorrect = incorrect;
|
||||
// }
|
||||
pub fn update_card_list(&self) {
|
||||
match self.imp().card_display.generate_card() {
|
||||
Some(_) => {
|
||||
self.imp().card_display.set_visible(true);
|
||||
self.imp().stats_label.set_visible(true);
|
||||
self.imp().no_cards_label.set_visible(false);
|
||||
self.imp().card_display.generate_card();
|
||||
},
|
||||
None => {
|
||||
self.imp().card_display.set_visible(false);
|
||||
self.imp().stats_label.set_visible(false);
|
||||
self.imp().no_cards_label.set_visible(true);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,8 @@ pub struct MemoryCardsSetupScene {
|
||||
pub edit_button: TemplateChild<Button>,
|
||||
#[template_child]
|
||||
pub start_button: TemplateChild<Button>,
|
||||
#[template_child]
|
||||
pub back_button: TemplateChild<Button>,
|
||||
}
|
||||
|
||||
#[glib::object_subclass]
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
mod imp;
|
||||
|
||||
use glib::Object;
|
||||
use gtk::{gio, glib, Application};
|
||||
use gtk::{gio, glib::{self, subclass::types::ObjectSubclassIsExt}, Application, Button};
|
||||
|
||||
glib::wrapper! {
|
||||
pub struct MemoryCardsSetupScene(ObjectSubclass<imp::MemoryCardsSetupScene>)
|
||||
@@ -14,4 +14,16 @@ impl MemoryCardsSetupScene {
|
||||
pub fn new(app: &Application) -> Self {
|
||||
Object::builder().property("application", app).build()
|
||||
}
|
||||
|
||||
pub fn get_edit_button(&self) -> &Button {
|
||||
self.imp().edit_button.as_ref()
|
||||
}
|
||||
|
||||
pub fn get_start_button(&self) -> &Button {
|
||||
self.imp().start_button.as_ref()
|
||||
}
|
||||
|
||||
pub fn get_back_button(&self) -> &Button {
|
||||
self.imp().back_button.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user