fix nested box containers (Cocoa)

4 days ago

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 16 Mar 2025 13:53:30 +0100 (4 days ago)
changeset 500
95ab1710993f
parent 499
0a386bd871be
child 501
c0f108b1b709

fix nested box containers (Cocoa)

make/xcode/toolkit/toolkit.xcodeproj/project.pbxproj file | annotate | diff | comparison | revisions
make/xcode/toolkit/toolkit/main.m file | annotate | diff | comparison | revisions
ui/cocoa/container.m file | annotate | diff | comparison | revisions
ui/cocoa/objs.mk file | annotate | diff | comparison | revisions
ui/cocoa/text.h file | annotate | diff | comparison | revisions
ui/cocoa/text.m file | annotate | diff | comparison | revisions
--- a/make/xcode/toolkit/toolkit.xcodeproj/project.pbxproj	Thu Mar 13 22:47:16 2025 +0100
+++ b/make/xcode/toolkit/toolkit.xcodeproj/project.pbxproj	Sun Mar 16 13:53:30 2025 +0100
@@ -7,6 +7,7 @@
 	objects = {
 
 /* Begin PBXBuildFile section */
+		ED52BFB02D86FC5D00FD8BE5 /* text.m in Sources */ = {isa = PBXBuildFile; fileRef = ED52BFAF2D86FC5D00FD8BE5 /* text.m */; };
 		ED6580EE2CFF19F900F5402F /* context.c in Sources */ = {isa = PBXBuildFile; fileRef = ED6580DD2CFF19F900F5402F /* context.c */; };
 		ED6580EF2CFF19F900F5402F /* menu.c in Sources */ = {isa = PBXBuildFile; fileRef = ED6580E12CFF19F900F5402F /* menu.c */; };
 		ED6580F02CFF19F900F5402F /* threadpool.c in Sources */ = {isa = PBXBuildFile; fileRef = ED6580E72CFF19F900F5402F /* threadpool.c */; };
@@ -45,6 +46,8 @@
 /* End PBXBuildFile section */
 
 /* Begin PBXFileReference section */
+		ED52BFAE2D86FC5D00FD8BE5 /* text.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = text.h; path = /Users/olaf/Projekte/toolkit/ui/cocoa/text.h; sourceTree = "<absolute>"; };
+		ED52BFAF2D86FC5D00FD8BE5 /* text.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = text.m; path = /Users/olaf/Projekte/toolkit/ui/cocoa/text.m; sourceTree = "<absolute>"; };
 		ED6580AC2CFF122700F5402F /* toolkit.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = toolkit.app; sourceTree = BUILT_PRODUCTS_DIR; };
 		ED6580DA2CFF19F900F5402F /* condvar.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = condvar.h; path = /Users/olaf/Projekte/toolkit/ui/common/condvar.h; sourceTree = "<absolute>"; };
 		ED6580DB2CFF19F900F5402F /* condvar.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = condvar.c; path = /Users/olaf/Projekte/toolkit/ui/common/condvar.c; sourceTree = "<absolute>"; };
@@ -257,6 +260,8 @@
 		ED65812E2CFF1A7200F5402F /* cocoa */ = {
 			isa = PBXGroup;
 			children = (
+				ED52BFAE2D86FC5D00FD8BE5 /* text.h */,
+				ED52BFAF2D86FC5D00FD8BE5 /* text.m */,
 				ED65815D2CFF4BF200F5402F /* WindowManager.h */,
 				ED65815E2CFF4BF200F5402F /* WindowManager.m */,
 				ED65815A2CFF3EE900F5402F /* MainWindow.h */,
@@ -401,6 +406,7 @@
 				ED6581312CFF1A8800F5402F /* toolkit.m in Sources */,
 				ED6581342CFF1F1900F5402F /* AppDelegate.m in Sources */,
 				ED6581292CFF1A3000F5402F /* allocator.c in Sources */,
+				ED52BFB02D86FC5D00FD8BE5 /* text.m in Sources */,
 				ED6581432CFF3BCE00F5402F /* window.m in Sources */,
 				ED6581442CFF3BCE00F5402F /* button.m in Sources */,
 				ED6581452CFF3BCE00F5402F /* Container.m in Sources */,
--- a/make/xcode/toolkit/toolkit/main.m	Thu Mar 13 22:47:16 2025 +0100
+++ b/make/xcode/toolkit/toolkit/main.m	Sun Mar 16 13:53:30 2025 +0100
@@ -37,33 +37,23 @@
 void application_startup(UiEvent *event, void *data) {
     UiObject *obj = ui_window("My Window", NULL);
     
-    ui_grid(obj, .rowspacing = 10) {
-        ui_button(obj, .label = "Button X1 -------------------------------------------------- END", .onclick = action_button);
-        ui_newline(obj);
-        
-        ui_togglebutton(obj, .label = "Togglebutton");
-        ui_newline(obj);
-        
-        ui_checkbox(obj, .label = "Checkbox");
-        ui_newline(obj);
-        
-        ui_switch(obj, .label = "Switch");
-        ui_newline(obj);
-        
-        ui_radiobutton(obj, .label = "Z Radio 1", .varname = "radio1");
-        ui_radiobutton(obj, .label = "Z Radio 2", .varname = "radio1");
-        ui_radiobutton(obj, .label = "Z Radio 3", .varname = "radio1");
-        
-        ui_newline(obj);
-        
-        ui_radiobutton(obj, .label = "X Radio 1", .varname = "radio2");
-        ui_radiobutton(obj, .label = "X Radio 2", .varname = "radio2");
-        ui_radiobutton(obj, .label = "X Radio 3", .varname = "radio2");
-        ui_newline(obj);
+    //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_textarea(obj, .fill = UI_OFF);
+    ui_button(obj, .label = "Button 2");
+    ui_button(obj, .label = "Button 3");
+    ui_button(obj, .label = "Button 4");
     
     ui_show(obj);
 }
--- a/ui/cocoa/container.m	Thu Mar 13 22:47:16 2025 +0100
+++ b/ui/cocoa/container.m	Sun Mar 16 13:53:30 2025 +0100
@@ -67,12 +67,21 @@
     if(self.orientation == NSUserInterfaceLayoutOrientationHorizontal) {
         [view.heightAnchor constraintEqualToAnchor:self.heightAnchor].active = YES;
         if(!fill) {
-            [view.widthAnchor constraintEqualToConstant:view.intrinsicContentSize.width].active = YES;
+            NSSize isize = view.intrinsicContentSize;
+            [view.widthAnchor constraintEqualToConstant:isize.width].active = YES;
         }
     } else {
         [view.widthAnchor constraintEqualToAnchor:self.widthAnchor].active = YES;
         if(!fill) {
-            [view.heightAnchor constraintEqualToConstant:view.intrinsicContentSize.height].active = YES;
+            NSSize isize = view.intrinsicContentSize;
+            NSRect frame = view.frame;
+            CGFloat height = isize.height > 0 ? isize.height : frame.size.height;
+            if(height == 0) {
+                printf("debug");
+            }
+            if(height > 0) {
+                [view.heightAnchor constraintEqualToConstant:height].active = YES;
+            }
         }
     }
     
--- a/ui/cocoa/objs.mk	Thu Mar 13 22:47:16 2025 +0100
+++ b/ui/cocoa/objs.mk	Sun Mar 16 13:53:30 2025 +0100
@@ -39,6 +39,7 @@
 COCOAOBJ += window.o
 COCOAOBJ += Container.o
 COCOAOBJ += button.o
+COCOAOBJ += text.o
 
 TOOLKITOBJS += $(COCOAOBJ:%=$(COCOA_OBJPRE)%)
 TOOLKITSOURCE += $(COCOAOBJ:%.o=cocoa/%.m)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ui/cocoa/text.h	Sun Mar 16 13:53:30 2025 +0100
@@ -0,0 +1,32 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2025 Olaf Wintermann. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above copyright
+ *      notice, this list of conditions and the following disclaimer in the
+ *      documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "toolkit.h"
+
+#import "../ui/text.h"
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ui/cocoa/text.m	Sun Mar 16 13:53:30 2025 +0100
@@ -0,0 +1,43 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2025 Olaf Wintermann. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above copyright
+ *      notice, this list of conditions and the following disclaimer in the
+ *      documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "text.h"
+#import "EventData.h"
+#import "Container.h"
+#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;
+    
+    UiLayout layout = UI_INIT_LAYOUT(args);
+    ui_container_add(obj, textview, &layout, TRUE);
+    
+    return (__bridge void*)textview;
+}

mercurial