-
-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathglade-example-main.c
52 lines (39 loc) · 1.11 KB
/
glade-example-main.c
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
#include <gtk/gtk.h>
// Roughly following https://prognotes.net/2016/03/gtk-3-c-code-hello-world-tutorial-using-glade-3/
GtkWidget *g_label_hello;
GtkWidget *g_button_count;
void on_button_hello_clicked()
{
static unsigned int count = 0;
char str_count[30] = {0};
count++;
snprintf(str_count, 30, "%d", count);
gtk_label_set_text(GTK_LABEL(g_label_hello), str_count);
}
// called when window is closed
void on_window_main_destroy()
{
gtk_main_quit();
}
int main(int argc, char **argv)
{
GtkBuilder *builder;
GtkWidget *window;
gtk_init(&argc, &argv);
builder = gtk_builder_new();
GError *error = NULL;
if (0 == gtk_builder_add_from_file(builder, "glade-example.glade", &error))
{
g_printerr("Error loading file: %s\n", error->message);
g_clear_error(&error);
return 1;
}
window = GTK_WIDGET(gtk_builder_get_object(builder, "window_main"));
gtk_builder_connect_signals(builder, NULL);
// get pointers to the two labels
g_label_hello = GTK_WIDGET(gtk_builder_get_object(builder, "label_hello"));
g_object_unref(builder);
gtk_widget_show(window);
gtk_main();
return 0;
}