ui/cocoa/GridLayout.m

changeset 800
814d374fb689
parent 799
f8ff8df41713
child 810
7b5ba65b246f
--- a/ui/cocoa/GridLayout.m	Sun Oct 05 12:34:42 2025 +0200
+++ b/ui/cocoa/GridLayout.m	Sun Oct 05 13:30:19 2025 +0200
@@ -80,6 +80,10 @@
             GridDef *col = &cols[x];
             GridDef *row = &rows[y];
             
+            if(elm->margin.left + elm->margin.right > 0) {
+                printf(""); // break
+            }
+            
             NSSize size = elm->view.intrinsicContentSize;
             NSSize size2 = elm->view.fittingSize;
             if(size.width == NSViewNoIntrinsicMetric) {
@@ -89,21 +93,21 @@
                 size.height = size2.height;
             }
             if(size.width != NSViewNoIntrinsicMetric) {
-                CGFloat width = size.width;
+                CGFloat width = size.width + elm->margin.left + elm->margin.right;
                 if(width > cols[elm->x].preferred_size && elm->colspan <= 1 && span_max == 1) {
                     cols[elm->x].preferred_size = width;
                 }
                 elm->preferred_width = width;
             }
             if(size.height != NSViewNoIntrinsicMetric) {
-                CGFloat height = size.height;
-                //CGFloat height = size.height;
+                CGFloat height = size.height + elm->margin.top + elm->margin.bottom;
                 if(height > rows[elm->y].preferred_size && elm->rowspan <= 1 && span_max == 1) {
                     rows[elm->y].preferred_size = height;
                 }
                 elm->preferred_height = height;
             }
             
+            
             if(elm->rowspan > span_max || elm->colspan > span_max) {
                 continue;
             }
@@ -254,16 +258,22 @@
                 if(end_col > ncols) {
                     end_col = ncols;
                 }
+                int real_span = 0;
                 for(int c=elm->x;c<end_col;c++) {
                     cwidth += cols[c].size;
+                    real_span++;
                 }
-                frame.size.width = cwidth + + alignment.left + alignment.right;
+                if(real_span > 0) {
+                    cwidth += (real_span-1) * colspacing;
+                }
+                frame.size.width = cwidth + alignment.left + alignment.right;
             } else {
                 frame.size.width = col->size + alignment.left + alignment.right;
             }
         } else {
             frame.size.width = elm->preferred_width + alignment.left + alignment.right;
         }
+        frame.size.width -= elm->margin.left + elm->margin.right;
         if(elm->vfill) {
             if(elm->rowspan > 1) {
                 int rheight = 0;
@@ -271,8 +281,13 @@
                 if(end_row > nrows) {
                     end_row = nrows;
                 }
+                int real_span = 0;
                 for(int r=elm->y;r<end_row;r++) {
                     rheight += rows[r].size;
+                    real_span++;
+                }
+                if(real_span > 0) {
+                    rheight += (real_span-1) * rowspacing;
                 }
                 frame.size.height = rheight;
             }
@@ -280,9 +295,10 @@
         } else {
             frame.size.height = elm->preferred_height;
         }
-        frame.origin.x = col->pos - (alignment.left+alignment.right)/2;
+        frame.size.height -= elm->margin.top + elm->margin.bottom;
+        frame.origin.x = col->pos + elm->margin.left - (alignment.left+alignment.right)/2;
         //frame.origin.y = viewFrame.size.height - row->pos - frame.size.height + ((alignment.top+alignment.right)/2);
-        frame.origin.y = viewFrame.size.height - row->pos - frame.size.height;
+        frame.origin.y = viewFrame.size.height - row->pos - elm->margin.top - frame.size.height;
         elm->view.frame = frame;
     }
     

mercurial