From 96d68fc72cc74fd0858846b9c0df0424faa46adb Mon Sep 17 00:00:00 2001 From: Joe Carstairs Date: Sat, 14 Dec 2024 10:47:52 +0000 Subject: Moves UI definition to XML --- schist_gtk4_gui/src/window/imp.rs | 50 +++++++++++++++++++++++++++++++++++++++ schist_gtk4_gui/src/window/mod.rs | 24 ++++++++++++------- 2 files changed, 66 insertions(+), 8 deletions(-) create mode 100644 schist_gtk4_gui/src/window/imp.rs (limited to 'schist_gtk4_gui/src/window') diff --git a/schist_gtk4_gui/src/window/imp.rs b/schist_gtk4_gui/src/window/imp.rs new file mode 100644 index 0000000..82e14b0 --- /dev/null +++ b/schist_gtk4_gui/src/window/imp.rs @@ -0,0 +1,50 @@ +use gtk::{ + glib::{ + self, + subclass::{ + object::{ + ObjectImpl, + ObjectImplExt, + }, + types::ObjectSubclass, InitializingObject, + }, + }, + subclass::{application_window::ApplicationWindowImpl, widget::{ + CompositeTemplateClass, CompositeTemplateInitializingExt, WidgetImpl + }, window::WindowImpl}, +}; + +#[derive(gtk::CompositeTemplate, Default)] +#[template(resource = "/net/joeac/schist/window.ui")] +pub struct Window { +} + +#[glib::object_subclass] +impl ObjectSubclass for Window { + const NAME: &'static str = "SchistWindow"; + type Type = super::Window; + type ParentType = gtk::ApplicationWindow; + + fn class_init(klass: &mut Self::Class) { + klass.bind_template(); + } + + fn instance_init(obj: &InitializingObject) { + obj.init_template(); + } +} + +impl ObjectImpl for Window { + fn constructed(&self) { + self.parent_constructed(); + } +} + +impl WidgetImpl for Window { +} + +impl WindowImpl for Window { +} + +impl ApplicationWindowImpl for Window { +} diff --git a/schist_gtk4_gui/src/window/mod.rs b/schist_gtk4_gui/src/window/mod.rs index fde5f42..9482184 100644 --- a/schist_gtk4_gui/src/window/mod.rs +++ b/schist_gtk4_gui/src/window/mod.rs @@ -1,10 +1,18 @@ -use gtk::{prelude::*, Application, ApplicationWindow}; +mod imp; -pub fn build_window(app: &Application) { - ApplicationWindow::builder() - .application(app) - .title("Schist") - .fullscreened(true) - .build() - .present() +use gtk::{gio, glib::{self, object::IsA}}; + +gtk::glib::wrapper! { + pub struct Window(ObjectSubclass) + @extends gtk::ApplicationWindow, gtk::Window, gtk::Widget, + @implements gio::ActionGroup, gio::ActionMap, gtk::Accessible, gtk::Buildable, + gtk::ConstraintTarget, gtk::Native, gtk::Root, gtk::ShortcutManager; +} + +impl Window { + pub fn new>(app: &A) -> Self { + glib::Object::builder() + .property("application", app) + .build() + } } -- cgit v1.2.3