summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock10
-rw-r--r--schist_gtk4_gui/Cargo.toml3
-rw-r--r--schist_gtk4_gui/build.rs7
-rw-r--r--schist_gtk4_gui/resources/resources.gresource.xml6
-rw-r--r--schist_gtk4_gui/resources/window.ui13
-rw-r--r--schist_gtk4_gui/src/lib.rs11
-rw-r--r--schist_gtk4_gui/src/window/imp.rs50
-rw-r--r--schist_gtk4_gui/src/window/mod.rs24
8 files changed, 114 insertions, 10 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 8646c54..f6d2d98 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -747,6 +747,15 @@ dependencies = [
]
[[package]]
+name = "glib-build-tools"
+version = "0.20.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7029c2651d9b5d5a3eea93ec8a1995665c6d3a69ce9bf6042ad9064d134736d8"
+dependencies = [
+ "gio",
+]
+
+[[package]]
name = "glib-macros"
version = "0.20.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1739,6 +1748,7 @@ dependencies = [
name = "schist_gtk4_gui"
version = "0.1.0"
dependencies = [
+ "glib-build-tools",
"gtk4",
]
diff --git a/schist_gtk4_gui/Cargo.toml b/schist_gtk4_gui/Cargo.toml
index 79fae5d..a5884cb 100644
--- a/schist_gtk4_gui/Cargo.toml
+++ b/schist_gtk4_gui/Cargo.toml
@@ -5,3 +5,6 @@ edition = "2021"
[dependencies]
gtk = { version = "0.9.4", package = "gtk4", features = ["v4_8"] }
+
+[build-dependencies]
+glib-build-tools = "0.20.0"
diff --git a/schist_gtk4_gui/build.rs b/schist_gtk4_gui/build.rs
new file mode 100644
index 0000000..6c2f68b
--- /dev/null
+++ b/schist_gtk4_gui/build.rs
@@ -0,0 +1,7 @@
+fn main() {
+ glib_build_tools::compile_resources(
+ &["resources"],
+ "resources/resources.gresource.xml",
+ "resources.gresource",
+ );
+}
diff --git a/schist_gtk4_gui/resources/resources.gresource.xml b/schist_gtk4_gui/resources/resources.gresource.xml
new file mode 100644
index 0000000..a74cfc9
--- /dev/null
+++ b/schist_gtk4_gui/resources/resources.gresource.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+ <gresource prefix="/net/joeac/schist/">
+ <file compressed="true" preprocess="xml-stripblanks">window.ui</file>
+ </gresource>
+</gresources>
diff --git a/schist_gtk4_gui/resources/window.ui b/schist_gtk4_gui/resources/window.ui
new file mode 100644
index 0000000..6fced19
--- /dev/null
+++ b/schist_gtk4_gui/resources/window.ui
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <template class="SchistWindow" parent="GtkApplicationWindow">
+ <property name="title">schist</property>
+ <property name="default-height">560</property>
+ <property name="default-width">1080</property>
+ <child>
+ <object class="GtkLabel">
+ <property name="label">Hello, world!</property>
+ </object>
+ </child>
+ </template>
+</interface>
diff --git a/schist_gtk4_gui/src/lib.rs b/schist_gtk4_gui/src/lib.rs
index 67a3946..4c3055c 100644
--- a/schist_gtk4_gui/src/lib.rs
+++ b/schist_gtk4_gui/src/lib.rs
@@ -1,12 +1,19 @@
mod window;
-use gtk::{glib, prelude::*, Application};
-use window::build_window;
+use gtk::{gio, glib, prelude::*, Application};
const APP_ID: &str = "net.joeac.schist";
pub fn run() -> glib::ExitCode {
+ gio::resources_register_include!("resources.gresource")
+ .expect("failed to register resources");
+
let app = Application::builder().application_id(APP_ID).build();
app.connect_activate(build_window);
app.run()
}
+
+fn build_window(app: &Application) {
+ let window = window::Window::new(app);
+ window.present()
+}
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<Self>) {
+ 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<imp::Window>)
+ @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<A: IsA<gtk::Application>>(app: &A) -> Self {
+ glib::Object::builder()
+ .property("application", app)
+ .build()
+ }
}