ui/motif/label.c

changeset 433
605bb5dc34f1
parent 430
ea949c0109d8
--- a/ui/motif/label.c	Sat Jan 04 16:38:48 2025 +0100
+++ b/ui/motif/label.c	Sun Jan 05 10:10:47 2025 +0100
@@ -56,7 +56,7 @@
     Widget w = XmCreateLabel(parent, name, xargs, n);
     XtManageChild(w);
     ctn->add(ctn, w);
-    
+      
     XmStringFree(label);
     return w;
 } 
@@ -74,7 +74,7 @@
 }
 
 
-/* ------------------------------ progressbar ------------------------------ */
+/* -------------------------- progressbar/spiner -------------------------- */
 
 static void ui_destroy_progressbar(Widget w, UiProgressBar *pb, XtPointer d) {
     // TODO: free other stuff
@@ -184,3 +184,59 @@
     pb->value = value;
     ui_progressbar_expose(pb->widget, pb, NULL);
 }
+
+
+UIWIDGET ui_progressspinner_create(UiObject* obj, UiProgressbarSpinnerArgs args) {
+    Arg xargs[16];
+    int n = 0;
+    
+    UiContainerPrivate *ctn = ui_obj_container(obj);
+    UI_APPLY_LAYOUT(ctn->layout, args);
+    
+    Widget parent = ctn->prepare(ctn, xargs, &n);
+     
+    XmString label = XmStringCreateSimple("");
+    XtSetArg(xargs[n], XmNlabelString, label); n++;
+    XtSetArg(xargs[n], XmNalignment, XmALIGNMENT_END); n++;
+    XtSetArg(xargs[n], gridMinWidth, 40); n++;
+    
+    char *name = args.name ? (char*)args.name : "progresss_spinner";
+    Widget w = XmCreateLabel(parent, name, xargs, n);
+    XtManageChild(w);
+    ctn->add(ctn, w);
+    
+    UiVar* var = uic_widget_var(obj->ctx, obj->ctx, args.value, args.varname, UI_VAR_INTEGER);
+    if(var) {
+        UiInteger *value = var->value;
+        value->obj = w;
+        value->get = ui_progressspinner_get;
+        value->set = ui_progressspinner_set;
+        
+        if(value->value) {
+            ui_progressspinner_set(value, 1);
+        }
+    }
+    
+      
+    XmStringFree(label);
+    return w;
+}
+
+int64_t ui_progressspinner_get(UiInteger *i) {
+    return i->value;
+}
+
+void ui_progressspinner_set(UiInteger *i, int64_t value) {
+    Widget w = i->obj;
+    XmString label;
+    if(value) {
+        char str[4];
+        snprintf(str, 4, "%c", 150);
+        label = XmStringCreateSimple(str);
+    } else {
+        label = XmStringCreateSimple("");
+    }
+    XtVaSetValues(w, XmNlabelString, label, NULL);
+    XmStringFree(label);
+    i->value = value;
+}

mercurial