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

62 lines
1.8 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::*;
2024-04-09 16:42:13 +03:00
use gtk::{glib, prelude::*, BoxLayout, CompositeTemplate, Entry, Label, Image};
2024-04-07 14:08:57 +03:00
#[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]
2024-04-09 16:42:13 +03:00
pub image: TemplateChild<Image>,
2024-04-07 14:08:57 +03:00
#[template_child]
pub answer_entry: TemplateChild<Entry>,
2024-04-08 16:34:14 +03:00
#[template_child]
pub error_message: TemplateChild<Label>,
2024-05-03 01:23:29 +03:00
#[template_child]
pub incorrect_message: TemplateChild<Label>,
2024-04-07 14:08:57 +03:00
#[property(get, set)]
pub imagepath: RefCell<String>,
#[property(get, set)]
pub hieroglyph: RefCell<String>,
2024-05-03 01:23:29 +03:00
#[property(get, set)]
pub reading: RefCell<String>,
#[property(get, set)]
pub translation: RefCell<String>,
2024-04-07 14:08:57 +03:00
}
#[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>();
}
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));
2024-04-09 16:42:13 +03:00
self.image.set_width_request(256);
self.image.set_height_request(256);
2024-04-07 14:08:57 +03:00
}
fn dispose(&self) {
self.dispose_template();
}
}
impl WidgetImpl for CardDisplay {}