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