use view.fittingSize as backup to intrisicContentSize in GridLayout (Cocoa)

3 days ago

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 30 Mar 2025 16:38:27 +0200 (3 days ago)
changeset 538
5004b4a9b16d
parent 537
81e46644f1aa
child 539
96f466ceaf23

use view.fittingSize as backup to intrisicContentSize in GridLayout (Cocoa)

make/xcode/toolkit/toolkit/main.m file | annotate | diff | comparison | revisions
ui/cocoa/GridLayout.m file | annotate | diff | comparison | revisions
ui/cocoa/text.m file | annotate | diff | comparison | revisions
--- a/make/xcode/toolkit/toolkit/main.m	Sun Mar 30 14:19:55 2025 +0200
+++ b/make/xcode/toolkit/toolkit/main.m	Sun Mar 30 16:38:27 2025 +0200
@@ -37,23 +37,17 @@
 void application_startup(UiEvent *event, void *data) {
     UiObject *obj = ui_window("My Window", NULL);
     
-    //ui_textarea(obj, .fill = UI_OFF);
-    ui_button(obj, .label = "Button 1");
-    ui_hbox(obj, .fill = UI_OFF) {
-        ui_button(obj, .label = "HButton 1");
-        ui_button(obj, .label = "HButton 2");
-        ui_button(obj, .label = "HButton 3");
-        ui_vbox0(obj) {
-            ui_button(obj, .label = "X1");
-            ui_button(obj, .label = "X2");
-            ui_button(obj, .label = "X3");
-            ui_button(obj, .label = "X4");
-        }
+    
+    ui_grid(obj, .columnspacing = 0, .rowspacing = 0) {
+        ui_textarea(obj, .fill = UI_ON);
     }
-    ui_textarea(obj, .fill = UI_OFF);
-    ui_button(obj, .label = "Button 2");
-    ui_button(obj, .label = "Button 3");
-    ui_button(obj, .label = "Button 4");
+    
+    
+    ui_vbox(obj, .spacing = 0, .fill = UI_OFF) {
+        ui_button(obj, .label = "V Button 1");
+        ui_button(obj, .label = "V Button 2");
+        ui_button(obj, .label = "V Button 3");
+    }
     
     ui_show(obj);
 }
--- a/ui/cocoa/GridLayout.m	Sun Mar 30 14:19:55 2025 +0200
+++ b/ui/cocoa/GridLayout.m	Sun Mar 30 16:38:27 2025 +0200
@@ -53,7 +53,6 @@
     NSSize s1 = _test.intrinsicContentSize;
     NSEdgeInsets e1 = _test.alignmentRectInsets;
     
-    printf("fuck\n");
 }
  */
 
@@ -80,7 +79,19 @@
             GridDef *row = &rows[y];
             
             NSSize size = elm->view.intrinsicContentSize;
+            NSSize size2 = elm->view.fittingSize;
             NSEdgeInsets alignment = elm->view.alignmentRectInsets;
+            // TODO: remove alignment
+            alignment.left = 0;
+            alignment.right = 0;
+            alignment.top = 0;
+            alignment.bottom = 0;
+            if(size.width == NSViewNoIntrinsicMetric) {
+                size.width = size2.width;
+            }
+            if(size.height == NSViewNoIntrinsicMetric) {
+                size.height = size2.height;
+            }
             if(size.width != NSViewNoIntrinsicMetric) {
                 CGFloat width = size.width + alignment.left + alignment.right;
                 if(width > cols[elm->x].preferred_size && elm->colspan <= 1 && span_max == 1) {
@@ -244,12 +255,12 @@
                 for(int c=elm->x;c<end_col;c++) {
                     cwidth += cols[c].size;
                 }
-                frame.size.width = cwidth;
+                frame.size.width = cwidth + + alignment.left + alignment.right;
             } else {
-                frame.size.width = col->size;
+                frame.size.width = col->size + alignment.left + alignment.right;
             }
         } else {
-            frame.size.width = elm->preferred_width;
+            frame.size.width = elm->preferred_width + alignment.left + alignment.right;
         }
         if(elm->vfill) {
             if(elm->rowspan > 1) {
@@ -268,7 +279,8 @@
             frame.size.height = elm->preferred_height;
         }
         frame.origin.x = col->pos - (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 + ((alignment.top+alignment.right)/2);
+        frame.origin.y = viewFrame.size.height - row->pos - frame.size.height;
         elm->view.frame = frame;
     }
     
@@ -294,10 +306,17 @@
     elm.margin = 0;
     elm.colspan = _uilayout.colspan;
     elm.rowspan = _uilayout.rowspan;
-    elm.hfill = _uilayout.hfill;
-    elm.vfill = _uilayout.vfill;
-    elm.hexpand = _uilayout.hexpand;
-    elm.vexpand = _uilayout.vexpand;
+    if(_uilayout.fill) {
+        elm.hfill = TRUE;
+        elm.vfill = TRUE;
+        elm.hexpand = TRUE;
+        elm.vexpand = TRUE;
+    } else {
+        elm.hfill = _uilayout.hfill;
+        elm.vfill = _uilayout.vfill;
+        elm.hexpand = _uilayout.hexpand;
+        elm.vexpand = _uilayout.vexpand;
+    }
     elm.view = view;
     cxListAdd(_children, &elm);
     
--- a/ui/cocoa/text.m	Sun Mar 30 14:19:55 2025 +0200
+++ b/ui/cocoa/text.m	Sun Mar 30 16:38:27 2025 +0200
@@ -32,12 +32,12 @@
 #import <objc/runtime.h>
 
 UIWIDGET ui_textarea_create(UiObject *obj, UiTextAreaArgs args) {
-    //NSScrollView *scrollview = [[NSScrollView alloc] initWithFrame:(NSRect){ 0, 0, 40, 40}];
-    NSTextView *textview = [[NSTextView alloc] initWithFrame:(NSRect){ 0, 0, 40, 40}];
-    //scrollview.documentView = textview;
+    NSScrollView *scrollview = [[NSScrollView alloc] init];
+    NSTextView *textview = [[NSTextView alloc] init];
+    scrollview.documentView = textview;
     
     UiLayout layout = UI_INIT_LAYOUT(args);
-    ui_container_add(obj, textview, &layout, TRUE);
+    ui_container_add(obj, scrollview, &layout, TRUE);
     
-    return (__bridge void*)textview;
+    return (__bridge void*)scrollview;
 }

mercurial