ui/gtk/button.c

branch
newapi
changeset 276
376921880a7f
parent 274
9e2aee097b69
child 278
a8faf8757450
equal deleted inserted replaced
275:132c7bcc6997 276:376921880a7f
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) { 38 void ui_button_set_icon_name(GtkWidget *button, const char *icon) {
39 if(!icon) { 39 if(!icon) {
40 return; 40 return;
41 } 41 }
42 42
43 #ifdef UI_GTK4 43 #ifdef UI_GTK4
44 gtk_button_set_icon_name(GTK_BUTTON(button), args.icon); 44 gtk_button_set_icon_name(GTK_BUTTON(button), icon);
45 #else 45 #else
46 #if GTK_CHECK_VERSION(2, 6, 0) 46 #if GTK_CHECK_VERSION(2, 6, 0)
47 GtkWidget *image = gtk_image_new_from_icon_name(icon, GTK_ICON_SIZE_BUTTON); 47 GtkWidget *image = gtk_image_new_from_icon_name(icon, GTK_ICON_SIZE_BUTTON);
48 if(image) { 48 if(image) {
49 gtk_button_set_image(GTK_BUTTON(button), image); 49 gtk_button_set_image(GTK_BUTTON(button), image);
58 UiObject* current = uic_current_obj(obj); 58 UiObject* current = uic_current_obj(obj);
59 GtkWidget *button = gtk_button_new(); 59 GtkWidget *button = gtk_button_new();
60 if(args.label) { 60 if(args.label) {
61 gtk_button_set_label(GTK_BUTTON(button), args.label); 61 gtk_button_set_label(GTK_BUTTON(button), args.label);
62 } 62 }
63 button_set_icon(button, args.icon); 63 ui_button_set_icon_name(button, args.icon);
64 64
65 65
66 if(args.onclick) { 66 if(args.onclick) {
67 UiEventData *event = malloc(sizeof(UiEventData)); 67 UiEventData *event = malloc(sizeof(UiEventData));
68 event->obj = obj; 68 event->obj = obj;
127 UiObject* current = uic_current_obj(obj); 127 UiObject* current = uic_current_obj(obj);
128 128
129 if(args.label) { 129 if(args.label) {
130 gtk_button_set_label(GTK_BUTTON(widget), args.label); 130 gtk_button_set_label(GTK_BUTTON(widget), args.label);
131 } 131 }
132 button_set_icon(widget, args.icon); 132 ui_button_set_icon_name(widget, args.icon);
133 133
134 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.value, args.varname, UI_VAR_INTEGER); 134 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.value, args.varname, UI_VAR_INTEGER);
135 if (var) { 135 if (var) {
136 UiInteger* value = (UiInteger*)var->value; 136 UiInteger* value = (UiInteger*)var->value;
137 value->obj = widget; 137 value->obj = widget;

mercurial