Mon, 10 Nov 2025 21:52:51 +0100
update ucx
|
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1 | /* |
|
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
|
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
3 | * |
| 100 | 4 | * Copyright 2024 Olaf Wintermann. All rights reserved. |
|
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
5 | * |
|
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
|
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
|
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
8 | * |
|
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
|
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
|
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
11 | * |
|
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
|
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
|
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
|
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
15 | * |
|
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
|
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
|
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
27 | */ |
|
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
28 | |
| 100 | 29 | #import "Container.h" |
| 30 | #import "GridLayout.h" | |
|
110
c00e968d018b
fix repolist menu button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
109
diff
changeset
|
31 | #import "BoxContainer.h" |
| 112 | 32 | #import "TabView.h" |
| 100 | 33 | |
| 34 | /* -------------------- public container functions --------------------- */ | |
| 35 | ||
|
108
77254bd6dccb
update toolkit, adjust UI code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
36 | static UIWIDGET ui_box_create(UiObject *obj, UiContainerArgs *args, NSUserInterfaceLayoutOrientation orientation) { |
|
77254bd6dccb
update toolkit, adjust UI code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
37 | BoxContainer *box = [[BoxContainer alloc] init:orientation spacing:args->spacing]; |
| 100 | 38 | box.translatesAutoresizingMaskIntoConstraints = false; |
| 112 | 39 | UiContainerX *container = ui_create_container(obj, box); |
|
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
40 | |
| 100 | 41 | // add box to the parent |
| 42 | UiLayout layout = UI_INIT_LAYOUT(args); | |
|
109
c3dfcb8f0be7
update toolkit, remove getvalue func from model to table/listview args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
108
diff
changeset
|
43 | ui_container_add(obj, box, &layout); |
| 100 | 44 | |
| 45 | // add new box to the obj container chain | |
| 112 | 46 | uic_object_push_container(obj, container); |
|
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
47 | |
| 100 | 48 | return (__bridge void*)box; |
| 49 | } | |
| 50 | ||
|
108
77254bd6dccb
update toolkit, adjust UI code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
51 | UIWIDGET ui_vbox_create(UiObject *obj, UiContainerArgs *args) { |
| 100 | 52 | return ui_box_create(obj, args, NSUserInterfaceLayoutOrientationVertical); |
| 53 | } | |
| 54 | ||
|
108
77254bd6dccb
update toolkit, adjust UI code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
55 | UIWIDGET ui_hbox_create(UiObject *obj, UiContainerArgs *args) { |
| 100 | 56 | return ui_box_create(obj, args, NSUserInterfaceLayoutOrientationHorizontal); |
| 57 | } | |
| 58 | ||
|
108
77254bd6dccb
update toolkit, adjust UI code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
59 | UIWIDGET ui_grid_create(UiObject *obj, UiContainerArgs *args) { |
| 100 | 60 | GridLayout *grid = [[GridLayout alloc] init]; |
| 61 | grid.translatesAutoresizingMaskIntoConstraints = false; | |
| 112 | 62 | grid.columnspacing = args->columnspacing; |
| 63 | grid.rowspacing = args->rowspacing; | |
| 64 | UiContainerX *container = ui_create_container(obj, grid); | |
| 65 | grid.container = container; | |
|
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
66 | |
| 100 | 67 | // add box to the parent |
| 68 | UiLayout layout = UI_INIT_LAYOUT(args); | |
|
109
c3dfcb8f0be7
update toolkit, remove getvalue func from model to table/listview args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
108
diff
changeset
|
69 | ui_container_add(obj, grid, &layout); |
|
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
70 | |
| 100 | 71 | // add new box to the obj container chain |
| 112 | 72 | uic_object_push_container(obj, container); |
| 100 | 73 | |
| 74 | return (__bridge void*)grid; | |
|
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
75 | } |
|
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
76 | |
| 112 | 77 | UIWIDGET ui_frame_create(UiObject *obj, UiFrameArgs *args) { |
| 78 | NSString *title = args->label ? [[NSString alloc]initWithUTF8String:args->label] : nil; | |
| 79 | FrameContainer *frame = [[FrameContainer alloc] init:title]; | |
| 80 | UiLayout layout = UI_ARGS2LAYOUT(args); | |
| 81 | ui_container_add(obj, frame, &layout); | |
| 82 | ||
| 83 | // add container to the chain | |
| 84 | UiContainerX *container; | |
| 85 | UiLayout subLayout = {0}; | |
| 86 | switch(args->subcontainer) { | |
| 87 | default: { | |
| 88 | // UI_CONTAINER_NO_SUB | |
| 89 | container = ui_create_container(obj, frame); | |
| 90 | break; | |
| 91 | } | |
| 92 | case UI_CONTAINER_VBOX: { | |
| 93 | BoxContainer *box = [[BoxContainer alloc]init:NSUserInterfaceLayoutOrientationVertical spacing:args->spacing]; | |
| 94 | box.translatesAutoresizingMaskIntoConstraints = false; | |
| 95 | [frame addView:box layout:&subLayout]; | |
| 96 | container = ui_create_container(obj, box); | |
| 97 | break; | |
| 98 | } | |
| 99 | case UI_CONTAINER_HBOX: { | |
| 100 | BoxContainer *box = [[BoxContainer alloc]init:NSUserInterfaceLayoutOrientationHorizontal spacing:args->spacing]; | |
| 101 | box.translatesAutoresizingMaskIntoConstraints = false; | |
| 102 | [frame addView:box layout:&subLayout]; | |
| 103 | container = ui_create_container(obj, box); | |
| 104 | break; | |
| 105 | } | |
| 106 | case UI_CONTAINER_GRID: { | |
| 107 | GridLayout *grid = [[GridLayout alloc] init]; | |
| 108 | grid.translatesAutoresizingMaskIntoConstraints = false; | |
| 109 | grid.columnspacing = args->columnspacing; | |
| 110 | grid.rowspacing = args->rowspacing; | |
| 111 | [frame addView:grid layout:&subLayout]; | |
| 112 | container = ui_create_container(obj, grid); | |
| 113 | break; | |
| 114 | } | |
| 115 | } | |
| 116 | ||
| 117 | uic_object_push_container(obj, container); | |
| 118 | ||
| 119 | return (__bridge void*)frame; | |
| 120 | } | |
| 121 | ||
| 122 | UIWIDGET ui_expander_create(UiObject *obj, UiFrameArgs *args) { | |
| 123 | return ui_frame_create(obj, args); // TODO | |
| 124 | } | |
| 125 | ||
| 126 | UIWIDGET ui_scrolledwindow_create(UiObject *obj, UiFrameArgs *args) { | |
| 127 | int colspacing = args->spacing; | |
| 128 | int rowspacing = args->spacing; | |
| 129 | if(args->subcontainer == UI_CONTAINER_GRID) { | |
| 130 | colspacing = args->columnspacing; | |
| 131 | rowspacing = args->rowspacing; | |
| 132 | } | |
| 133 | ScrollViewContainer *scrollview = [[ScrollViewContainer alloc]init:args->subcontainer columnSpacing:colspacing rowSpacing:rowspacing]; | |
| 134 | scrollview.hasVerticalScroller = YES; | |
| 135 | scrollview.scrollerStyle = NSScrollerStyleOverlay; | |
| 136 | scrollview.autohidesScrollers = YES; | |
| 137 | UiLayout layout = UI_ARGS2LAYOUT(args); | |
| 138 | ui_container_add(obj, scrollview, &layout); | |
| 139 | ||
| 140 | UiContainerX *container = ui_create_container(obj, scrollview); | |
| 141 | uic_object_push_container(obj, container); | |
| 142 | ||
| 143 | return (__bridge void*)scrollview; | |
| 144 | } | |
| 145 | ||
| 146 | UIWIDGET ui_tabview_create(UiObject *obj, UiTabViewArgs *args) { | |
| 147 | NSView<TabView, Container> *tabview; | |
| 148 | switch(args->tabview) { | |
| 149 | default: tabview = [[UiTopTabView alloc]init:obj args:args]; break; | |
| 150 | } | |
| 151 | ||
| 152 | UiLayout layout = UI_ARGS2LAYOUT(args); | |
| 153 | ui_container_add(obj, tabview, &layout); | |
| 154 | ||
| 155 | UiContainerX *container = ui_create_container(obj, tabview); | |
| 156 | uic_object_push_container(obj, container); | |
| 157 | ||
| 158 | return (__bridge void*)tabview; | |
| 159 | } | |
| 160 | ||
| 161 | void ui_tab_create(UiObject *obj, const char* title) { | |
| 162 | UiContainerX *ctn = obj->container_end; | |
| 163 | id<TabView> tabview = (__bridge id<TabView>)ctn->container; | |
| 164 | NSString *s = title ? [[NSString alloc]initWithUTF8String:title] : @""; | |
| 165 | NSView<Container> *sub = [tabview createTab:-1 title:s]; | |
| 166 | ||
| 167 | UiContainerX *container = ui_create_container(obj, sub); | |
| 168 | uic_object_push_container(obj, container); | |
| 169 | } | |
| 170 | ||
| 171 | void ui_tabview_select(UIWIDGET tabview, int tab) { | |
| 172 | id<TabView> tabv = (__bridge id<TabView>)tabview; | |
| 173 | [tabv selectTab:tab]; | |
| 174 | } | |
| 175 | ||
| 176 | void ui_tabview_remove(UIWIDGET tabview, int tab) { | |
| 177 | id<TabView> tabv = (__bridge id<TabView>)tabview; | |
| 178 | [tabv removeTab:tab]; | |
| 179 | } | |
| 180 | ||
| 181 | UiObject* ui_tabview_add(UIWIDGET tabview, const char *name, int tab_index) { | |
| 182 | id<TabView> tabv = (__bridge id<TabView>)tabview; | |
| 183 | NSString *s = name ? [[NSString alloc]initWithUTF8String:name] : @""; | |
| 184 | return [tabv addTab:tab_index title:s]; | |
| 185 | } | |
| 186 | ||
| 187 | ||
| 113 | 188 | UIWIDGET ui_headerbar_create(UiObject *obj, UiHeaderbarArgs *args) { |
| 189 | return NULL; // TODO | |
| 190 | } | |
| 191 | ||
| 192 | UIWIDGET ui_itemlist_create(UiObject *obj, UiItemListContainerArgs *args) { | |
| 193 | return NULL; // TODO | |
| 194 | } | |
| 195 | ||
| 196 | UIWIDGET ui_hsplitpane_create(UiObject *obj, UiSplitPaneArgs *args) { | |
| 197 | return NULL; // TODO | |
| 198 | } | |
| 199 | ||
| 200 | UIWIDGET ui_vsplitpane_create(UiObject *obj, UiSplitPaneArgs *args) { | |
| 201 | return NULL; // TODO | |
| 202 | } | |
| 203 | ||
| 112 | 204 | |
| 205 | ||
| 100 | 206 | void ui_container_begin_close(UiObject *obj) { |
| 207 | UiContainerX *ct = obj->container_end; | |
| 208 | ct->close = 1; | |
| 209 | } | |
| 210 | ||
| 211 | int ui_container_finish(UiObject *obj) { | |
| 212 | UiContainerX *ct = obj->container_end; | |
| 213 | if(ct->close) { | |
| 214 | ui_end_new(obj); | |
| 215 | return 0; | |
| 216 | } | |
| 217 | return 1; | |
|
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
218 | } |
|
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
219 | |
| 112 | 220 | /* -------------------------- Frame Container -------------------------- */ |
| 221 | ||
| 222 | @implementation FrameContainer | |
| 223 | ||
| 224 | @synthesize container = _container; | |
| 225 | ||
| 226 | - (id)init:(NSString*)title { | |
| 227 | self = [super init]; | |
| 228 | self.title = title; | |
| 229 | self.boxType = NSBoxPrimary; | |
| 230 | if(title != nil) { | |
| 231 | self.titlePosition = NSAtTop; | |
| 232 | } | |
| 233 | return self; | |
| 234 | } | |
| 235 | ||
| 236 | - (void) addView:(NSView*)view layout:(UiLayout*)layout { | |
| 237 | [self.contentView addSubview:view]; | |
| 238 | view.translatesAutoresizingMaskIntoConstraints = NO; | |
| 239 | [NSLayoutConstraint activateConstraints:@[ | |
| 240 | [view.topAnchor constraintEqualToAnchor:self.contentView.topAnchor constant:0], | |
| 241 | [view.leadingAnchor constraintEqualToAnchor:self.contentView.leadingAnchor constant:0], | |
| 242 | [view.bottomAnchor constraintEqualToAnchor:self.contentView.bottomAnchor constant:-0], | |
| 243 | [view.trailingAnchor constraintEqualToAnchor:self.contentView.trailingAnchor constant:-0] | |
| 244 | ]]; | |
| 245 | } | |
| 246 | ||
| 247 | @end | |
| 248 | ||
| 249 | ||
| 250 | /* -------------------------- Expander Container -------------------------- */ | |
| 251 | ||
| 252 | // TODO | |
| 253 | ||
| 254 | ||
| 255 | /* ------------------------ ScrollView Container ------------------------ */ | |
| 256 | ||
| 257 | @implementation ScrollViewContainer | |
| 258 | ||
| 259 | @synthesize container = _container; | |
| 260 | ||
| 261 | - (id)init:(UiSubContainerType)subContainer columnSpacing:(int)columnSpacing rowSpacing:(int)rowSpacing { | |
| 262 | self = [super init]; | |
| 263 | ||
| 264 | if(subContainer != UI_CONTAINER_NO_SUB) { | |
| 265 | GridLayout *child; | |
| 266 | switch(subContainer) { | |
| 267 | default: | |
| 268 | case UI_CONTAINER_VBOX: { | |
| 269 | child = [[BoxContainer alloc]init:NSUserInterfaceLayoutOrientationVertical spacing:columnSpacing]; | |
| 270 | break; | |
| 271 | } | |
| 272 | case UI_CONTAINER_HBOX: { | |
| 273 | child = [[BoxContainer alloc]init:NSUserInterfaceLayoutOrientationHorizontal spacing:columnSpacing]; | |
| 274 | break; | |
| 275 | } | |
| 276 | case UI_CONTAINER_GRID: { | |
| 277 | child = [[GridLayout alloc]init]; | |
| 278 | child.columnspacing = columnSpacing; | |
| 279 | child.rowspacing = rowSpacing; | |
| 280 | break; | |
| 281 | } | |
| 282 | } | |
| 283 | child.translatesAutoresizingMaskIntoConstraints = NO; | |
| 284 | ||
| 285 | self.documentView = child; | |
| 286 | [child.widthAnchor constraintEqualToAnchor:self.contentView.widthAnchor].active = YES; | |
| 287 | ||
| 288 | _child = child; | |
| 289 | } | |
| 290 | ||
| 291 | ||
| 292 | return self; | |
| 293 | } | |
| 294 | ||
| 295 | - (void) addView:(NSView*)view layout:(UiLayout*)layout { | |
| 296 | if(_child != nil) { | |
| 297 | _child.container = self.container; // required, otherwise child has no container and can't access the newline property | |
| 298 | view.translatesAutoresizingMaskIntoConstraints = NO; | |
| 299 | [_child addView:view layout:layout]; | |
| 300 | } else { | |
| 301 | self.documentView = view; | |
| 302 | [view.widthAnchor constraintEqualToAnchor:self.contentView.widthAnchor].active = YES; | |
| 303 | } | |
| 304 | } | |
| 305 | ||
| 306 | @end | |
| 307 | ||
| 100 | 308 | /* ------------------------- private functions ------------------------- */ |
| 309 | ||
| 310 | UiContainerX* ui_create_container(UiObject *obj, id<Container> container) { | |
| 311 | UiContainerX *ctn = ui_malloc(obj->ctx, sizeof(UiContainerX)); | |
| 312 | ctn->container = (__bridge void*)container; | |
| 313 | ctn->close = 0; | |
| 314 | ctn->prev = NULL; | |
| 315 | ctn->next = NULL; | |
| 112 | 316 | container.container = ctn; |
| 100 | 317 | return ctn; |
|
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
318 | } |
| 100 | 319 | |
|
109
c3dfcb8f0be7
update toolkit, remove getvalue func from model to table/listview args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
108
diff
changeset
|
320 | void ui_container_add(UiObject *obj, NSView *view, UiLayout *layout) { |
| 100 | 321 | UiContainerX *ctn = obj->container_end; |
| 322 | id<Container> container = (__bridge id<Container>)ctn->container; | |
| 112 | 323 | UiLayout adjustedLayout = *layout; |
| 324 | if(adjustedLayout.margin > 0) { | |
| 325 | adjustedLayout.margin_left = adjustedLayout.margin; | |
| 326 | adjustedLayout.margin_right = adjustedLayout.margin; | |
| 327 | adjustedLayout.margin_top = adjustedLayout.margin; | |
| 328 | adjustedLayout.margin_bottom = adjustedLayout.margin; | |
| 329 | } | |
| 330 | [container addView:view layout:&adjustedLayout]; | |
| 100 | 331 | } |
| 332 |