33 #include "container.h" |
33 #include "container.h" |
34 #include <cx/allocator.h> |
34 #include <cx/allocator.h> |
35 #include "../common/context.h" |
35 #include "../common/context.h" |
36 #include "../common/object.h" |
36 #include "../common/object.h" |
37 |
37 |
|
38 static void button_set_icon(GtkWidget *button, const char *icon) { |
|
39 if(!icon) { |
|
40 return; |
|
41 } |
|
42 |
|
43 #ifdef UI_GTK4 |
|
44 gtk_button_set_icon_name(GTK_BUTTON(button), args.icon); |
|
45 #else |
|
46 #if GTK_CHECK_VERSION(2, 6, 0) |
|
47 GtkWidget *image = gtk_image_new_from_icon_name(icon, GTK_ICON_SIZE_BUTTON); |
|
48 if(image) { |
|
49 gtk_button_set_image(GTK_BUTTON(button), image); |
|
50 } |
|
51 #else |
|
52 // TODO |
|
53 #endif |
|
54 #endif |
|
55 } |
|
56 |
38 UIWIDGET ui_button_create(UiObject *obj, UiButtonArgs args) { |
57 UIWIDGET ui_button_create(UiObject *obj, UiButtonArgs args) { |
39 UiObject* current = uic_current_obj(obj); |
58 UiObject* current = uic_current_obj(obj); |
40 GtkWidget *button = gtk_button_new_with_label(args.label); |
59 GtkWidget *button = gtk_button_new(); |
|
60 if(args.label) { |
|
61 gtk_button_set_label(GTK_BUTTON(button), args.label); |
|
62 } |
|
63 button_set_icon(button, args.icon); |
|
64 |
41 |
65 |
42 if(args.onclick) { |
66 if(args.onclick) { |
43 UiEventData *event = malloc(sizeof(UiEventData)); |
67 UiEventData *event = malloc(sizeof(UiEventData)); |
44 event->obj = obj; |
68 event->obj = obj; |
45 event->userdata = args.onclickdata; |
69 event->userdata = args.onclickdata; |