about summary refs log tree commit diff
path: root/cmd/demo-gtk3/main.ha
blob: 7637fcb7a763c887d6825907b3100a59a6c80ea2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use gi::gio;
use gi::glib;
use gi::gobject;
use gi::gtk;
use os;
use rt;
use types::c;

fn about_clicked(btn: *gtk::Button, data: *opaque) void = {
	let dialog = gtk::about_dialog_new();
	const authors: []*c::char = [
		c::nulstr("Harriet?\0"),
		null: *c::char,
	];
	gtk::about_dialog_set_license_type(
		dialog,
		gtk::License::MPL_2_0,
	);
	gtk::about_dialog_set_authors(
		dialog,
		authors: *[*]*c::char: **c::char,
	);
	gtk::about_dialog_set_website(
		dialog,
		c::nulstr("https://git.sr.ht/~yerinalexey/hare-gi\0"),
	);
	gtk::widget_show_all(dialog);
};

fn activate(app: *gio::Application, data: *opaque) void = {
	const app = app: *gtk::Application;

	let button = gtk::button_new_with_label(c::nulstr("About\0"));
	gtk::button_connect_clicked(button, &about_clicked, null);

	let headerbar = gtk::header_bar_new();
	gtk::header_bar_set_title(headerbar, c::nulstr("hare-gi demo\0"));
	gtk::header_bar_set_show_close_button(headerbar, glib::TRUE);
	gtk::header_bar_pack_end(headerbar, button);

	let window = gtk::application_window_new(app);
	gtk::window_set_titlebar(window, headerbar);
	gtk::widget_show_all(window);
};

export fn main() void = {
	let app = gtk::application_new(
		c::nulstr("hare_gi.example\0"),
		gio::ApplicationFlags::FLAGS_NONE,
	);
	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);
};