diff options
| -rw-r--r-- | schist_gtk4_gui/resources/resources.gresource.xml | 3 | ||||
| -rw-r--r-- | schist_gtk4_gui/resources/ui/categories_view.ui | 10 | ||||
| -rw-r--r-- | schist_gtk4_gui/resources/ui/window.ui (renamed from schist_gtk4_gui/resources/window.ui) | 9 | ||||
| -rw-r--r-- | schist_gtk4_gui/src/categories_view.rs | 56 | ||||
| -rw-r--r-- | schist_gtk4_gui/src/lib.rs | 1 | ||||
| -rw-r--r-- | schist_gtk4_gui/src/window.rs | 14 |
6 files changed, 85 insertions, 8 deletions
diff --git a/schist_gtk4_gui/resources/resources.gresource.xml b/schist_gtk4_gui/resources/resources.gresource.xml index 30fdd9f..4b1b90d 100644 --- a/schist_gtk4_gui/resources/resources.gresource.xml +++ b/schist_gtk4_gui/resources/resources.gresource.xml @@ -1,7 +1,8 @@ <?xml version="1.0" encoding="UTF-8"?> <gresources> <gresource prefix="/net/joeac/schist/"> - <file compressed="true" preprocess="xml-stripblanks">window.ui</file> + <file compressed="true" preprocess="xml-stripblanks">ui/categories_view.ui</file> + <file compressed="true" preprocess="xml-stripblanks">ui/window.ui</file> <file compressed="true">css/styles.css</file> <file compressed="true">css/window.css</file> </gresource> diff --git a/schist_gtk4_gui/resources/ui/categories_view.ui b/schist_gtk4_gui/resources/ui/categories_view.ui new file mode 100644 index 0000000..197fcb3 --- /dev/null +++ b/schist_gtk4_gui/resources/ui/categories_view.ui @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="UTF-8"?> +<interface> + <template class="SchistCategoriesView" parent="GtkBox"> + <child> + <object class="GtkLabel"> + <property name="label">Hello, categories!</property> + </object> + </child> + </template> +</interface> diff --git a/schist_gtk4_gui/resources/window.ui b/schist_gtk4_gui/resources/ui/window.ui index 9d6a10d..2dcf4c8 100644 --- a/schist_gtk4_gui/resources/window.ui +++ b/schist_gtk4_gui/resources/ui/window.ui @@ -1,4 +1,4 @@ -<?xml version="1.0" encoding="UTF-8"?> +<?xml version="1.0" encoding="UTF-8" ?> <interface> <template class="SchistWindow" parent="GtkApplicationWindow"> <property name="title">schist</property> @@ -21,9 +21,10 @@ <property name="name">categories</property> <property name="title">Categories</property> <property name="child"> - <object class="GtkLabel"> - <property name="label">Hello, categories!</property> - </object> + <object + class="SchistCategoriesView" + id="categories_view" + /> </property> </object> </child> diff --git a/schist_gtk4_gui/src/categories_view.rs b/schist_gtk4_gui/src/categories_view.rs new file mode 100644 index 0000000..efad621 --- /dev/null +++ b/schist_gtk4_gui/src/categories_view.rs @@ -0,0 +1,56 @@ +use gtk::{ + glib::{ + self, + subclass::{ + object::{ObjectImpl, ObjectImplExt}, + types::ObjectSubclass, + InitializingObject, + }, + Object, + }, + subclass::{ + box_::BoxImpl, + widget::{CompositeTemplateClass, CompositeTemplateInitializingExt, WidgetImpl}, + }, +}; + +glib::wrapper! { + pub struct SchistCategoriesView(ObjectSubclass<SchistCategoriesViewImpl>) + @extends gtk::Box, gtk::Widget, + @implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget, gtk::Orientable; +} + +impl SchistCategoriesView { + pub fn new() -> Self { + Object::builder().build() + } +} + +#[derive(gtk::CompositeTemplate, Default)] +#[template(resource = "/net/joeac/schist/ui/categories_view.ui")] +pub struct SchistCategoriesViewImpl {} + +#[glib::object_subclass] +impl ObjectSubclass for SchistCategoriesViewImpl { + const NAME: &'static str = "SchistCategoriesView"; + type Type = SchistCategoriesView; + type ParentType = gtk::Box; + + fn class_init(klass: &mut Self::Class) { + klass.bind_template(); + } + + fn instance_init(obj: &InitializingObject<Self>) { + obj.init_template(); + } +} + +impl ObjectImpl for SchistCategoriesViewImpl { + fn constructed(&self) { + self.parent_constructed(); + } +} + +impl WidgetImpl for SchistCategoriesViewImpl {} + +impl BoxImpl for SchistCategoriesViewImpl {} diff --git a/schist_gtk4_gui/src/lib.rs b/schist_gtk4_gui/src/lib.rs index 1430f4c..7455d83 100644 --- a/schist_gtk4_gui/src/lib.rs +++ b/schist_gtk4_gui/src/lib.rs @@ -1,3 +1,4 @@ +mod categories_view; mod window; use gtk::{gdk::Display, gio, glib, prelude::*, Application, CssProvider}; diff --git a/schist_gtk4_gui/src/window.rs b/schist_gtk4_gui/src/window.rs index b1ca9f6..b612e92 100644 --- a/schist_gtk4_gui/src/window.rs +++ b/schist_gtk4_gui/src/window.rs @@ -11,11 +11,16 @@ use gtk::{ }, subclass::{ application_window::ApplicationWindowImpl, - widget::{CompositeTemplateClass, CompositeTemplateInitializingExt, WidgetImpl}, + widget::{ + CompositeTemplateClass, CompositeTemplateInitializingExt, WidgetClassExt, WidgetImpl, + }, window::WindowImpl, }, + TemplateChild, }; +use crate::categories_view::SchistCategoriesView; + gtk::glib::wrapper! { pub struct SchistWindow(ObjectSubclass<SchistWindowSubclass>) @extends gtk::ApplicationWindow, gtk::Window, gtk::Widget, @@ -30,8 +35,11 @@ impl SchistWindow { } #[derive(gtk::CompositeTemplate, Default)] -#[template(resource = "/net/joeac/schist/window.ui")] -pub struct SchistWindowSubclass {} +#[template(resource = "/net/joeac/schist/ui/window.ui")] +pub struct SchistWindowSubclass { + #[template_child] + pub categories_view: TemplateChild<SchistCategoriesView>, +} #[glib::object_subclass] impl ObjectSubclass for SchistWindowSubclass { |
