ui/motif/Grid.c

branch
newapi
changeset 426
3eb26df703bf
parent 425
effdc7283337
child 429
0921f8a5d535
--- a/ui/motif/Grid.c	Tue Dec 31 17:29:58 2024 +0100
+++ b/ui/motif/Grid.c	Tue Dec 31 17:57:43 2024 +0100
@@ -52,6 +52,39 @@
 <EnterWindow>:		getfocus()\n\
 <LeaveWindow>:          loosefocus()\n";
 
+static XtResource resources[] =
+{
+    {
+        gridColumnSpacing,
+        gridColumnSpacing,
+        XmRDimension,
+        sizeof (Dimension),
+        XtOffsetOf( GridRec,
+                   mywidget.columnspacing),
+        XmRImmediate,
+        (XtPointer) 0
+    },
+    {
+        gridRowSpacing,
+        gridRowSpacing,
+        XmRDimension,
+        sizeof (Dimension),
+        XtOffsetOf( GridRec,
+                   mywidget.rowspacing),
+        XmRImmediate,
+        (XtPointer) 0
+    },
+    {
+        gridMargin,
+        gridMargin,
+        XmRDimension,
+        sizeof (Dimension),
+        XtOffsetOf( GridRec,
+                   mywidget.margin),
+        XmRImmediate,
+        (XtPointer) 0
+    }
+};
 
 ///*
 static XtResource constraints[] =
@@ -179,7 +212,6 @@
     
 };
 //*/
-//static XtResource constraints[] = {};
 
 GridClassRec gridClassRec = {
     // Core Class
@@ -187,17 +219,17 @@
         //(WidgetClass)&constraintClassRec,   // superclass  
         (WidgetClass)&xmManagerClassRec,
         "Grid",                       // class_name
-        sizeof(GridRec),          // widget_size
-        grid_class_initialize,    // class_initialize
+        sizeof(GridRec),              // widget_size
+        grid_class_initialize,        // class_initialize
         NULL,                         // class_part_initialize
         FALSE,                        // class_inited
-        (XtInitProc)grid_initialize,          // initialize
+        (XtInitProc)grid_initialize,  // initialize
         NULL,                         // initialize_hook
-        grid_realize,             // realize
-        actionslist,                         // actions
-        XtNumber(actionslist),                            // num_actions
-        NULL,                         // resources
-        0,                            // num_resources
+        grid_realize,                 // realize
+        actionslist,                  // actions
+        XtNumber(actionslist),        // num_actions
+        resources,                    // resources
+        XtNumber(resources),          // num_resources
         NULLQUARK,                    // xrm_class
         True,                         // compress_motion
         True,                         // compress_exposure
@@ -465,7 +497,7 @@
         span_max = 50000; // not sure if this is unreasonable low or high
     }
     
-    
+    // calc required size
     for(int i=0;i<ncols;i++) {
         if(cols[i].expand) {
             num_cols_expanding++;
@@ -480,6 +512,10 @@
     }
     
     if(req_width > 0 && req_height > 0) {
+        // add col/row spacing
+        req_width += (ncols-1)*w->mywidget.columnspacing;
+        req_height += (nrows-1)*w->mywidget.rowspacing;
+        
         Widget parent = w->core.parent;
         Dimension rwidth = req_width;
         Dimension rheight = req_height;
@@ -509,6 +545,7 @@
         
     }
     
+    // how much space can we add to each expanding col/row
     int hexpand = 0;
     int width_diff = (int)w->core.width - req_width;
     int hexpand2 = 0;
@@ -522,7 +559,7 @@
         if(cols[i].expand) {
             cols[i].size += hexpand + hexpand2;
         }
-        x += cols[i].size;
+        x += cols[i].size + w->mywidget.columnspacing;
         
         hexpand2 = 0;
     }
@@ -540,7 +577,7 @@
         if(rows[i].expand) {
             rows[i].size += vexpand + vexpand2;
         }
-        y += rows[i].size;
+        y += rows[i].size += w->mywidget.rowspacing;
         
         vexpand2 = 0;
     }
@@ -559,12 +596,12 @@
                 Dimension cwidth = 0;
                 for(int j=0;j<constraints->grid.colspan;j++) {
                     if(constraints->grid.x+j < ncols) {
-                        cwidth += cols[constraints->grid.x+j].size;
+                        cwidth += cols[constraints->grid.x+j].size + (j > 0 ? w->mywidget.columnspacing : 0);
                     }
                 }
                 width = cwidth;
             } else {
-                width = c.size;
+                width = c.size - w->mywidget.columnspacing;
             }
         }
         if(constraints->grid.vfill) {
@@ -572,12 +609,12 @@
                 Dimension cheight = 0;
                 for(int j=0;j<constraints->grid.rowspan;j++) {
                     if(constraints->grid.y+j < nrows) {
-                        cheight += rows[constraints->grid.y+j].size;
+                        cheight += rows[constraints->grid.y+j].size + (j > 0 ? w->mywidget.rowspacing : 0);
                     }
                 }
                 height = cheight;
             } else {
-                height = r.size;
+                height = r.size - w->mywidget.rowspacing;
             }
         }
         

mercurial