# HG changeset patch # User Olaf Wintermann # Date 1759660482 -7200 # Node ID f8ff8df4171311d0e4c7d7a089ea6c2341c83fb4 # Parent 504c45926386b5def0e0886dab906bd297c330ee fix grid spacing (Cocoa) diff -r 504c45926386 -r f8ff8df41713 make/xcode/toolkit/toolkit/main.m --- a/make/xcode/toolkit/toolkit/main.m Sat Oct 04 18:33:58 2025 +0200 +++ b/make/xcode/toolkit/toolkit/main.m Sun Oct 05 12:34:42 2025 +0200 @@ -133,17 +133,20 @@ ui_button(obj, .label = "HBox Button 1"); ui_button(obj, .label = "HBox Button 2"); - ui_grid(obj, .fill = TRUE) { - ui_hbox(obj, .spacing = 0, .colspan = 2) { + ui_grid(obj, .fill = TRUE, .columnspacing = 20, .rowspacing = 10) { + ui_hbox(obj, .spacing = 8, .colspan = 1) { ui_button(obj, .label = "HBox Button 1"); ui_button(obj, .label = "HBox Button 2"); ui_button(obj, .label = "HBox Button 3"); + ui_button(obj, .label = "HBox Button 4"); } ui_newline(obj); ui_spinbox(obj, .width = 300, .varname = "number", .digits = 2, .step = 0.1); + ui_button(obj, .label = "spinbox", .hfill = TRUE); ui_newline(obj); ui_textfield(obj, .width = 300); + ui_button(obj, .label = "textfield", .hfill = TRUE); } ui_button(obj, .label = "HBox Button 3"); diff -r 504c45926386 -r f8ff8df41713 ui/cocoa/BoxContainer.m --- a/ui/cocoa/BoxContainer.m Sat Oct 04 18:33:58 2025 +0200 +++ b/ui/cocoa/BoxContainer.m Sun Oct 05 12:34:42 2025 +0200 @@ -13,7 +13,7 @@ return self; } -- (void) addView:(NSView*)view { +- (void) addView:(NSView*)view margin:(NSEdgeInsets)margin { UiLayout layout = self.uilayout; if(_orientation == NSUserInterfaceLayoutOrientationVertical) { layout.hexpand = TRUE; @@ -24,7 +24,7 @@ self.newline = FALSE; } self.uilayout = layout; - [super addView:view]; + [super addView:view margin:margin]; if(_orientation == NSUserInterfaceLayoutOrientationVertical) { self.newline = TRUE; } diff -r 504c45926386 -r f8ff8df41713 ui/cocoa/GridLayout.h --- a/ui/cocoa/GridLayout.h Sat Oct 04 18:33:58 2025 +0200 +++ b/ui/cocoa/GridLayout.h Sun Oct 05 12:34:42 2025 +0200 @@ -34,7 +34,7 @@ typedef struct GridElm { NSView *view; - int margin; + NSEdgeInsets margin; int x; int y; int colspan; diff -r 504c45926386 -r f8ff8df41713 ui/cocoa/GridLayout.m --- a/ui/cocoa/GridLayout.m Sat Oct 04 18:33:58 2025 +0200 +++ b/ui/cocoa/GridLayout.m Sun Oct 05 12:34:42 2025 +0200 @@ -184,17 +184,23 @@ int preferred_width = 0; int preferred_height = 0; for(int j=0;j 0) { + preferred_width += (ncols-1) * colspacing; + } + if(nrows > 0) { + preferred_height += (nrows-1) * rowspacing; + } _preferredSize.width = preferred_width; _preferredSize.height = preferred_height; @@ -292,7 +298,7 @@ return self.preferredSize; } -- (void) addView:(NSView*)view { +- (void) addView:(NSView*)view margin:(NSEdgeInsets)margin { _preferredSize.width = -1; _preferredSize.height = -1; @@ -305,7 +311,7 @@ GridElm elm; elm.x = _x; elm.y = _y; - elm.margin = 0; + elm.margin = margin; elm.colspan = _uilayout.colspan; elm.rowspan = _uilayout.rowspan; if(_uilayout.fill) { diff -r 504c45926386 -r f8ff8df41713 ui/cocoa/container.h --- a/ui/cocoa/container.h Sat Oct 04 18:33:58 2025 +0200 +++ b/ui/cocoa/container.h Sun Oct 05 12:34:42 2025 +0200 @@ -71,7 +71,7 @@ @property const char *label; @property UiBool newline; -- (void) addView:(NSView*)view; +- (void) addView:(NSView*)view margin:(NSEdgeInsets)margin; @end diff -r 504c45926386 -r f8ff8df41713 ui/cocoa/container.m --- a/ui/cocoa/container.m Sat Oct 04 18:33:58 2025 +0200 +++ b/ui/cocoa/container.m Sun Oct 05 12:34:42 2025 +0200 @@ -120,6 +120,8 @@ UIWIDGET ui_grid_create(UiObject *obj, UiContainerArgs *args) { GridLayout *grid = [[GridLayout alloc] init]; grid.translatesAutoresizingMaskIntoConstraints = false; + grid.columnspacing = args->columnspacing; + grid.rowspacing = args->rowspacing; // add box to the parent UiLayout layout = UI_INIT_LAYOUT(args); @@ -160,7 +162,8 @@ UiContainerX *ctn = obj->container_end; id container = (__bridge id)ctn->container; container.uilayout = *layout; - [container addView:view]; + NSEdgeInsets margin = {0}; // TODO + [container addView:view margin:margin]; } /* ---------------------- public layout functions ----------------------- */