# HG changeset patch # User Olaf Wintermann # Date 1708027461 -3600 # Node ID 8cce275d2847b18b682a644eb22c70b752a3d395 # Parent a252f68c665aadfaea0ca41c0d989e5772c2ab4a implement button icon parameter (GTK) diff -r a252f68c665a -r 8cce275d2847 application/main.c --- a/application/main.c Wed Feb 14 22:00:41 2024 +0100 +++ b/application/main.c Thu Feb 15 21:04:21 2024 +0100 @@ -67,7 +67,7 @@ UiObject *obj = ui_window("Test", NULL); - ui_button(obj, .label = "Test Button"); + ui_button(obj, .label = "Test Button", .icon = "folder-documents"); ui_togglebutton(obj, .label = "Toggle"); ui_checkbox(obj, .label = "Checkbox"); diff -r a252f68c665a -r 8cce275d2847 ui/gtk/button.c --- 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) {