cards preview are now displaying, some improvements and renaming

This commit is contained in:
2024-04-06 02:06:25 +03:00
parent 8d17e4e474
commit fa260bb8f5
10 changed files with 158 additions and 70 deletions

View File

@@ -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();
}