layout and fix
This commit is contained in:
		@@ -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<Picture>,
 | 
			
		||||
    #[template_child]
 | 
			
		||||
    pub answer_entry: TemplateChild<Entry>,
 | 
			
		||||
    #[template_child]
 | 
			
		||||
    pub error_message: TemplateChild<Label>,
 | 
			
		||||
    #[property(get, set)]
 | 
			
		||||
    pub imagepath: RefCell<String>,
 | 
			
		||||
    #[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) {
 | 
			
		||||
 
 | 
			
		||||
@@ -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<String>, &RefCell<String>) {
 | 
			
		||||
    pub fn generate_card(&self) -> Option<(&RefCell<String>, &RefCell<String>)> {
 | 
			
		||||
        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 {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user