# HG changeset patch # User Olaf Wintermann # Date 1760431281 -7200 # Node ID 50de0f36973fe2d95e4b0ef656a98318291f8161 # Parent ffa983c223c1673b9ec48ffd91fa155453453266 add scrolledwindow container (Cocoa) diff -r ffa983c223c1 -r 50de0f36973f make/xcode/toolkit/toolkit/main.m --- a/make/xcode/toolkit/toolkit/main.m Tue Oct 14 09:45:44 2025 +0200 +++ b/make/xcode/toolkit/toolkit/main.m Tue Oct 14 10:41:21 2025 +0200 @@ -147,7 +147,7 @@ ui_linkbutton(obj, .varname = "link", .hexpand = TRUE, .hfill = TRUE); ui_newline(obj); - ui_frame(obj, .label = "Test", .margin = 10, .hfill = TRUE, .vfill = TRUE, .hexpand = TRUE, .vexpand = TRUE, .subcontainer = UI_CONTAINER_VBOX, .spacing = 10) { + ui_frame(obj, .label = "Test", .margin_bottom = 10, .hfill = TRUE, .vfill = TRUE, .hexpand = TRUE, .vexpand = TRUE, .subcontainer = UI_CONTAINER_VBOX, .spacing = 10) { ui_button(obj, .label = "Test Button"); ui_button(obj, .label = "Test Button"); ui_button(obj, .label = "Test Button"); @@ -158,9 +158,21 @@ } ui_right_panel0(obj) { + /* ui_grid(obj, .margin_left = 10, .margin_right = 10, .fill = TRUE) { ui_button(obj, .label = "right", .hexpand = TRUE, .hfill = TRUE); } + */ + + ui_scrolledwindow(obj, .margin_left = 10, .margin_right = 10, .fill = TRUE, .subcontainer = UI_CONTAINER_NO_SUB) { + ui_vbox(obj, .margin = 0) { + for(int i=0;i<50;i++) { + char label[32]; + snprintf(label, 32, "Button %d", i); + ui_button(obj, .label = label); + } + } + } } ui_linkbutton_value_set(doc->link, "unixwork", "https://unixwork.de/"); diff -r ffa983c223c1 -r 50de0f36973f ui/cocoa/container.h --- a/ui/cocoa/container.h Tue Oct 14 09:45:44 2025 +0200 +++ b/ui/cocoa/container.h Tue Oct 14 10:41:21 2025 +0200 @@ -66,7 +66,13 @@ @end +@interface ScrollViewContainer : NSScrollView +@property NSView *child; + +- (id)init:(UiSubContainerType)subContainer columnSpacing:(int)columnSpacing rowSpacing:(int)rowSpacing; + +@end UiContainerX* ui_create_container(UiObject *obj, id container); diff -r ffa983c223c1 -r 50de0f36973f ui/cocoa/container.m --- a/ui/cocoa/container.m Tue Oct 14 09:45:44 2025 +0200 +++ b/ui/cocoa/container.m Tue Oct 14 10:41:21 2025 +0200 @@ -76,7 +76,8 @@ UIWIDGET ui_frame_create(UiObject *obj, UiFrameArgs *args) { NSString *title = args->label ? [[NSString alloc]initWithUTF8String:args->label] : nil; - FrameContainer *frame = [[FrameContainer alloc] init:title]; UiLayout layout = UI_ARGS2LAYOUT(args); + FrameContainer *frame = [[FrameContainer alloc] init:title]; + UiLayout layout = UI_ARGS2LAYOUT(args); ui_container_add(obj, frame, &layout); // add container to the chain @@ -115,7 +116,27 @@ uic_object_push_container(obj, container); - return NULL; + return (__bridge void*)frame; +} + +UIWIDGET ui_scrolledwindow_create(UiObject *obj, UiFrameArgs *args) { + int colspacing = args->spacing; + int rowspacing = args->spacing; + if(args->subcontainer == UI_CONTAINER_GRID) { + colspacing = args->columnspacing; + rowspacing = args->rowspacing; + } + ScrollViewContainer *scrollview = [[ScrollViewContainer alloc]init:args->subcontainer columnSpacing:colspacing rowSpacing:rowspacing]; + scrollview.hasVerticalScroller = YES; + scrollview.scrollerStyle = NSScrollerStyleOverlay; + scrollview.autohidesScrollers = YES; + UiLayout layout = UI_ARGS2LAYOUT(args); + ui_container_add(obj, scrollview, &layout); + + UiContainerX *container = ui_create_container(obj, scrollview); + uic_object_push_container(obj, container); + + return (__bridge void*)scrollview; } void ui_container_begin_close(UiObject *obj) { @@ -161,6 +182,65 @@ @end + +/* -------------------------- Expander Container -------------------------- */ + +// TODO + + +/* ------------------------ ScrollView Container ------------------------ */ + +@implementation ScrollViewContainer + +@synthesize container = _container; + +- (id)init:(UiSubContainerType)subContainer columnSpacing:(int)columnSpacing rowSpacing:(int)rowSpacing { + self = [super init]; + + if(subContainer != UI_CONTAINER_NO_SUB) { + GridLayout *child; + switch(subContainer) { + default: + case UI_CONTAINER_VBOX: { + child = [[BoxContainer alloc]init:NSUserInterfaceLayoutOrientationVertical spacing:columnSpacing]; + break; + } + case UI_CONTAINER_HBOX: { + child = [[BoxContainer alloc]init:NSUserInterfaceLayoutOrientationHorizontal spacing:columnSpacing]; + break; + } + case UI_CONTAINER_GRID: { + child = [[GridLayout alloc]init]; + child.columnspacing = columnSpacing; + child.rowspacing = rowSpacing; + break; + } + } + child.translatesAutoresizingMaskIntoConstraints = NO; + + self.documentView = child; + [child.widthAnchor constraintEqualToAnchor:self.contentView.widthAnchor].active = YES; + + _child = child; + } + + + return self; +} + +- (void) addView:(NSView*)view layout:(UiLayout*)layout { + if(_child != nil) { + _child.container = self.container; // required, otherwise child has no container and can't access the newline property + view.translatesAutoresizingMaskIntoConstraints = NO; + [_child addView:view layout:layout]; + } else { + self.documentView = view; + [view.widthAnchor constraintEqualToAnchor:self.contentView.widthAnchor].active = YES; + } +} + +@end + /* ------------------------- private functions ------------------------- */ UiContainerX* ui_create_container(UiObject *obj, id container) { @@ -183,6 +263,6 @@ adjustedLayout.margin_top = adjustedLayout.margin; adjustedLayout.margin_bottom = adjustedLayout.margin; } - [container addView:view layout:layout]; + [container addView:view layout:&adjustedLayout]; } diff -r ffa983c223c1 -r 50de0f36973f ui/cocoa/label.m --- a/ui/cocoa/label.m Tue Oct 14 09:45:44 2025 +0200 +++ b/ui/cocoa/label.m Tue Oct 14 10:41:21 2025 +0200 @@ -51,7 +51,7 @@ label.stringValue = str; } - UiLayout layout = UI_INIT_LAYOUT(args); + UiLayout layout = UI_ARGS2LAYOUT(args); ui_container_add(obj, label, &layout); UiVar *var = uic_widget_var(obj->ctx, obj->ctx, args->value, args->varname, UI_VAR_STRING);