implement spinbox width arg (GTK)

Fri, 03 Oct 2025 09:03:59 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Fri, 03 Oct 2025 09:03:59 +0200
changeset 788
27f126f6e361
parent 787
91205084a852
child 789
d70799b3333e

implement spinbox width arg (GTK)

ui/gtk/entry.c file | annotate | diff | comparison | revisions
ui/gtk/text.c file | annotate | diff | comparison | revisions
--- a/ui/gtk/entry.c	Thu Oct 02 17:51:13 2025 +0200
+++ b/ui/gtk/entry.c	Fri Oct 03 09:03:59 2025 +0200
@@ -82,6 +82,11 @@
     GtkWidget *spin = gtk_spin_button_new_with_range(min, max, args->step);
     ui_set_name_and_style(spin, args->name, args->style_class);
     ui_set_widget_groups(obj->ctx, spin, args->groups);
+    
+    if(args->width > 0) {
+        gtk_widget_set_size_request(spin, args->width, -1);
+    }
+    
     gtk_spin_button_set_digits(GTK_SPIN_BUTTON(spin), args->digits);
     UiObserver **obs = NULL;
     if(var) {
--- a/ui/gtk/text.c	Thu Oct 02 17:51:13 2025 +0200
+++ b/ui/gtk/text.c	Fri Oct 03 09:03:59 2025 +0200
@@ -616,10 +616,11 @@
                 uitext);
     
     if(args->width > 0) {
-        // TODO: gtk4
-#if GTK_MAJOR_VERSION <= 3
-        gtk_entry_set_width_chars(GTK_ENTRY(textfield), args->width);
-#endif
+        // An early implementation used gtk_entry_set_width_chars,
+        // but that is not available on gtk4 and other toolkits
+        // also don't have this. Setting the width in pixels can
+        // be implemented on all platforms
+        gtk_widget_set_size_request(textfield, args->width, -1);
     }
     if(frameless) {
         // TODO: gtk2legacy workaroud

mercurial