learn-hieroglyphs/src/widgets/card_display/imp.rs

53 lines
1.5 KiB
Rust
Raw Normal View History

2024-04-07 14:08:57 +03:00
use std::cell::RefCell;
use glib::subclass::InitializingObject;
use glib::Properties;
use gtk::subclass::prelude::*;
use gtk::{glib, prelude::*, BoxLayout, CompositeTemplate, Entry, Picture};
#[derive(CompositeTemplate, Properties, Default)]
#[properties(wrapper_type = super::CardDisplay)]
#[template(resource = "/org/foxarmy/learn-hieroglyph/widgets/card_display/template.ui.xml")]
pub struct CardDisplay {
#[template_child]
pub picture: TemplateChild<Picture>,
#[template_child]
pub answer_entry: TemplateChild<Entry>,
#[property(get, set)]
pub imagepath: RefCell<String>,
#[property(get, set)]
pub hieroglyph: RefCell<String>,
}
#[glib::object_subclass]
impl ObjectSubclass for CardDisplay {
const NAME: &'static str = "CardDisplay";
type Type = super::CardDisplay;
type ParentType = gtk::Widget;
fn class_init(klass: &mut Self::Class) {
klass.bind_template();
klass.set_layout_manager_type::<gtk::BoxLayout>();
// klass.set_layout_manager_type(a);
}
fn instance_init(obj: &InitializingObject<Self>) {
obj.init_template();
}
}
#[glib::derived_properties]
impl ObjectImpl for CardDisplay {
fn constructed(&self) {
self.parent_constructed();
let layout_manager: BoxLayout = BoxLayout::new(gtk::Orientation::Vertical);
self.obj().set_layout_manager(Some(layout_manager));
}
fn dispose(&self) {
self.dispose_template();
}
}
impl WidgetImpl for CardDisplay {}