cards preview are now displaying, some improvements and renaming
This commit is contained in:
		@@ -1,7 +1,9 @@
 | 
			
		||||
use std::cell::RefCell;
 | 
			
		||||
use std::path::Path;
 | 
			
		||||
 | 
			
		||||
use glib::subclass::InitializingObject;
 | 
			
		||||
use glib::Properties;
 | 
			
		||||
use gtk::gio::File;
 | 
			
		||||
use gtk::subclass::prelude::*;
 | 
			
		||||
use gtk::{glib, prelude::*, Button, CompositeTemplate, Label, Picture};
 | 
			
		||||
 | 
			
		||||
@@ -14,16 +16,15 @@ pub struct CardEntry {
 | 
			
		||||
    #[template_child]
 | 
			
		||||
    pub hieroglyph_label: TemplateChild<Label>,
 | 
			
		||||
    #[template_child]
 | 
			
		||||
    pub translation_label: TemplateChild<Label>,
 | 
			
		||||
    pub reading_label: TemplateChild<Label>,
 | 
			
		||||
    #[template_child]
 | 
			
		||||
    pub edit_button: TemplateChild<Button>,
 | 
			
		||||
 | 
			
		||||
    #[property(get, set)]
 | 
			
		||||
    image_hash: RefCell<String>,
 | 
			
		||||
    imagepath: RefCell<String>,
 | 
			
		||||
    #[property(get, set)]
 | 
			
		||||
    hieroglyph: RefCell<String>,
 | 
			
		||||
    #[property(get, set)]
 | 
			
		||||
    translation: RefCell<String>,
 | 
			
		||||
    reading: RefCell<String>,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[glib::object_subclass]
 | 
			
		||||
@@ -46,15 +47,22 @@ impl ObjectImpl for CardEntry {
 | 
			
		||||
    fn constructed(&self) {
 | 
			
		||||
        self.parent_constructed();
 | 
			
		||||
 | 
			
		||||
        let picture_binding: &Picture = self.picture.as_ref();
 | 
			
		||||
        let picture_file: File =
 | 
			
		||||
            File::for_path(Path::new(&String::from(&*self.imagepath.borrow())));
 | 
			
		||||
        picture_binding.set_file(glib::bitflags::__private::core::option::Option::Some(
 | 
			
		||||
            &picture_file,
 | 
			
		||||
        ));
 | 
			
		||||
 | 
			
		||||
        let hieroglyph_label_binding: &Label = self.hieroglyph_label.as_ref();
 | 
			
		||||
        self.obj()
 | 
			
		||||
            .bind_property("hieroglyph", hieroglyph_label_binding, "label")
 | 
			
		||||
            .sync_create()
 | 
			
		||||
            .build();
 | 
			
		||||
 | 
			
		||||
        let translation_label_binding: &Label = self.translation_label.as_ref();
 | 
			
		||||
        let reading_label_binding: &Label = self.reading_label.as_ref();
 | 
			
		||||
        self.obj()
 | 
			
		||||
            .bind_property("translation", translation_label_binding, "label")
 | 
			
		||||
            .bind_property("reading", reading_label_binding, "label")
 | 
			
		||||
            .sync_create()
 | 
			
		||||
            .build();
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -1,7 +1,7 @@
 | 
			
		||||
mod imp;
 | 
			
		||||
 | 
			
		||||
use glib::Object;
 | 
			
		||||
use gtk::{gio, glib};
 | 
			
		||||
use gtk::{gio, glib::{self, subclass::types::ObjectSubclassIsExt}, Picture};
 | 
			
		||||
 | 
			
		||||
glib::wrapper! {
 | 
			
		||||
    pub struct CardEntry(ObjectSubclass<imp::CardEntry>)
 | 
			
		||||
@@ -11,7 +11,15 @@ glib::wrapper! {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl CardEntry {
 | 
			
		||||
    pub fn new(hieroglyph: &String, translation: &String) -> Self {
 | 
			
		||||
        Object::builder().property("hieroglyph", hieroglyph).property("translation", translation).build()
 | 
			
		||||
    pub fn new(image_path: &String, hieroglyph: &String, reading: &String) -> Self {
 | 
			
		||||
        Object::builder()
 | 
			
		||||
            .property("imagepath", image_path)
 | 
			
		||||
            .property("hieroglyph", hieroglyph)
 | 
			
		||||
            .property("reading", reading)
 | 
			
		||||
            .build()
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn get_picture_widget(&self) -> &Picture {
 | 
			
		||||
        self.imp().picture.as_ref()
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user