ui/gtk/button.c

branch
newapi
changeset 259
8cce275d2847
parent 258
a252f68c665a
child 261
b39f0e61fd99
--- a/ui/gtk/button.c	Wed Feb 14 22:00:41 2024 +0100
+++ b/ui/gtk/button.c	Thu Feb 15 21:04:21 2024 +0100
@@ -35,9 +35,33 @@
 #include "../common/context.h"
 #include "../common/object.h"
 
+static void button_set_icon(GtkWidget *button, const char *icon) {
+    if(!icon) {
+        return;
+    }
+    
+#ifdef UI_GTK4
+    gtk_button_set_icon_name(GTK_BUTTON(button), args.icon);
+#else
+#if GTK_CHECK_VERSION(2, 6, 0)
+    GtkWidget *image = gtk_image_new_from_icon_name(icon, GTK_ICON_SIZE_BUTTON);
+    if(image) {
+        gtk_button_set_image(GTK_BUTTON(button), image);
+    }
+#else
+    // TODO
+#endif
+#endif
+}
+
 UIWIDGET ui_button_create(UiObject *obj, UiButtonArgs args) {
     UiObject* current = uic_current_obj(obj);
-    GtkWidget *button = gtk_button_new_with_label(args.label);
+    GtkWidget *button = gtk_button_new();
+    if(args.label) {
+        gtk_button_set_label(GTK_BUTTON(button), args.label);
+    }
+    button_set_icon(button, args.icon);
+
     
     if(args.onclick) {
         UiEventData *event = malloc(sizeof(UiEventData));
@@ -105,6 +129,7 @@
     if(args.label) {
         gtk_button_set_label(GTK_BUTTON(widget), args.label);
     }
+    button_set_icon(widget, args.icon);
     
     UiVar* var = NULL;
     if (args.value) {

mercurial