ui/gtk/button.c

branch
newapi
changeset 259
8cce275d2847
parent 258
a252f68c665a
child 261
b39f0e61fd99
equal deleted inserted replaced
258:a252f68c665a 259:8cce275d2847
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;
103 UiObject* current = uic_current_obj(obj); 127 UiObject* current = uic_current_obj(obj);
104 128
105 if(args.label) { 129 if(args.label) {
106 gtk_button_set_label(GTK_BUTTON(widget), args.label); 130 gtk_button_set_label(GTK_BUTTON(widget), args.label);
107 } 131 }
132 button_set_icon(widget, args.icon);
108 133
109 UiVar* var = NULL; 134 UiVar* var = NULL;
110 if (args.value) { 135 if (args.value) {
111 var = uic_create_value_var(current->ctx, args.value); 136 var = uic_create_value_var(current->ctx, args.value);
112 } 137 }

mercurial