about summary refs log tree commit diff
path: root/cmd/demo/main.ha
diff options
context:
space:
mode:
authorAlexey Yerin <yyp@disroot.org>2023-05-28 14:10:05 +0300
committerAlexey Yerin <yyp@disroot.org>2023-05-28 14:15:22 +0300
commit16e730f540acfe6a0015464c81831cdfacaf107b (patch)
treea2aa04bf788dc16977fc6cda2ed874938c3c13c5 /cmd/demo/main.ha
Initial commit
Diffstat (limited to 'cmd/demo/main.ha')
-rw-r--r--cmd/demo/main.ha58
1 files changed, 58 insertions, 0 deletions
diff --git a/cmd/demo/main.ha b/cmd/demo/main.ha
new file mode 100644
index 0000000..cf807c6
--- /dev/null
+++ b/cmd/demo/main.ha
@@ -0,0 +1,58 @@
+use gio;
+use glib;
+use gobject;
+use gtk;
+use os;
+use rt;
+use types::c;
+
+fn about_clicked(btn: *gtk::Button, data: *void) void = {
+	let dialog = gtk::about_dialog_new();
+	const authors: []*c::char = [
+		c::fromstr("Harriet?"),
+		null: *c::char,
+	];
+	gtk::about_dialog_set_license_type(
+		dialog: *gtk::AboutDialog,
+		gtk::License::MPL_2_0,
+	);
+	gtk::about_dialog_set_authors(
+		dialog: *gtk::AboutDialog,
+		authors: *[*]*c::char: **c::char,
+	);
+	gtk::about_dialog_set_website(
+		dialog: *gtk::AboutDialog,
+		c::fromstr("https://git.sr.ht/~yerinalexey/hare-gi"),
+	);
+
+	gtk::widget_show_all(dialog);
+};
+
+fn activate(app: *gio::Application, data: *void) void = {
+	const app = app: *gtk::Application;
+
+	let button = gtk::button_new_with_label(c::fromstr("About"));
+	gtk::button_connect_clicked(button: *gtk::Button, &about_clicked, null);
+
+	let headerbar = gtk::header_bar_new();
+	gtk::header_bar_set_title(headerbar: *gtk::HeaderBar, c::fromstr("hare-gi demo"));
+	gtk::header_bar_set_show_close_button(headerbar: *gtk::HeaderBar, glib::TRUE);
+	gtk::header_bar_pack_end(headerbar: *gtk::HeaderBar, button);
+
+	let window = gtk::application_window_new(app);
+	gtk::window_set_titlebar(window: *gtk::Window, headerbar);
+	gtk::widget_show_all(window);
+};
+
+export fn main() void = {
+	let app = gtk::application_new(
+		c::fromstr("hare_gi.example"),
+		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);
+};