Add no cards notification
This commit is contained in:
		@@ -174,7 +174,6 @@ async fn file_choose_dialog<W: IsA<gtk::Window>>(window: Rc<W>) {
 | 
			
		||||
            _ => panic!("Could not create directory for storing images!"),
 | 
			
		||||
        },
 | 
			
		||||
    };
 | 
			
		||||
    println!("Setting handler");
 | 
			
		||||
    w.get_done_button().connect_closure(
 | 
			
		||||
        "clicked",
 | 
			
		||||
        false,
 | 
			
		||||
@@ -189,8 +188,6 @@ async fn file_choose_dialog<W: IsA<gtk::Window>>(window: Rc<W>) {
 | 
			
		||||
            let reading = w.get_reading_input();
 | 
			
		||||
            let conn = Connection::open(get_db_path()).unwrap();
 | 
			
		||||
 | 
			
		||||
            println!("INSERTING NEW IMAGE");
 | 
			
		||||
 | 
			
		||||
            let query = "INSERT INTO cards (imagename, hieroglyph, reading) VALUES(?1, ?2, ?3)";
 | 
			
		||||
            conn.execute(query, (&new_filename, &hieroglyph, &reading)).unwrap();      
 | 
			
		||||
            w.close();
 | 
			
		||||
 
 | 
			
		||||
@@ -6,7 +6,7 @@ use glib::subclass::InitializingObject;
 | 
			
		||||
use gtk::glib::clone;
 | 
			
		||||
use gtk::subclass::prelude::*;
 | 
			
		||||
use gtk::{prelude::*, Entry};
 | 
			
		||||
use gtk::{glib, CompositeTemplate, Label};
 | 
			
		||||
use gtk::{glib, CompositeTemplate, Label, Box};
 | 
			
		||||
 | 
			
		||||
#[derive(CompositeTemplate, Default)]
 | 
			
		||||
#[template(resource = "/org/foxarmy/learn-hieroglyph/cards/game/ui.xml")]
 | 
			
		||||
@@ -15,6 +15,8 @@ pub struct MemoryCardsGameScene {
 | 
			
		||||
    pub card_display: TemplateChild<CardDisplay>,
 | 
			
		||||
    #[template_child]
 | 
			
		||||
    pub stats_label: TemplateChild<Label>,
 | 
			
		||||
    #[template_child]
 | 
			
		||||
    pub content: TemplateChild<Box>,
 | 
			
		||||
 | 
			
		||||
    pub correct: RefCell<usize>,
 | 
			
		||||
    pub incorrect: RefCell<usize>
 | 
			
		||||
@@ -42,7 +44,17 @@ impl ObjectImpl for MemoryCardsGameScene {
 | 
			
		||||
        let card_display_binding = self.card_display.imp().obj();
 | 
			
		||||
        let self_binding = self.obj();
 | 
			
		||||
 | 
			
		||||
        card_display_binding.generate_card();
 | 
			
		||||
        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| {
 | 
			
		||||
            println!("{}", e.text());
 | 
			
		||||
            println!("{} = {}? -> {}", e.text(), card_display_binding.get_hieroglyph(), e.text().to_string() == *card_display_binding.get_hieroglyph());
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user