diff --git a/resources/cards/edit/ui.xml b/resources/cards/edit/ui.xml index e3d2dc4..cafe7e9 100644 --- a/resources/cards/edit/ui.xml +++ b/resources/cards/edit/ui.xml @@ -38,6 +38,14 @@ true + GTK_ALIGN_FILL + GTK_ALIGN_FILL + vertical + true + true + true + true + true vertical GTK_ALIGN_FILL GTK_ALIGN_FILL diff --git a/resources/cards/game/ui.xml b/resources/cards/game/ui.xml index 58860c0..11e44f8 100644 --- a/resources/cards/game/ui.xml +++ b/resources/cards/game/ui.xml @@ -5,6 +5,7 @@ vertical + GTK_ALIGN_CENTER diff --git a/resources/cards/new/ui.xml b/resources/cards/new/ui.xml index 71de52a..c82d635 100644 --- a/resources/cards/new/ui.xml +++ b/resources/cards/new/ui.xml @@ -6,9 +6,6 @@ 512 - vertical - GTK_ALIGN_CENTER - GTK_ALIGN_CENTER GTK_ALIGN_CENTER diff --git a/resources/widgets/card_display/template.ui.xml b/resources/widgets/card_display/template.ui.xml index 2a87297..764051e 100644 --- a/resources/widgets/card_display/template.ui.xml +++ b/resources/widgets/card_display/template.ui.xml @@ -7,6 +7,12 @@ GTK_ALIGN_CENTER + + + false + No card image found in database. If you think this is an error, please, create an issue. + + GTK_ALIGN_CENTER diff --git a/resources/widgets/card_entry/template.ui.xml b/resources/widgets/card_entry/template.ui.xml index 6d8fffe..035095d 100644 --- a/resources/widgets/card_entry/template.ui.xml +++ b/resources/widgets/card_entry/template.ui.xml @@ -3,26 +3,26 @@ - GTK_ALIGN_CENTER + GTK_ALIGN_START GTK_ALIGN_CENTER GTK_ALIGN_START - GTK_ALIGN_START + GTK_ALIGN_CENTER GTK_ALIGN_START - GTK_ALIGN_START + GTK_ALIGN_CENTER GTK_ALIGN_END - GTK_ALIGN_END + GTK_ALIGN_CENTER delete diff --git a/src/ui/cards/edit/imp.rs b/src/ui/cards/edit/imp.rs index 133f735..58555f0 100644 --- a/src/ui/cards/edit/imp.rs +++ b/src/ui/cards/edit/imp.rs @@ -84,7 +84,7 @@ impl ObjectImpl for MemoryCardsEditScene { ); binding.imp().update_card_list(); })); - self.update_card_list(); + // self.update_card_list(); } } @@ -139,8 +139,10 @@ impl MemoryCardsEditScene { let connection = Connection::open(get_db_path()).unwrap(); let imagepath = card.imagepath(); let imagename = &Path::new(&imagepath).file_name().unwrap().to_str().unwrap(); + dbg!("removing {}", imagename); fs::remove_file(get_images_store_path() + "/" + &imagename).expect("Could not remove file!"); connection.execute("DELETE FROM cards WHERE imagename = ?1", [&imagename]).unwrap(); + self_binding.imp().query_cards(None); self_binding.imp().update_card_list(); })); card.update_file_for_picture(); diff --git a/src/widgets/card_display/imp.rs b/src/widgets/card_display/imp.rs index 59c6a6c..152406a 100644 --- a/src/widgets/card_display/imp.rs +++ b/src/widgets/card_display/imp.rs @@ -3,7 +3,7 @@ use std::cell::RefCell; use glib::subclass::InitializingObject; use glib::Properties; use gtk::subclass::prelude::*; -use gtk::{glib, prelude::*, BoxLayout, CompositeTemplate, Entry, Picture}; +use gtk::{glib, prelude::*, BoxLayout, CompositeTemplate, Entry, Label, Picture}; #[derive(CompositeTemplate, Properties, Default)] #[properties(wrapper_type = super::CardDisplay)] @@ -13,6 +13,8 @@ pub struct CardDisplay { pub picture: TemplateChild, #[template_child] pub answer_entry: TemplateChild, + #[template_child] + pub error_message: TemplateChild, #[property(get, set)] pub imagepath: RefCell, #[property(get, set)] @@ -42,6 +44,10 @@ impl ObjectImpl for CardDisplay { let layout_manager: BoxLayout = BoxLayout::new(gtk::Orientation::Vertical); self.obj().set_layout_manager(Some(layout_manager)); + self.picture.set_width_request(256); + self.picture.set_height_request(256); + // self.picture. + // self.picture.set } fn dispose(&self) { diff --git a/src/widgets/card_display/mod.rs b/src/widgets/card_display/mod.rs index d8d51d0..a658f66 100644 --- a/src/widgets/card_display/mod.rs +++ b/src/widgets/card_display/mod.rs @@ -3,7 +3,7 @@ mod imp; use std::cell::RefCell; use glib::Object; -use gtk::{gio, glib::{self, subclass::types::ObjectSubclassIsExt}, Entry, Picture}; +use gtk::{gio, glib::{self, subclass::types::ObjectSubclassIsExt}, prelude::*, Entry, Picture}; use rusqlite::Connection; use crate::db::{get_db_path, get_images_store_path}; @@ -32,10 +32,13 @@ impl CardDisplay { pub fn update_file_for_picture(&self) { let picture_binding: &Picture = self.imp().picture.as_ref(); let path: &str = &*self.imp().imagepath.borrow().clone().to_string(); + if path == "" { + self.imp().error_message.set_visible(true); + return; + } picture_binding.set_file(Some(&gio::File::for_path(path))); } - - pub fn generate_card(&self) -> (&RefCell, &RefCell) { + pub fn generate_card(&self) -> Option<(&RefCell, &RefCell)> { let connection = Connection::open(get_db_path()).unwrap(); let mut stmt = connection.prepare("SELECT imagename, hieroglyph FROM cards ORDER BY RANDOM() LIMIT 1").unwrap(); @@ -52,14 +55,17 @@ impl CardDisplay { for i in random_card_iter { random_card = Some(i.unwrap()); } - let random_card: Card = random_card.unwrap(); + let random_card: Card = match random_card { + Some(card) => card, + None => return None + }; *self.imp().imagepath.borrow_mut() = get_images_store_path() + "/" + random_card.imagename.as_str(); *self.imp().hieroglyph.borrow_mut() = random_card.hieroglyph; self.update_file_for_picture(); - (&self.imp().imagepath, &self.imp().hieroglyph) + Some((&self.imp().imagepath, &self.imp().hieroglyph)) } pub fn get_answer_entry(&self) -> &Entry {