cards/new, cards/edit and some improvements
This commit is contained in:
67
src/widgets/card_entry/imp.rs
Normal file
67
src/widgets/card_entry/imp.rs
Normal file
@@ -0,0 +1,67 @@
|
||||
use std::cell::RefCell;
|
||||
|
||||
use glib::subclass::InitializingObject;
|
||||
use glib::Properties;
|
||||
use gtk::subclass::prelude::*;
|
||||
use gtk::{glib, prelude::*, Button, CompositeTemplate, Label, Picture};
|
||||
|
||||
#[derive(CompositeTemplate, Properties, Default)]
|
||||
#[properties(wrapper_type = super::CardEntry)]
|
||||
#[template(resource = "/org/foxarmy/learn-hieroglyph/widgets/card_entry/template.ui.xml")]
|
||||
pub struct CardEntry {
|
||||
#[template_child]
|
||||
pub picture: TemplateChild<Picture>,
|
||||
#[template_child]
|
||||
pub hieroglyph_label: TemplateChild<Label>,
|
||||
#[template_child]
|
||||
pub translation_label: TemplateChild<Label>,
|
||||
#[template_child]
|
||||
pub edit_button: TemplateChild<Button>,
|
||||
|
||||
#[property(get, set)]
|
||||
image_hash: RefCell<String>,
|
||||
#[property(get, set)]
|
||||
hieroglyph: RefCell<String>,
|
||||
#[property(get, set)]
|
||||
translation: RefCell<String>,
|
||||
}
|
||||
|
||||
#[glib::object_subclass]
|
||||
impl ObjectSubclass for CardEntry {
|
||||
const NAME: &'static str = "CardEntry";
|
||||
type Type = super::CardEntry;
|
||||
type ParentType = gtk::Widget;
|
||||
|
||||
fn class_init(klass: &mut Self::Class) {
|
||||
klass.bind_template();
|
||||
klass.set_layout_manager_type::<gtk::BoxLayout>();
|
||||
}
|
||||
|
||||
fn instance_init(obj: &InitializingObject<Self>) {
|
||||
obj.init_template();
|
||||
}
|
||||
}
|
||||
#[glib::derived_properties]
|
||||
impl ObjectImpl for CardEntry {
|
||||
fn constructed(&self) {
|
||||
self.parent_constructed();
|
||||
|
||||
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();
|
||||
self.obj()
|
||||
.bind_property("translation", translation_label_binding, "label")
|
||||
.sync_create()
|
||||
.build();
|
||||
}
|
||||
|
||||
fn dispose(&self) {
|
||||
self.dispose_template();
|
||||
}
|
||||
}
|
||||
|
||||
impl WidgetImpl for CardEntry {}
|
||||
Reference in New Issue
Block a user