ui/gtk/button.c

changeset 4
39b9b86ec452
parent 3
c1a75454b444
child 5
19d37cb9c96c
equal deleted inserted replaced
3:c1a75454b444 4:39b9b86ec452
28 28
29 #include <stdio.h> 29 #include <stdio.h>
30 #include <stdlib.h> 30 #include <stdlib.h>
31 31
32 #include "button.h" 32 #include "button.h"
33 #include "container.h"
34 #include "../../ucx/mempool.h"
35 #include "../common/context.h"
33 36
37 UIWIDGET ui_button(UiObject *obj, char *label, ui_callback f, void *data) {
38 GtkWidget *button = gtk_button_new_with_label(label);
39
40 if(f) {
41 UiEventData *event = ucx_mempool_malloc(
42 obj->ctx->mempool,
43 sizeof(UiEventData));
44 event->obj = obj;
45 event->user_data = data;
46 event->callback = f;
47
48 g_signal_connect(
49 button,
50 "clicked",
51 G_CALLBACK(ui_button_clicked),
52 event);
53 }
54
55 obj->container->add(obj->container, button);
56
57 return button;
58 }
34 59
35 60
36 void ui_button_clicked(GtkWidget *widget, UiEventData *event) { 61 void ui_button_clicked(GtkWidget *widget, UiEventData *event) {
37 UiEvent e; 62 UiEvent e;
38 e.obj = event->obj; 63 e.obj = event->obj;

mercurial