implement spinbox min/max args (QT)

Fri, 12 Sep 2025 17:38:39 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Fri, 12 Sep 2025 17:38:39 +0200
changeset 761
b963af4aac40
parent 760
396caea0234a
child 762
9452eccfc0f0

implement spinbox min/max args (QT)

application/main.c file | annotate | diff | comparison | revisions
ui/gtk/entry.c file | annotate | diff | comparison | revisions
ui/qt/entry.cpp file | annotate | diff | comparison | revisions
--- a/application/main.c	Fri Sep 12 17:27:54 2025 +0200
+++ b/application/main.c	Fri Sep 12 17:38:39 2025 +0200
@@ -1035,7 +1035,7 @@
         
         ui_button(obj, .label = "Button Y");
         ui_checkbox(obj, .label = "Checkbox");
-        ui_spinner(obj, .digits = 2);
+        ui_spinbox(obj, .digits = 2);
         ui_newline(obj);
         
         ui_hbox(obj, .colspan = 3) {
--- a/ui/gtk/entry.c	Fri Sep 12 17:27:54 2025 +0200
+++ b/ui/gtk/entry.c	Fri Sep 12 17:38:39 2025 +0200
@@ -61,7 +61,7 @@
         }
     }
     
-    if(var && var->type == UI_VAR_RANGE) {
+    if(vartype == UI_VAR_RANGE) {
         UiRange *r = var->value;
         min = r->min;
         max = r->max;
--- a/ui/qt/entry.cpp	Fri Sep 12 17:27:54 2025 +0200
+++ b/ui/qt/entry.cpp	Fri Sep 12 17:38:39 2025 +0200
@@ -40,10 +40,15 @@
     UiContainerPrivate *ctn = ui_obj_container(obj);
     UI_APPLY_LAYOUT(ctn->layout, args);
     
+    double min = args->min;
+    double max = args->max != 0 ? args->max : 100000;
+    
     bool use_double = false;
     UiVar *var = NULL;
+    UiVarType vartype = UI_VAR_SPECIAL;
     if(args->varname) {
         var = uic_get_var(obj->ctx, args->varname);
+        vartype = var->type;
         if(var->type == UI_VAR_DOUBLE) {
             use_double = true;
         } else if(var->type == UI_VAR_RANGE) {
@@ -57,11 +62,14 @@
     if(!var) {
         if(args->intvalue) {
             var = uic_widget_var(obj->ctx, obj->ctx, args->intvalue, NULL, UI_VAR_INTEGER);
+            vartype = UI_VAR_INTEGER;
         } else if(args->doublevalue) {
             var = uic_widget_var(obj->ctx, obj->ctx, args->doublevalue, NULL, UI_VAR_DOUBLE);
+            vartype = UI_VAR_DOUBLE;
             use_double = true;
         } else if(args->rangevalue) {
             var = uic_widget_var(obj->ctx, obj->ctx, args->rangevalue, NULL, UI_VAR_RANGE);
+            vartype = UI_VAR_RANGE;
             use_double = true;
         } else {
             if(args->digits > 0) {
@@ -70,6 +78,12 @@
         }
     }
     
+    if(vartype == UI_VAR_RANGE) {
+        UiRange *r = (UiRange*)var->value;
+        min = r->min;
+        max = r->max;
+    }
+    
     QAbstractSpinBox *widget = nullptr;
     if(use_double) {
         QDoubleSpinBox *spinbox = new QDoubleSpinBox();
@@ -77,17 +91,21 @@
         if(args->step != 0) {
             spinbox->setSingleStep(args->step);
         }
+        spinbox->setMinimum(min);
+        spinbox->setMaximum(max);
         widget = spinbox;
     } else {
         QSpinBox *spinbox = new QSpinBox();
         if(args->step != 0) {
             spinbox->setSingleStep(args->step);
         }
+        spinbox->setMinimum((int)min);
+        spinbox->setMaximum((int)max);
         widget = spinbox;
     }
     
     if(var) {
-        if(var->type == UI_VAR_INTEGER) {
+        if(vartype == UI_VAR_INTEGER) {
             UiInteger *value = (UiInteger*)var->value;
             value->obj = widget;
             if(value->value != 0) {
@@ -96,7 +114,7 @@
             }
             value->get = ui_spinbox_int_get;
             value->set = ui_spinbox_int_set;
-        } else if(var->type == UI_VAR_DOUBLE) {
+        } else if(vartype == UI_VAR_DOUBLE) {
             UiDouble *value = (UiDouble*)var->value;
             value->obj = widget;
             if(value->value != 0) {
@@ -105,7 +123,7 @@
             }
             value->get = ui_spinbox_double_get;
             value->set = ui_spinbox_double_set;
-        } else if(var->type == UI_VAR_RANGE) {
+        } else if(vartype == UI_VAR_RANGE) {
             UiRange *value = (UiRange*)var->value;
             value->obj = widget;
             QDoubleSpinBox *spinbox = (QDoubleSpinBox*)widget;

mercurial