about summary refs log tree commit diff
path: root/cmd/demo-gtk4/main.ha
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/demo-gtk4/main.ha')
-rw-r--r--cmd/demo-gtk4/main.ha59
1 files changed, 59 insertions, 0 deletions
diff --git a/cmd/demo-gtk4/main.ha b/cmd/demo-gtk4/main.ha
new file mode 100644
index 0000000..39ca4ca
--- /dev/null
+++ b/cmd/demo-gtk4/main.ha
@@ -0,0 +1,59 @@
+use gi::gio;
+use gi::glib;
+use gi::gobject;
+use gi::gtk4;
+use os;
+use rt;
+use types::c;
+
+fn about_clicked(btn: *gtk4::Button, data: *opaque) void = {
+	let dialog = gtk4::about_dialog_new();
+	const authors: []*c::char = [
+		c::nulstr("Harriet?\0"),
+		null: *c::char,
+	];
+	gtk4::about_dialog_set_license_type(
+		dialog: *gtk4::AboutDialog,
+		gtk4::License::MPL_2_0,
+	);
+	gtk4::about_dialog_set_authors(
+		dialog: *gtk4::AboutDialog,
+		authors: *[*]*c::char: **c::char,
+	);
+	gtk4::about_dialog_set_website(
+		dialog: *gtk4::AboutDialog,
+		c::nulstr("https://git.sr.ht/~yerinalexey/hare-gi\0"),
+	);
+
+	gtk4::widget_show(dialog);
+};
+
+fn activate(app: *gio::Application, data: *opaque) void = {
+	const app = app: *gtk4::Application;
+
+	let button = gtk4::button_new_with_label(c::nulstr("About\0"));
+	gtk4::button_connect_clicked(button: *gtk4::Button, &about_clicked, null);
+
+	let headerbar = gtk4::header_bar_new();
+	let title = gtk4::label_new(c::nulstr("hare-gi demo\0"));
+	gtk4::header_bar_set_title_widget(headerbar: *gtk4::HeaderBar, title);
+	gtk4::header_bar_set_show_title_buttons(headerbar: *gtk4::HeaderBar, glib::TRUE);
+	gtk4::header_bar_pack_end(headerbar: *gtk4::HeaderBar, button);
+
+	let window = gtk4::application_window_new(app);
+	gtk4::window_set_titlebar(window: *gtk4::Window, headerbar);
+	gtk4::widget_show(window);
+};
+
+export fn main() void = {
+	let app = gtk4::application_new(
+		c::nulstr("hare_gi.example\0"),
+		gio::ApplicationFlags::FLAGS_NONE,
+	): *gio::Application;
+	gio::application_connect_activate(app, &activate, null);
+	const status = gio::application_run(
+		app, rt::argc: int, rt::argv: **c::char,
+	);
+	gobject::object_unref(app);
+	os::exit(status);
+};