Sun, 24 Aug 2025 15:24:16 +0200
update toolkit, remove getvalue func from model to table/listview args
|
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" | |
| 31 | ||
| 32 | /* ------------------------- container classes ------------------------- */ | |
|
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
33 | |
| 100 | 34 | @implementation BoxContainer |
|
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
35 | |
| 100 | 36 | @synthesize label=_label; |
| 37 | @synthesize uilayout=_uilayout; | |
| 38 | @synthesize newline=_newline; | |
|
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
39 | |
| 100 | 40 | - (BoxContainer*)init:(NSUserInterfaceLayoutOrientation)orientation spacing:(int)spacing { |
| 41 | self = [super init]; | |
| 42 | _label = NULL; | |
| 43 | _uilayout = (UiLayout){ 0 }; | |
| 44 | _newline = false; | |
| 45 | ||
| 46 | self.distribution = NSStackViewDistributionFillProportionally; | |
| 47 | self.spacing = spacing; | |
| 48 | ||
| 49 | self.orientation = orientation; | |
| 50 | if(orientation == NSUserInterfaceLayoutOrientationHorizontal) { | |
| 51 | self.alignment = NSLayoutAttributeHeight; | |
| 52 | } else { | |
| 53 | self.alignment = NSLayoutAttributeWidth; | |
| 54 | } | |
| 55 | ||
| 56 | ||
| 57 | return self; | |
|
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
58 | } |
|
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
59 | |
|
109
c3dfcb8f0be7
update toolkit, remove getvalue func from model to table/listview args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
108
diff
changeset
|
60 | - (void) addView:(NSView*)view { |
|
c3dfcb8f0be7
update toolkit, remove getvalue func from model to table/listview args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
108
diff
changeset
|
61 | UiBool fill = _uilayout.fill; |
|
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
62 | |
| 100 | 63 | [self addArrangedSubview:view]; |
|
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
64 | |
| 100 | 65 | if(self.orientation == NSUserInterfaceLayoutOrientationHorizontal) { |
| 66 | [view.heightAnchor constraintEqualToAnchor:self.heightAnchor].active = YES; | |
| 67 | if(!fill) { | |
|
103
6606616eca9f
update uwproj, toolkit, libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
100
diff
changeset
|
68 | NSSize isize = view.intrinsicContentSize; |
|
6606616eca9f
update uwproj, toolkit, libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
100
diff
changeset
|
69 | [view.widthAnchor constraintEqualToConstant:isize.width].active = YES; |
| 100 | 70 | } |
| 71 | } else { | |
| 72 | [view.widthAnchor constraintEqualToAnchor:self.widthAnchor].active = YES; | |
| 73 | if(!fill) { | |
|
103
6606616eca9f
update uwproj, toolkit, libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
100
diff
changeset
|
74 | NSSize isize = view.intrinsicContentSize; |
|
6606616eca9f
update uwproj, toolkit, libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
100
diff
changeset
|
75 | NSRect frame = view.frame; |
|
6606616eca9f
update uwproj, toolkit, libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
100
diff
changeset
|
76 | CGFloat height = isize.height > 0 ? isize.height : frame.size.height; |
|
6606616eca9f
update uwproj, toolkit, libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
100
diff
changeset
|
77 | if(height == 0) { |
|
6606616eca9f
update uwproj, toolkit, libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
100
diff
changeset
|
78 | printf("debug"); |
|
6606616eca9f
update uwproj, toolkit, libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
100
diff
changeset
|
79 | } |
|
6606616eca9f
update uwproj, toolkit, libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
100
diff
changeset
|
80 | if(height > 0) { |
|
6606616eca9f
update uwproj, toolkit, libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
100
diff
changeset
|
81 | [view.heightAnchor constraintEqualToConstant:height].active = YES; |
|
6606616eca9f
update uwproj, toolkit, libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
100
diff
changeset
|
82 | } |
| 100 | 83 | } |
| 84 | } | |
|
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
85 | |
| 100 | 86 | // at the moment, only the fill layout option needs to be reset |
| 87 | _uilayout.fill = UI_DEFAULT; | |
| 88 | } | |
| 89 | ||
| 90 | @end | |
| 91 | ||
| 92 | ||
| 93 | ||
| 94 | /* -------------------- public container functions --------------------- */ | |
| 95 | ||
|
108
77254bd6dccb
update toolkit, adjust UI code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
96 | 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
|
97 | BoxContainer *box = [[BoxContainer alloc] init:orientation spacing:args->spacing]; |
| 100 | 98 | box.translatesAutoresizingMaskIntoConstraints = false; |
|
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
99 | |
| 100 | 100 | // add box to the parent |
| 101 | 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
|
102 | ui_container_add(obj, box, &layout); |
| 100 | 103 | |
| 104 | // add new box to the obj container chain | |
| 105 | uic_object_push_container(obj, ui_create_container(obj, box)); | |
|
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
106 | |
| 100 | 107 | return (__bridge void*)box; |
| 108 | } | |
| 109 | ||
|
108
77254bd6dccb
update toolkit, adjust UI code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
110 | UIWIDGET ui_vbox_create(UiObject *obj, UiContainerArgs *args) { |
| 100 | 111 | return ui_box_create(obj, args, NSUserInterfaceLayoutOrientationVertical); |
| 112 | } | |
| 113 | ||
|
108
77254bd6dccb
update toolkit, adjust UI code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
114 | UIWIDGET ui_hbox_create(UiObject *obj, UiContainerArgs *args) { |
| 100 | 115 | return ui_box_create(obj, args, NSUserInterfaceLayoutOrientationHorizontal); |
| 116 | } | |
| 117 | ||
|
108
77254bd6dccb
update toolkit, adjust UI code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
118 | UIWIDGET ui_grid_create(UiObject *obj, UiContainerArgs *args) { |
| 100 | 119 | GridLayout *grid = [[GridLayout alloc] init]; |
| 120 | grid.translatesAutoresizingMaskIntoConstraints = false; | |
|
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
121 | |
| 100 | 122 | // add box to the parent |
| 123 | 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
|
124 | ui_container_add(obj, grid, &layout); |
|
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
125 | |
| 100 | 126 | // add new box to the obj container chain |
| 127 | uic_object_push_container(obj, ui_create_container(obj, grid)); | |
| 128 | ||
| 129 | return (__bridge void*)grid; | |
|
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
130 | } |
|
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
131 | |
|
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
132 | |
| 100 | 133 | void ui_container_begin_close(UiObject *obj) { |
| 134 | UiContainerX *ct = obj->container_end; | |
| 135 | ct->close = 1; | |
| 136 | } | |
| 137 | ||
| 138 | int ui_container_finish(UiObject *obj) { | |
| 139 | UiContainerX *ct = obj->container_end; | |
| 140 | if(ct->close) { | |
| 141 | ui_end_new(obj); | |
| 142 | return 0; | |
| 143 | } | |
| 144 | return 1; | |
|
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
145 | } |
|
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
146 | |
| 100 | 147 | /* ------------------------- private functions ------------------------- */ |
| 148 | ||
| 149 | UiContainerX* ui_create_container(UiObject *obj, id<Container> container) { | |
| 150 | UiContainerX *ctn = ui_malloc(obj->ctx, sizeof(UiContainerX)); | |
| 151 | ctn->container = (__bridge void*)container; | |
| 152 | ctn->close = 0; | |
| 153 | ctn->prev = NULL; | |
| 154 | ctn->next = NULL; | |
| 155 | return ctn; | |
|
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
156 | } |
| 100 | 157 | |
|
109
c3dfcb8f0be7
update toolkit, remove getvalue func from model to table/listview args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
108
diff
changeset
|
158 | void ui_container_add(UiObject *obj, NSView *view, UiLayout *layout) { |
| 100 | 159 | UiContainerX *ctn = obj->container_end; |
| 160 | id<Container> container = (__bridge id<Container>)ctn->container; | |
| 161 | container.uilayout = *layout; | |
|
109
c3dfcb8f0be7
update toolkit, remove getvalue func from model to table/listview args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
108
diff
changeset
|
162 | [container addView:view]; |
| 100 | 163 | } |
| 164 | ||
| 165 | /* ---------------------- public layout functions ----------------------- */ | |
| 166 | ||
| 167 | void ui_newline(UiObject *obj) { | |
| 168 | UiContainerX *ctn = obj->container_end; | |
| 169 | if(ctn) { | |
| 170 | id<Container> container = (__bridge id<Container>)ctn->container; | |
| 171 | container.newline = TRUE; | |
| 172 | } else { | |
| 173 | fprintf(stderr, "Error: obj has no container\n"); | |
| 174 | } | |
| 175 | } |