cards/new, cards/edit and some improvements
This commit is contained in:
		
							
								
								
									
										0
									
								
								src/widgets/card_display/mod.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								src/widgets/card_display/mod.rs
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										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 {}
 | 
			
		||||
							
								
								
									
										17
									
								
								src/widgets/card_entry/mod.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								src/widgets/card_entry/mod.rs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,17 @@
 | 
			
		||||
mod imp;
 | 
			
		||||
 | 
			
		||||
use glib::Object;
 | 
			
		||||
use gtk::{gio, glib};
 | 
			
		||||
 | 
			
		||||
glib::wrapper! {
 | 
			
		||||
    pub struct CardEntry(ObjectSubclass<imp::CardEntry>)
 | 
			
		||||
        @extends gtk::Widget,
 | 
			
		||||
        @implements gio::ActionGroup, gio::ActionMap, gtk::Accessible, gtk::Buildable,
 | 
			
		||||
                    gtk::ConstraintTarget, gtk::Native, gtk::Root, gtk::ShortcutManager;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl CardEntry {
 | 
			
		||||
    pub fn new(hieroglyph: &String, translation: &String) -> Self {
 | 
			
		||||
        Object::builder().property("hieroglyph", hieroglyph).property("translation", translation).build()
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										52
									
								
								src/widgets/labled_switch/imp.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										52
									
								
								src/widgets/labled_switch/imp.rs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,52 @@
 | 
			
		||||
use std::cell::RefCell;
 | 
			
		||||
 | 
			
		||||
use glib::subclass::InitializingObject;
 | 
			
		||||
use glib::Properties;
 | 
			
		||||
use gtk::subclass::prelude::*;
 | 
			
		||||
use gtk::{glib, prelude::*, CompositeTemplate, Label, Switch};
 | 
			
		||||
 | 
			
		||||
#[derive(CompositeTemplate, Properties, Default)]
 | 
			
		||||
#[properties(wrapper_type = super::LabledSwitch)]
 | 
			
		||||
#[template(resource = "/org/foxarmy/learn-hieroglyph/widgets/labled_switch/template.ui.xml")]
 | 
			
		||||
pub struct LabledSwitch {
 | 
			
		||||
    #[template_child]
 | 
			
		||||
    pub switch_obj: TemplateChild<Switch>,
 | 
			
		||||
    #[template_child]
 | 
			
		||||
    pub label_obj: TemplateChild<Label>,
 | 
			
		||||
    #[property(get, set)]
 | 
			
		||||
    label_text: RefCell<String>,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[glib::object_subclass]
 | 
			
		||||
impl ObjectSubclass for LabledSwitch {
 | 
			
		||||
    const NAME: &'static str = "LabledSwitch";
 | 
			
		||||
    type Type = super::LabledSwitch;
 | 
			
		||||
    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 LabledSwitch {
 | 
			
		||||
    fn constructed(&self) {
 | 
			
		||||
        self.parent_constructed();
 | 
			
		||||
 | 
			
		||||
        let l: &Label = self.label_obj.as_ref();
 | 
			
		||||
        self.obj()
 | 
			
		||||
            .bind_property("label_text", l, "label")
 | 
			
		||||
            .sync_create()
 | 
			
		||||
            .build();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fn dispose(&self) {
 | 
			
		||||
        self.dispose_template();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl WidgetImpl for LabledSwitch {}
 | 
			
		||||
							
								
								
									
										28
									
								
								src/widgets/labled_switch/mod.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								src/widgets/labled_switch/mod.rs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,28 @@
 | 
			
		||||
mod imp;
 | 
			
		||||
 | 
			
		||||
use glib::Object;
 | 
			
		||||
use gtk::{
 | 
			
		||||
    gio,
 | 
			
		||||
    glib::{self, subclass::types::ObjectSubclassIsExt},
 | 
			
		||||
    Label, Switch,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
glib::wrapper! {
 | 
			
		||||
    pub struct LabledSwitch(ObjectSubclass<imp::LabledSwitch>)
 | 
			
		||||
        @extends gtk::Widget,
 | 
			
		||||
        @implements gio::ActionGroup, gio::ActionMap, gtk::Accessible, gtk::Buildable,
 | 
			
		||||
                    gtk::ConstraintTarget, gtk::Native, gtk::Root, gtk::ShortcutManager;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl LabledSwitch {
 | 
			
		||||
    pub fn new(label: &String) -> Self {
 | 
			
		||||
        Object::builder().property("label_text", label).build()
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn get_switch(&self) -> &Switch {
 | 
			
		||||
        self.imp().switch_obj.as_ref()
 | 
			
		||||
    }
 | 
			
		||||
    pub fn get_label(&self) -> &Label {
 | 
			
		||||
        self.imp().label_obj.as_ref()
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										3
									
								
								src/widgets/mod.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								src/widgets/mod.rs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,3 @@
 | 
			
		||||
pub mod labled_switch;
 | 
			
		||||
pub mod card_entry;
 | 
			
		||||
pub mod card_display;
 | 
			
		||||
		Reference in New Issue
	
	Block a user