implement progress spinner (Motif)

Sun, 05 Jan 2025 10:10:47 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 05 Jan 2025 10:10:47 +0100
changeset 433
605bb5dc34f1
parent 431
bb7da585debc
child 434
9a68f8cbeffa

implement progress spinner (Motif)

application/main.c file | annotate | diff | comparison | revisions
ui/motif/Grid.c file | annotate | diff | comparison | revisions
ui/motif/Grid.h file | annotate | diff | comparison | revisions
ui/motif/button.c file | annotate | diff | comparison | revisions
ui/motif/label.c file | annotate | diff | comparison | revisions
ui/motif/label.h file | annotate | diff | comparison | revisions
ui/motif/toolkit.c file | annotate | diff | comparison | revisions
ui/ui/display.h file | annotate | diff | comparison | revisions
--- a/application/main.c	Sat Jan 04 16:38:48 2025 +0100
+++ b/application/main.c	Sun Jan 05 10:10:47 2025 +0100
@@ -547,6 +547,7 @@
 typedef struct WData {
     UiString *path;
     UiList *list;
+    UiInteger *spinner;
 } WData;
 
 
@@ -587,6 +588,7 @@
     WData *wdata = ui_malloc(obj->ctx, sizeof(WData));
     wdata->path = ui_string_new(obj->ctx, NULL);
     wdata->list = ui_list_new(obj->ctx, NULL);
+    wdata->spinner = ui_int_new(obj->ctx, NULL);
     obj->window = wdata;
     
     ui_list_append(wdata->list, "List Item 1");
@@ -596,13 +598,18 @@
     
     ui_button(obj, .label = "Add Menu Item", .onclick = action_button, .name = "mybutton1");
     ui_button(obj, .label = "Add List Item", .onclick = action_button2);
-    ui_progressbar(obj, .name = "pb");
+    ui_hbox0(obj) {
+        ui_progressbar(obj, .name = "pb", .fill = UI_ON);
+        ui_progressspinner(obj, .value = wdata->spinner);
+    }
     ui_listview(obj, .list = wdata->list, .fill = UI_ON, .multiselection = TRUE,
             .onactivate = action_listevent, .onactivatedata = "activate",
             .onselection = action_listevent, .onselectiondata = "selection");
     
     
     ui_show(obj);
+    
+    ui_set(wdata->spinner, 1);
 }
 
 void action_test(UiEvent *event, void *data) {
--- a/ui/motif/Grid.c	Sat Jan 04 16:38:48 2025 +0100
+++ b/ui/motif/Grid.c	Sun Jan 05 10:10:47 2025 +0100
@@ -208,8 +208,17 @@
                    grid.vfill),
         XmRImmediate,
         (XtPointer) 0
+    },
+    {
+        gridMinWidth,
+        gridMinWidth,
+        XmRDimension,
+        sizeof (Dimension),
+        XtOffsetOf( GridConstraintRec,
+                   grid.min_width),
+        XmRImmediate,
+        (XtPointer) 0
     }
-    
 };
 //*/
 
@@ -415,6 +424,9 @@
             if(constraints->grid.pref_height == 0) {
                 constraints->grid.pref_height = child->core.height;
             }
+            if(constraints->grid.pref_width < constraints->grid.min_width) {
+                constraints->grid.pref_width = constraints->grid.min_width;
+            }
             
             if(constraints->grid.colspan > span_max || constraints->grid.rowspan > span_max) {
                 continue;
--- a/ui/motif/Grid.h	Sat Jan 04 16:38:48 2025 +0100
+++ b/ui/motif/Grid.h	Sun Jan 05 10:10:47 2025 +0100
@@ -58,6 +58,7 @@
 #define gridMarginRight "gridMarginRight"
 #define gridMarginTop "gridMarginTop"
 #define gridMarginBottom "gridMarginBottom"
+#define gridMinWidth "gridMinWidth"
     
 
 typedef struct GridDef {
@@ -116,6 +117,7 @@
     Dimension rowspan;
     Dimension pref_width;
     Dimension pref_height;
+    Dimension min_width;
 } GridContraintPart;
 
 typedef struct GridConstraintRec {
--- a/ui/motif/button.c	Sat Jan 04 16:38:48 2025 +0100
+++ b/ui/motif/button.c	Sun Jan 05 10:10:47 2025 +0100
@@ -49,7 +49,7 @@
     UI_APPLY_LAYOUT(ctn->layout, args);
     
     Widget parent = ctn->prepare(ctn, xargs, &n);
-    
+       
     XmString label = NULL;
     if(args.label) {
         label = XmStringCreateLocalized((char*)args.label);
--- 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;
+}
--- a/ui/motif/label.h	Sat Jan 04 16:38:48 2025 +0100
+++ b/ui/motif/label.h	Sun Jan 05 10:10:47 2025 +0100
@@ -50,6 +50,9 @@
 double ui_progressbar_get(UiDouble *d);
 void ui_progressbar_set(UiDouble *d, double value);
 
+int64_t ui_progressspinner_get(UiInteger *i);
+void ui_progressspinner_set(UiInteger *i, int64_t value);
+
 #ifdef	__cplusplus
 }
 #endif
--- a/ui/motif/toolkit.c	Sat Jan 04 16:38:48 2025 +0100
+++ b/ui/motif/toolkit.c	Sun Jan 05 10:10:47 2025 +0100
@@ -65,16 +65,15 @@
 
 
 static String fallback[] = {
-    	//"*fontList: -dt-interface system-medium-r-normal-s*utf*:",    
-        "*text_area*renderTable: f1",
-        "*f1*fontType: FONT_IS_XFT",
-        "*f1*fontName: Monospace",
-        "*f1*fontSize: 11",
+    	//"*fontList: -dt-interface system-medium-r-normal-s*utf*:",                 
         "*renderTable: rt",
         "*rt*fontType: FONT_IS_XFT",
         "*rt*fontName: Sans",
         "*rt*fontSize: 11",
         
+        "*progresss_spinner*renderTable*fontType: FONT_IS_FONT",
+        "*progresss_spinner*renderTable*fontName: Cursor",
+        
         "*window_frame.shadowType: SHADOW_ETCHED_OUT",
         "*window_frame.shadowThickness: 1",
         "*togglebutton.shadowThickness: 1",
--- a/ui/ui/display.h	Sat Jan 04 16:38:48 2025 +0100
+++ b/ui/ui/display.h	Sun Jan 05 10:10:47 2025 +0100
@@ -101,6 +101,8 @@
     UiBool vfill;
     int colspan;
     int rowspan;
+    const char *name;
+    const char *style_class;
 
     UiInteger* value;
     const char* varname;

mercurial