Skip to content

Commit

Permalink
Small steps
Browse files Browse the repository at this point in the history
  • Loading branch information
OSA413 committed Aug 1, 2024
1 parent e488d69 commit 58df192
Show file tree
Hide file tree
Showing 12 changed files with 139 additions and 3 deletions.
10 changes: 9 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,12 @@ adw = { version = "0.7", package = "libadwaita", features = ["v1_5"] }
gtk = { version = "0.9", package = "gtk4", features = ["v4_12"] }

[build-dependencies]
glib-build-tools = "0.20"
glib-build-tools = "0.20"

[[bin]]
name="example"
path="src/example/main.rs"

[[bin]]
name="ManagerLauncher"
path="src/ManagerLauncher/main.rs"
9 changes: 7 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
fn main() {
glib_build_tools::compile_resources(
&["src/resources"],
"src/resources/resources.gresource.xml",
&["src/example/resources"],
"src/example/resources/resources.gresource.xml",
"actions_6.gresource",
);
glib_build_tools::compile_resources(
&["src/ManagerLauncher/resources"],
"src/ManagerLauncher/resources/resources.gresource.xml",
"ManagerLauncher.gresource",
);
}
20 changes: 20 additions & 0 deletions src/ManagerLauncher/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
mod window;

use gtk::{gio, glib};
use window::Window;
use adw::prelude::*;

const APP_ID: &str = "Sonic4ModLoader.ManagerLauncher";

fn main() -> glib::ExitCode {
gio::resources_register_include!("ManagerLauncher.gresource")
.expect("Failed to register resources.");

let app = adw::Application::builder().application_id(APP_ID).build();
app.connect_activate(build_ui);
app.run()
}

fn build_ui(app: &adw::Application) {
Window::new(app).present()
}
6 changes: 6 additions & 0 deletions src/ManagerLauncher/resources/resources.gresource.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/Sonic4ModLoader/ManagerLauncher/">
<file compressed="true" preprocess="xml-stripblanks">window.ui</file>
</gresource>
</gresources>
24 changes: 24 additions & 0 deletions src/ManagerLauncher/resources/window.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<template class="ManagerLauncher" parent="GtkApplicationWindow">
<property name="title">ManagerLauncher</property>
<property name="width-request">360</property>
<child>
<object class="GtkBox" id="gtk_box">
<property name="orientation">vertical</property>
<property name="margin-top">12</property>
<property name="margin-bottom">12</property>
<property name="margin-start">12</property>
<property name="margin-end">12</property>
<property name="spacing">12</property>
<property name="halign">center</property>
<child>
<object class="GtkButton" id="button">
<property name="label">test</property>
<property name="action-name"></property>
</object>
</child>
</object>
</child>
</template>
</interface>
50 changes: 50 additions & 0 deletions src/ManagerLauncher/window/imp.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
use glib::subclass::InitializingObject;
use gtk::subclass::prelude::*;
use gtk::{glib, Button, CompositeTemplate, Label};

// Object holding the state
#[derive(CompositeTemplate, Default)]
#[template(resource = "/Sonic4ModLoader/ManagerLauncher/window.ui")]
pub struct Window {
#[template_child]
pub gtk_box: TemplateChild<gtk::Box>,
#[template_child]
pub button: TemplateChild<Button>,
}

// The central trait for subclassing a GObject
#[glib::object_subclass]
impl ObjectSubclass for Window {
// `NAME` needs to match `class` attribute of template
const NAME: &'static str = "ManagerLauncher";
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();
}
}

// Trait shared by all GObjects
impl ObjectImpl for Window {
fn constructed(&self) {
// Call "constructed" on parent
self.parent_constructed();

// Add actions
self.obj().setup_actions();
}
}

// Trait shared by all widgets
impl WidgetImpl for Window {}

// Trait shared by all windows
impl WindowImpl for Window {}

// Trait shared by all application windows
impl ApplicationWindowImpl for Window {}
23 changes: 23 additions & 0 deletions src/ManagerLauncher/window/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
mod imp;

use gio::{ActionEntry, PropertyAction};
use glib::Object;
use gtk::prelude::*;
use gtk::subclass::prelude::*;
use gtk::{gio, glib, Orientation};

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(app: &adw::Application) -> Self {
Object::builder().property("application", app).build()
}

fn setup_actions(&self) {
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 58df192

Please sign in to comment.