Skip to content

Commit 32c7b9f

Browse files
authored
add swifty gtk4 template (#4)
1 parent 18f99c9 commit 32c7b9f

File tree

7 files changed

+121
-0
lines changed

7 files changed

+121
-0
lines changed

templates/meson.build

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
install_subdir('gtk', install_dir: templates_dir)
22
install_subdir('lib', install_dir: templates_dir)
33
install_subdir('new', install_dir: templates_dir)
4+
5+
install_subdir('swifty-gtk4', install_dir: templates_dir)

templates/swifty-gtk4/README.md.in

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# ${PROJECT_NAME}
2+
3+
A shiny new GTK app.
4+
5+
## Build instructions:
6+
7+
```Bash
8+
$ meson build
9+
$ ninja -C build
10+
$ build/${PROGRAM_NAME}
11+
```
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
public class ${NAMESPACE}.App : Gtk.Application {
2+
// Member variables
3+
4+
// Constructor
5+
public App () {
6+
Object (application_id: "${APP_ID}",
7+
flags : GLib.ApplicationFlags.FLAGS_NONE
8+
);
9+
}
10+
11+
protected override void activate () {
12+
var win = this.get_active_window ();
13+
if (win == null) {
14+
win = new MainWindow (this);
15+
}
16+
win.present ();
17+
}
18+
19+
protected override void open (GLib.File[] files, string hint) {
20+
}
21+
}
22+
23+
int main (string[] args) {
24+
var my_app = new ${NAMESPACE}.App ();
25+
return my_app.run (args);
26+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
public class ${NAMESPACE}.MainWindow : Gtk.ApplicationWindow {
2+
// GLib.ListStore clocks_list_store;
3+
public MainWindow (Gtk.Application app) {
4+
Object (application: app);
5+
6+
this.default_height = 400;
7+
this.default_width = 600;
8+
9+
var header = new Gtk.HeaderBar ();
10+
this.set_titlebar (header);
11+
12+
var label = new Gtk.Label ("Hello World!");
13+
label.hexpand = label.vexpand = true;
14+
15+
var button = new Gtk.Button.with_label ("Click Me!");
16+
17+
button.clicked.connect (() => {
18+
var str = label.label;
19+
var temp_str = str.reverse ();
20+
label.label = temp_str;
21+
});
22+
23+
var box = new Gtk.Box (Gtk.Orientation.VERTICAL, 10);
24+
box.append (label);
25+
box.append (button);
26+
27+
this.child = box;
28+
}
29+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
sources = files(
2+
'Main.vala',
3+
'MainWindow.vala',
4+
)
5+
6+
dependencies = [
7+
dependency('glib-2.0'),
8+
dependency('gobject-2.0'),
9+
dependency('gtk4'),
10+
]
11+
12+
executable(
13+
'${PROGRAM_NAME}',
14+
sources,
15+
dependencies: dependencies,
16+
install: true
17+
)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
project(
2+
'${PROJECT_NAME}',
3+
'vala', 'c',
4+
version: '${PROJECT_VERSION}'
5+
)
6+
7+
add_project_arguments(['--enable-experimental'], language: 'vala')
8+
9+
subdir('Sources')
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"description": "an opinionated Gtk4 application template",
3+
"variables": {
4+
"PROGRAM_NAME": {
5+
"summary": "the name of the program",
6+
"default": "/${PROJECT_NAME}/\\w+/\\L\\0\\E/\\W+/-/",
7+
"pattern": "^[[:word:]-]+$"
8+
},
9+
"NAMESPACE": {
10+
"summary": "the namespace to use for the application",
11+
"default": "Gtk4App",
12+
"pattern": "^[A-Za-z_]\\w*$"
13+
},
14+
"APP_ID": {
15+
"summary": "the application ID",
16+
"default": "com.github.author.example",
17+
"pattern": "^\\w+(\\.\\w+)*$"
18+
}
19+
},
20+
"inputs": [
21+
"Sources/Main.vala.in",
22+
"Sources/MainWindow.vala.in",
23+
"Sources/meson.build.in",
24+
"meson.build.in",
25+
"README.md.in"
26+
]
27+
}

0 commit comments

Comments
 (0)