implemented labled switch

This commit is contained in:
leca 2024-04-02 02:35:52 +03:00
parent d6b6c220b8
commit b01e248971
4 changed files with 33 additions and 7 deletions

View File

@ -6,8 +6,23 @@
<object class="GtkBox" id="content"> <object class="GtkBox" id="content">
<property name="orientation">vertical</property> <property name="orientation">vertical</property>
<child> <child>
<object class="LabledSwitch" id="hiragana-enable"> <object class="LabledSwitch" id="hiragana_enable">
<!-- <property name="label_text">Enable hiragana?</property> --> <property name="label_text">Enable hiragana?</property>
</object>
</child>
<child>
<object class="LabledSwitch" id="katakana_enable">
<property name="label_text">Enable katakana?</property>
</object>
</child>
<child>
<object class="LabledSwitch" id="ktr_enable">
<property name="label_text">Enable kana to romaji?</property>
</object>
</child>
<child>
<object class="LabledSwitch" id="rtk_enable">
<property name="label_text">Enable romaji to kana?</property>
</object> </object>
</child> </child>
</object> </object>

View File

@ -1,15 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<interface> <interface>
<template class="LabledSwitch" parent="GtkWidget"> <template class="LabledSwitch" parent="GtkWidget">
<!-- <property name="layout-managet">GtkBoxLayout</property> --> <property name="label_text">placeholder</property>
<property name="label_text">Practice vocabulary with memory cards</property>
<child> <child>
<object class="GtkSwitch" id="switch_obj"> <object class="GtkSwitch" id="switch_obj">
</object> </object>
</child> </child>
<child> <child>
<object class="GtkLabel" id="label_obj"> <object class="GtkLabel" id="label_obj">
<property name="label">There's a question:</property>
</object> </object>
</child> </child>
</template> </template>

View File

@ -25,17 +25,22 @@ impl ObjectSubclass for LabledSwitch {
fn class_init(klass: &mut Self::Class) { fn class_init(klass: &mut Self::Class) {
klass.bind_template(); klass.bind_template();
klass.set_layout_manager_type::<gtk::BoxLayout>();
} }
fn instance_init(obj: &InitializingObject<Self>) { fn instance_init(obj: &InitializingObject<Self>) {
obj.init_template(); obj.init_template();
} }
} }
#[glib::derived_properties]
impl ObjectImpl for LabledSwitch { impl ObjectImpl for LabledSwitch {
fn constructed(&self) { fn constructed(&self) {
self.parent_constructed(); self.parent_constructed();
// let a = LayoutManager:: ;
// self.obj().set_layout_manager(a);
let l: &Label = self.label_obj.as_ref(); let l: &Label = self.label_obj.as_ref();
self.obj().bind_property("label_text", l, "label").sync_create().build(); self.obj().bind_property("label_text", l, "label").sync_create().build();
} }

View File

@ -10,7 +10,13 @@ use gtk::{glib, CompositeTemplate};
#[template(resource = "/org/foxarmy/learn-hieroglyph/guessing/setup/ui.xml")] #[template(resource = "/org/foxarmy/learn-hieroglyph/guessing/setup/ui.xml")]
pub struct GuessingSetupScene { pub struct GuessingSetupScene {
#[template_child] #[template_child]
pub question_label: TemplateChild<LabledSwitch>, pub hiragana_enable: TemplateChild<LabledSwitch>,
#[template_child]
pub katakana_enable: TemplateChild<LabledSwitch>,
#[template_child]
pub ktr_enable: TemplateChild<LabledSwitch>,
#[template_child]
pub rtk_enable: TemplateChild<LabledSwitch>,
} }
#[glib::object_subclass] #[glib::object_subclass]
@ -31,6 +37,8 @@ impl ObjectSubclass for GuessingSetupScene {
impl ObjectImpl for GuessingSetupScene { impl ObjectImpl for GuessingSetupScene {
fn constructed(&self) { fn constructed(&self) {
self.parent_constructed(); self.parent_constructed();
//TODO: tie switches to settings and make "start" button
} }
} }