nomen-lang 0.7.1 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/audit_runtime.c +12 -2
- package/core/System/Arena.nm +8 -1
- package/core/System/Buffer.nm +397 -8
- package/core/System/ClassBuffer.nm +156 -0
- package/core/System/Controls/Alert.nm +326 -0
- package/core/System/Controls/App.nm +147 -0
- package/core/System/Controls/Button.nm +119 -1
- package/core/System/Controls/CheckBox.nm +25 -1
- package/core/System/Controls/ColorPicker.nm +307 -0
- package/core/System/Controls/ComboBox.nm +430 -0
- package/core/System/Controls/Container.nm +843 -9
- package/core/System/Controls/Control.nm +443 -0
- package/core/System/Controls/DatePicker.nm +288 -0
- package/core/System/Controls/Form.nm +70 -0
- package/core/System/Controls/GroupBox.nm +267 -0
- package/core/System/Controls/ImageView.nm +311 -0
- package/core/System/Controls/LevelIndicator.nm +305 -0
- package/core/System/Controls/ListView.nm +633 -0
- package/core/System/Controls/Menu.nm +428 -0
- package/core/System/Controls/NumberInput.nm +56 -0
- package/core/System/Controls/OtpInput.nm +50 -0
- package/core/System/Controls/OutlineView.nm +598 -0
- package/core/System/Controls/Pagination.nm +142 -0
- package/core/System/Controls/Popover.nm +296 -0
- package/core/System/Controls/Progress.nm +348 -0
- package/core/System/Controls/Radio.nm +292 -0
- package/core/System/Controls/Scrollable.nm +584 -0
- package/core/System/Controls/SearchField.nm +326 -0
- package/core/System/Controls/SecureField.nm +344 -0
- package/core/System/Controls/Segmented.nm +380 -0
- package/core/System/Controls/Select.nm +340 -0
- package/core/System/Controls/Separator.nm +198 -0
- package/core/System/Controls/Sheet.nm +329 -0
- package/core/System/Controls/Slider.nm +315 -0
- package/core/System/Controls/Spinner.nm +287 -0
- package/core/System/Controls/SplitView.nm +509 -0
- package/core/System/Controls/Stepper.nm +349 -0
- package/core/System/Controls/Switch.nm +259 -0
- package/core/System/Controls/Table.nm +833 -0
- package/core/System/Controls/Tabs.nm +500 -0
- package/core/System/Controls/Text.nm +108 -11
- package/core/System/Controls/TextBox.nm +113 -2
- package/core/System/Controls/TextView.nm +329 -0
- package/core/System/Controls/Toggle.nm +346 -0
- package/core/System/Controls/Toolbar.nm +501 -0
- package/core/System/Controls/Tooltip.nm +76 -0
- package/core/System/Controls/Window.nm +1548 -91
- package/core/System/LinkedList.nm +8 -1
- package/core/System/List.nm +97 -7
- package/core/System/Map.nm +191 -18
- package/core/System/Mutex.nm +4 -4
- package/core/System/Random.nm +3 -4
- package/core/System/Set.nm +101 -13
- package/core/System/StableList.nm +371 -0
- package/core/System/Stream/Directory.nm +2 -2
- package/core/System/Stream/File.nm +2 -2
- package/core/System/Stream/Http.nm +2 -2
- package/core/System/String.nm +10 -5
- package/core/System/StringBuilder.nm +213 -2
- package/core/System/Text/CharIndex.nm +9 -9
- package/core/System/Text/Json.nm +60 -46
- package/core/System/Text/JsonTree.nm +120 -92
- package/core/System/Text/Regex.nm +23 -18
- package/core/System/Text/Utf8.nm +5 -5
- package/core/System/float.nm +36 -22
- package/core/System/int.nm +80 -28
- package/core/System/int16.nm +11 -0
- package/core/System/int32.nm +11 -0
- package/core/System/int64.nm +11 -0
- package/core/System/int8.nm +11 -0
- package/core/System/uint.nm +11 -0
- package/core/System/uint16.nm +11 -0
- package/core/System/uint32.nm +11 -0
- package/core/System/uint64.nm +11 -0
- package/core/System/uint8.nm +11 -0
- package/core/docs/System/StringBuilder.md +6 -0
- package/core/docs/System/Text/JsonTree.md +3 -2
- package/dist/index.mjs +38332 -30604
- package/package.json +1 -1
- package/src/bench_loop.nm +9 -9
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A row of mutually exclusive segment buttons
|
|
3
|
+
*
|
|
4
|
+
* An OWNING STRUCT (STRUCT_PLAN_3 Phase R, tranche 4 — the shape menu): the
|
|
5
|
+
* single field is a platform handle, so the value is movable and its
|
|
6
|
+
* `#destroy` releases what the handle names. The constructor's `self` is
|
|
7
|
+
* the inline instance (the `.` accessor); methods keep the pointer form.
|
|
8
|
+
*
|
|
9
|
+
* The segment count is fixed at construction; labels and the selection are
|
|
10
|
+
* set/poll per frame like every other control.
|
|
11
|
+
**/
|
|
12
|
+
pub mv struct Segmented: Control {
|
|
13
|
+
var uint64 handle = 0
|
|
14
|
+
|
|
15
|
+
pub func #init = (self, Window window, int count) {
|
|
16
|
+
```
|
|
17
|
+
#arch: c
|
|
18
|
+
#platform: macos
|
|
19
|
+
id seg = ((id(*)(id, SEL, CGRect))objc_msgSend)(
|
|
20
|
+
((id(*)(id, SEL))objc_msgSend)((id)objc_getClass("NSSegmentedControl"), sel_registerName("alloc")),
|
|
21
|
+
sel_registerName("initWithFrame:"),
|
|
22
|
+
((CGRect(*)(double, double, double, double))CGRectMake)(0, 0, 200, 24));
|
|
23
|
+
((void(*)(id, SEL, long))objc_msgSend)(
|
|
24
|
+
seg, sel_registerName("setSegmentCount:"), (long)count);
|
|
25
|
+
((void(*)(id, SEL, long))objc_msgSend)(
|
|
26
|
+
seg, sel_registerName("setSelectedSegment:"), 0);
|
|
27
|
+
id contentView = ((id(*)(id, SEL))objc_msgSend)(
|
|
28
|
+
(id)window->handle, sel_registerName("contentView"));
|
|
29
|
+
((void(*)(id, SEL, id))objc_msgSend)(
|
|
30
|
+
contentView, sel_registerName("addSubview:"), seg);
|
|
31
|
+
// NSSegmentedControl sends its action on USER segment clicks — arm
|
|
32
|
+
// it so on_select drains fire (programmatic setSelectedSegment
|
|
33
|
+
// stays silent).
|
|
34
|
+
extern void nomen_control_arm_selects(unsigned long long);
|
|
35
|
+
nomen_control_arm_selects((unsigned long long)seg);
|
|
36
|
+
self.handle = (uint64_t)seg;
|
|
37
|
+
```
|
|
38
|
+
```
|
|
39
|
+
#arch: aarch64_use_c
|
|
40
|
+
#platform: macos
|
|
41
|
+
id seg = ((id(*)(id, SEL, CGRect))objc_msgSend)(
|
|
42
|
+
((id(*)(id, SEL))objc_msgSend)((id)objc_getClass("NSSegmentedControl"), sel_registerName("alloc")),
|
|
43
|
+
sel_registerName("initWithFrame:"),
|
|
44
|
+
((CGRect(*)(double, double, double, double))CGRectMake)(0, 0, 200, 24));
|
|
45
|
+
((void(*)(id, SEL, long))objc_msgSend)(
|
|
46
|
+
seg, sel_registerName("setSegmentCount:"), (long)count);
|
|
47
|
+
((void(*)(id, SEL, long))objc_msgSend)(
|
|
48
|
+
seg, sel_registerName("setSelectedSegment:"), 0);
|
|
49
|
+
id contentView = ((id(*)(id, SEL))objc_msgSend)(
|
|
50
|
+
(id)window->handle, sel_registerName("contentView"));
|
|
51
|
+
((void(*)(id, SEL, id))objc_msgSend)(
|
|
52
|
+
contentView, sel_registerName("addSubview:"), seg);
|
|
53
|
+
extern void nomen_control_arm_selects(unsigned long long) __asm__("nomen_control_arm_selects");
|
|
54
|
+
nomen_control_arm_selects((unsigned long long)seg);
|
|
55
|
+
self->handle = (uint64_t)seg;
|
|
56
|
+
```
|
|
57
|
+
```
|
|
58
|
+
#arch: c
|
|
59
|
+
#platform: ios
|
|
60
|
+
id seg = ((id(*)(id, SEL, CGRect))objc_msgSend)(
|
|
61
|
+
((id(*)(id, SEL))objc_msgSend)((id)objc_getClass("UISegmentedControl"), sel_registerName("alloc")),
|
|
62
|
+
sel_registerName("initWithFrame:"),
|
|
63
|
+
((CGRect(*)(double, double, double, double))CGRectMake)(0, 0, 200, 32));
|
|
64
|
+
// UISegmentedControl grows by insertion (no setSegmentCount:); fill it
|
|
65
|
+
// with empty titled segments so indices line up with the macOS API.
|
|
66
|
+
for (long i = 0; i < (long)count; i++) {
|
|
67
|
+
((void(*)(id, SEL, id, long, BOOL))objc_msgSend)(
|
|
68
|
+
seg, sel_registerName("insertSegmentWithTitle:atIndex:animated:"),
|
|
69
|
+
((id(*)(id, SEL, const char*))objc_msgSend)(
|
|
70
|
+
(id)objc_getClass("NSString"), sel_registerName("stringWithUTF8String:"), ""),
|
|
71
|
+
i, 0);
|
|
72
|
+
}
|
|
73
|
+
id parentView = ((id(*)(id, SEL))objc_msgSend)(
|
|
74
|
+
((id(*)(id, SEL))objc_msgSend)(
|
|
75
|
+
(id)window->handle, sel_registerName("rootViewController")),
|
|
76
|
+
sel_registerName("view"));
|
|
77
|
+
((void(*)(id, SEL, id))objc_msgSend)(
|
|
78
|
+
parentView, sel_registerName("addSubview:"), seg);
|
|
79
|
+
self.handle = (uint64_t)seg;
|
|
80
|
+
```
|
|
81
|
+
```
|
|
82
|
+
#arch: aarch64_use_c
|
|
83
|
+
#platform: ios
|
|
84
|
+
id seg = ((id(*)(id, SEL, CGRect))objc_msgSend)(
|
|
85
|
+
((id(*)(id, SEL))objc_msgSend)((id)objc_getClass("UISegmentedControl"), sel_registerName("alloc")),
|
|
86
|
+
sel_registerName("initWithFrame:"),
|
|
87
|
+
((CGRect(*)(double, double, double, double))CGRectMake)(0, 0, 200, 32));
|
|
88
|
+
// UISegmentedControl grows by insertion (no setSegmentCount:); fill it
|
|
89
|
+
// with empty titled segments so indices line up with the macOS API.
|
|
90
|
+
for (long i = 0; i < (long)count; i++) {
|
|
91
|
+
((void(*)(id, SEL, id, long, BOOL))objc_msgSend)(
|
|
92
|
+
seg, sel_registerName("insertSegmentWithTitle:atIndex:animated:"),
|
|
93
|
+
((id(*)(id, SEL, const char*))objc_msgSend)(
|
|
94
|
+
(id)objc_getClass("NSString"), sel_registerName("stringWithUTF8String:"), ""),
|
|
95
|
+
i, 0);
|
|
96
|
+
}
|
|
97
|
+
id parentView = ((id(*)(id, SEL))objc_msgSend)(
|
|
98
|
+
((id(*)(id, SEL))objc_msgSend)(
|
|
99
|
+
(id)window->handle, sel_registerName("rootViewController")),
|
|
100
|
+
sel_registerName("view"));
|
|
101
|
+
((void(*)(id, SEL, id))objc_msgSend)(
|
|
102
|
+
parentView, sel_registerName("addSubview:"), seg);
|
|
103
|
+
self->handle = (uint64_t)seg;
|
|
104
|
+
```
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
pub func set_frame = (ref self, int x, int y, int width, int height) {
|
|
108
|
+
```
|
|
109
|
+
#arch: c
|
|
110
|
+
#platform: macos
|
|
111
|
+
((void(*)(id, SEL, CGRect))objc_msgSend)(
|
|
112
|
+
(id)self->handle, sel_registerName("setFrame:"),
|
|
113
|
+
((CGRect(*)(double, double, double, double))CGRectMake)((double)x, (double)y, (double)width, (double)height));
|
|
114
|
+
```
|
|
115
|
+
```
|
|
116
|
+
#arch: aarch64_use_c
|
|
117
|
+
#platform: macos
|
|
118
|
+
((void(*)(id, SEL, CGRect))objc_msgSend)(
|
|
119
|
+
(id)self->handle, sel_registerName("setFrame:"),
|
|
120
|
+
((CGRect(*)(double, double, double, double))CGRectMake)((double)x, (double)y, (double)width, (double)height));
|
|
121
|
+
```
|
|
122
|
+
```
|
|
123
|
+
#arch: c
|
|
124
|
+
#platform: ios
|
|
125
|
+
((void(*)(id, SEL, CGRect))objc_msgSend)(
|
|
126
|
+
(id)self->handle, sel_registerName("setFrame:"),
|
|
127
|
+
((CGRect(*)(double, double, double, double))CGRectMake)((double)x, (double)y, (double)width, (double)height));
|
|
128
|
+
```
|
|
129
|
+
```
|
|
130
|
+
#arch: aarch64_use_c
|
|
131
|
+
#platform: ios
|
|
132
|
+
((void(*)(id, SEL, CGRect))objc_msgSend)(
|
|
133
|
+
(id)self->handle, sel_registerName("setFrame:"),
|
|
134
|
+
((CGRect(*)(double, double, double, double))CGRectMake)((double)x, (double)y, (double)width, (double)height));
|
|
135
|
+
```
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
pub func set_label = (self, int index, string title) {
|
|
139
|
+
```
|
|
140
|
+
#arch: c
|
|
141
|
+
#platform: macos
|
|
142
|
+
((void(*)(id, SEL, id, long))objc_msgSend)(
|
|
143
|
+
(id)self->handle, sel_registerName("setLabel:forSegment:"),
|
|
144
|
+
((id(*)(id, SEL, const char*))objc_msgSend)(
|
|
145
|
+
(id)objc_getClass("NSString"), sel_registerName("stringWithUTF8String:"), title.ptr),
|
|
146
|
+
(long)index);
|
|
147
|
+
```
|
|
148
|
+
```
|
|
149
|
+
#arch: aarch64_use_c
|
|
150
|
+
#platform: macos
|
|
151
|
+
((void(*)(id, SEL, id, long))objc_msgSend)(
|
|
152
|
+
(id)self->handle, sel_registerName("setLabel:forSegment:"),
|
|
153
|
+
((id(*)(id, SEL, const char*))objc_msgSend)(
|
|
154
|
+
(id)objc_getClass("NSString"), sel_registerName("stringWithUTF8String:"), title.ptr),
|
|
155
|
+
(long)index);
|
|
156
|
+
```
|
|
157
|
+
```
|
|
158
|
+
#arch: c
|
|
159
|
+
#platform: ios
|
|
160
|
+
((void(*)(id, SEL, id, unsigned long))objc_msgSend)(
|
|
161
|
+
(id)self->handle, sel_registerName("setTitle:forSegmentAtIndex:"),
|
|
162
|
+
((id(*)(id, SEL, const char*))objc_msgSend)(
|
|
163
|
+
(id)objc_getClass("NSString"), sel_registerName("stringWithUTF8String:"), title.ptr),
|
|
164
|
+
(unsigned long)index);
|
|
165
|
+
```
|
|
166
|
+
```
|
|
167
|
+
#arch: aarch64_use_c
|
|
168
|
+
#platform: ios
|
|
169
|
+
((void(*)(id, SEL, id, unsigned long))objc_msgSend)(
|
|
170
|
+
(id)self->handle, sel_registerName("setTitle:forSegmentAtIndex:"),
|
|
171
|
+
((id(*)(id, SEL, const char*))objc_msgSend)(
|
|
172
|
+
(id)objc_getClass("NSString"), sel_registerName("stringWithUTF8String:"), title.ptr),
|
|
173
|
+
(unsigned long)index);
|
|
174
|
+
```
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
pub func set_selected = (self, int index) {
|
|
178
|
+
```
|
|
179
|
+
#arch: c
|
|
180
|
+
#platform: macos
|
|
181
|
+
((void(*)(id, SEL, long))objc_msgSend)(
|
|
182
|
+
(id)self->handle, sel_registerName("setSelectedSegment:"), (long)index);
|
|
183
|
+
```
|
|
184
|
+
```
|
|
185
|
+
#arch: aarch64_use_c
|
|
186
|
+
#platform: macos
|
|
187
|
+
((void(*)(id, SEL, long))objc_msgSend)(
|
|
188
|
+
(id)self->handle, sel_registerName("setSelectedSegment:"), (long)index);
|
|
189
|
+
```
|
|
190
|
+
```
|
|
191
|
+
#arch: c
|
|
192
|
+
#platform: ios
|
|
193
|
+
((void(*)(id, SEL, long))objc_msgSend)(
|
|
194
|
+
(id)self->handle, sel_registerName("setSelectedSegmentIndex:"), (long)index);
|
|
195
|
+
```
|
|
196
|
+
```
|
|
197
|
+
#arch: aarch64_use_c
|
|
198
|
+
#platform: ios
|
|
199
|
+
((void(*)(id, SEL, long))objc_msgSend)(
|
|
200
|
+
(id)self->handle, sel_registerName("setSelectedSegmentIndex:"), (long)index);
|
|
201
|
+
```
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// The selected segment's index, or -1 when nothing is selected.
|
|
205
|
+
pub func selected_index = (self, out int) {
|
|
206
|
+
```
|
|
207
|
+
#arch: c
|
|
208
|
+
#platform: macos
|
|
209
|
+
return (int)((long(*)(id, SEL))objc_msgSend)(
|
|
210
|
+
(id)self->handle, sel_registerName("selectedSegment"));
|
|
211
|
+
```
|
|
212
|
+
```
|
|
213
|
+
#arch: aarch64_use_c
|
|
214
|
+
#platform: macos
|
|
215
|
+
return (int)((long(*)(id, SEL))objc_msgSend)(
|
|
216
|
+
(id)self->handle, sel_registerName("selectedSegment"));
|
|
217
|
+
```
|
|
218
|
+
```
|
|
219
|
+
#arch: c
|
|
220
|
+
#platform: ios
|
|
221
|
+
return (int)((long(*)(id, SEL))objc_msgSend)(
|
|
222
|
+
(id)self->handle, sel_registerName("selectedSegmentIndex"));
|
|
223
|
+
```
|
|
224
|
+
```
|
|
225
|
+
#arch: aarch64_use_c
|
|
226
|
+
#platform: ios
|
|
227
|
+
return (int)((long(*)(id, SEL))objc_msgSend)(
|
|
228
|
+
(id)self->handle, sel_registerName("selectedSegmentIndex"));
|
|
229
|
+
```
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// The on_select desugar's drain (docs/HANDLERS.md): true when the user
|
|
233
|
+
// clicked a segment since the last drain (the record is consumed).
|
|
234
|
+
// User-driven only — AppKit sends the control's action for user clicks,
|
|
235
|
+
// not for programmatic setSelectedSegment. The handler body reads the
|
|
236
|
+
// segment through selected_index().
|
|
237
|
+
pub func take_select = (self, out bool) {
|
|
238
|
+
```
|
|
239
|
+
#arch: c
|
|
240
|
+
#platform: macos
|
|
241
|
+
extern long nomen_select_take(unsigned long long);
|
|
242
|
+
return (long)nomen_select_take((unsigned long long)self->handle);
|
|
243
|
+
```
|
|
244
|
+
```
|
|
245
|
+
#arch: aarch64_use_c
|
|
246
|
+
#platform: macos
|
|
247
|
+
extern long nomen_select_take(unsigned long long);
|
|
248
|
+
return (long)nomen_select_take((unsigned long long)self->handle);
|
|
249
|
+
```
|
|
250
|
+
```
|
|
251
|
+
#arch: c
|
|
252
|
+
#platform: ios
|
|
253
|
+
return 0;
|
|
254
|
+
```
|
|
255
|
+
```
|
|
256
|
+
#arch: aarch64_use_c
|
|
257
|
+
#platform: ios
|
|
258
|
+
return 0;
|
|
259
|
+
```
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
pub func count = (self, out int) {
|
|
263
|
+
```
|
|
264
|
+
#arch: c
|
|
265
|
+
#platform: macos
|
|
266
|
+
return (int)((long(*)(id, SEL))objc_msgSend)(
|
|
267
|
+
(id)self->handle, sel_registerName("segmentCount"));
|
|
268
|
+
```
|
|
269
|
+
```
|
|
270
|
+
#arch: aarch64_use_c
|
|
271
|
+
#platform: macos
|
|
272
|
+
return (int)((long(*)(id, SEL))objc_msgSend)(
|
|
273
|
+
(id)self->handle, sel_registerName("segmentCount"));
|
|
274
|
+
```
|
|
275
|
+
```
|
|
276
|
+
#arch: c
|
|
277
|
+
#platform: ios
|
|
278
|
+
return (int)((long(*)(id, SEL))objc_msgSend)(
|
|
279
|
+
(id)self->handle, sel_registerName("numberOfSegments"));
|
|
280
|
+
```
|
|
281
|
+
```
|
|
282
|
+
#arch: aarch64_use_c
|
|
283
|
+
#platform: ios
|
|
284
|
+
return (int)((long(*)(id, SEL))objc_msgSend)(
|
|
285
|
+
(id)self->handle, sel_registerName("numberOfSegments"));
|
|
286
|
+
```
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
pub func set_hidden = (self, bool hidden) {
|
|
290
|
+
```
|
|
291
|
+
#arch: c
|
|
292
|
+
#platform: macos
|
|
293
|
+
((void(*)(id, SEL, BOOL))objc_msgSend)(
|
|
294
|
+
(id)self->handle, sel_registerName("setHidden:"), hidden ? 1 : 0);
|
|
295
|
+
```
|
|
296
|
+
```
|
|
297
|
+
#arch: aarch64_use_c
|
|
298
|
+
#platform: macos
|
|
299
|
+
((void(*)(id, SEL, BOOL))objc_msgSend)(
|
|
300
|
+
(id)self->handle, sel_registerName("setHidden:"), hidden ? 1 : 0);
|
|
301
|
+
```
|
|
302
|
+
```
|
|
303
|
+
#arch: c
|
|
304
|
+
#platform: ios
|
|
305
|
+
((void(*)(id, SEL, BOOL))objc_msgSend)(
|
|
306
|
+
(id)self->handle, sel_registerName("setHidden:"), hidden ? 1 : 0);
|
|
307
|
+
```
|
|
308
|
+
```
|
|
309
|
+
#arch: aarch64_use_c
|
|
310
|
+
#platform: ios
|
|
311
|
+
((void(*)(id, SEL, BOOL))objc_msgSend)(
|
|
312
|
+
(id)self->handle, sel_registerName("setHidden:"), hidden ? 1 : 0);
|
|
313
|
+
```
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
// ── Control trait conformance ──
|
|
317
|
+
pub func intrinsic_size = (self, out Size) {
|
|
318
|
+
var [w, h] = native_intrinsic(self.handle)
|
|
319
|
+
var s = Size()
|
|
320
|
+
s.width = w
|
|
321
|
+
s.height = h
|
|
322
|
+
return s
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
pub func measure = (self, BoxConstraints constraints, out Size) {
|
|
326
|
+
var Size s = self.intrinsic_size()
|
|
327
|
+
if s.width > constraints.max_width {
|
|
328
|
+
s.width = constraints.max_width
|
|
329
|
+
}
|
|
330
|
+
if s.width < constraints.min_width {
|
|
331
|
+
s.width = constraints.min_width
|
|
332
|
+
}
|
|
333
|
+
if s.height > constraints.max_height {
|
|
334
|
+
s.height = constraints.max_height
|
|
335
|
+
}
|
|
336
|
+
if s.height < constraints.min_height {
|
|
337
|
+
s.height = constraints.min_height
|
|
338
|
+
}
|
|
339
|
+
return s
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
func #destroy = () {
|
|
343
|
+
```
|
|
344
|
+
#arch: c
|
|
345
|
+
#platform: macos
|
|
346
|
+
if (self->handle) {
|
|
347
|
+
((void(*)(id, SEL))objc_msgSend)((id)self->handle, sel_registerName("removeFromSuperview"));
|
|
348
|
+
((void(*)(id, SEL))objc_msgSend)((id)self->handle, sel_registerName("release"));
|
|
349
|
+
self->handle = 0;
|
|
350
|
+
}
|
|
351
|
+
```
|
|
352
|
+
```
|
|
353
|
+
#arch: aarch64_use_c
|
|
354
|
+
#platform: macos
|
|
355
|
+
if (self->handle) {
|
|
356
|
+
((void(*)(id, SEL))objc_msgSend)((id)self->handle, sel_registerName("removeFromSuperview"));
|
|
357
|
+
((void(*)(id, SEL))objc_msgSend)((id)self->handle, sel_registerName("release"));
|
|
358
|
+
self->handle = 0;
|
|
359
|
+
}
|
|
360
|
+
```
|
|
361
|
+
```
|
|
362
|
+
#arch: c
|
|
363
|
+
#platform: ios
|
|
364
|
+
if (self->handle) {
|
|
365
|
+
((void(*)(id, SEL))objc_msgSend)((id)self->handle, sel_registerName("removeFromSuperview"));
|
|
366
|
+
((void(*)(id, SEL))objc_msgSend)((id)self->handle, sel_registerName("release"));
|
|
367
|
+
self->handle = 0;
|
|
368
|
+
}
|
|
369
|
+
```
|
|
370
|
+
```
|
|
371
|
+
#arch: aarch64_use_c
|
|
372
|
+
#platform: ios
|
|
373
|
+
if (self->handle) {
|
|
374
|
+
((void(*)(id, SEL))objc_msgSend)((id)self->handle, sel_registerName("removeFromSuperview"));
|
|
375
|
+
((void(*)(id, SEL))objc_msgSend)((id)self->handle, sel_registerName("release"));
|
|
376
|
+
self->handle = 0;
|
|
377
|
+
}
|
|
378
|
+
```
|
|
379
|
+
}
|
|
380
|
+
}
|
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A dropdown choice control (NSPopUpButton)
|
|
3
|
+
*
|
|
4
|
+
* An OWNING STRUCT (STRUCT_PLAN_3 Phase R, tranche 4 — the shape menu): the
|
|
5
|
+
* single field is a platform handle, so the value is movable and its
|
|
6
|
+
* `#destroy` releases what the handle names. The constructor's `self` is
|
|
7
|
+
* the inline instance (the `.` accessor); methods keep the pointer form.
|
|
8
|
+
*
|
|
9
|
+
* macOS-first: the items live in the native menu, so `selected_index` is
|
|
10
|
+
* polled after each event batch. iOS needs a picker or action sheet and
|
|
11
|
+
* defers (TODO stubs below; see GUI_PLAN Tier 1 #9).
|
|
12
|
+
**/
|
|
13
|
+
pub mv struct Select: Control {
|
|
14
|
+
var uint64 handle = 0
|
|
15
|
+
|
|
16
|
+
pub func #init = (self, Window window) {
|
|
17
|
+
```
|
|
18
|
+
#arch: c
|
|
19
|
+
#platform: macos
|
|
20
|
+
id pop = ((id(*)(id, SEL, CGRect, BOOL))objc_msgSend)(
|
|
21
|
+
((id(*)(id, SEL))objc_msgSend)((id)objc_getClass("NSPopUpButton"), sel_registerName("alloc")),
|
|
22
|
+
sel_registerName("initWithFrame:pullsDown:"),
|
|
23
|
+
((CGRect(*)(double, double, double, double))CGRectMake)(0, 0, 140, 26),
|
|
24
|
+
0);
|
|
25
|
+
id contentView = ((id(*)(id, SEL))objc_msgSend)(
|
|
26
|
+
(id)window->handle, sel_registerName("contentView"));
|
|
27
|
+
((void(*)(id, SEL, id))objc_msgSend)(
|
|
28
|
+
contentView, sel_registerName("addSubview:"), pop);
|
|
29
|
+
// NSPopUpButton sends its action on USER selection only — arm it so
|
|
30
|
+
// on_select drains fire (programmatic selection stays silent).
|
|
31
|
+
extern void nomen_control_arm_selects(unsigned long long);
|
|
32
|
+
nomen_control_arm_selects((unsigned long long)pop);
|
|
33
|
+
self.handle = (uint64_t)pop;
|
|
34
|
+
```
|
|
35
|
+
```
|
|
36
|
+
#arch: aarch64_use_c
|
|
37
|
+
#platform: macos
|
|
38
|
+
id pop = ((id(*)(id, SEL, CGRect, BOOL))objc_msgSend)(
|
|
39
|
+
((id(*)(id, SEL))objc_msgSend)((id)objc_getClass("NSPopUpButton"), sel_registerName("alloc")),
|
|
40
|
+
sel_registerName("initWithFrame:pullsDown:"),
|
|
41
|
+
((CGRect(*)(double, double, double, double))CGRectMake)(0, 0, 140, 26),
|
|
42
|
+
0);
|
|
43
|
+
id contentView = ((id(*)(id, SEL))objc_msgSend)(
|
|
44
|
+
(id)window->handle, sel_registerName("contentView"));
|
|
45
|
+
((void(*)(id, SEL, id))objc_msgSend)(
|
|
46
|
+
contentView, sel_registerName("addSubview:"), pop);
|
|
47
|
+
extern void nomen_control_arm_selects(unsigned long long) __asm__("nomen_control_arm_selects");
|
|
48
|
+
nomen_control_arm_selects((unsigned long long)pop);
|
|
49
|
+
self->handle = (uint64_t)pop;
|
|
50
|
+
```
|
|
51
|
+
```
|
|
52
|
+
#arch: c
|
|
53
|
+
#platform: ios
|
|
54
|
+
/* TODO: iOS — needs a picker or action sheet presentation (see
|
|
55
|
+
* GUI_PLAN Tier 1 #9; defer the iOS block). */
|
|
56
|
+
```
|
|
57
|
+
```
|
|
58
|
+
#arch: aarch64_use_c
|
|
59
|
+
#platform: ios
|
|
60
|
+
/* TODO: iOS — needs a picker or action sheet presentation (see
|
|
61
|
+
* GUI_PLAN Tier 1 #9; defer the iOS block). */
|
|
62
|
+
```
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
pub func set_frame = (ref self, int x, int y, int width, int height) {
|
|
66
|
+
```
|
|
67
|
+
#arch: c
|
|
68
|
+
#platform: macos
|
|
69
|
+
((void(*)(id, SEL, CGRect))objc_msgSend)(
|
|
70
|
+
(id)self->handle, sel_registerName("setFrame:"),
|
|
71
|
+
((CGRect(*)(double, double, double, double))CGRectMake)((double)x, (double)y, (double)width, (double)height));
|
|
72
|
+
```
|
|
73
|
+
```
|
|
74
|
+
#arch: aarch64_use_c
|
|
75
|
+
#platform: macos
|
|
76
|
+
((void(*)(id, SEL, CGRect))objc_msgSend)(
|
|
77
|
+
(id)self->handle, sel_registerName("setFrame:"),
|
|
78
|
+
((CGRect(*)(double, double, double, double))CGRectMake)((double)x, (double)y, (double)width, (double)height));
|
|
79
|
+
```
|
|
80
|
+
```
|
|
81
|
+
#arch: c
|
|
82
|
+
#platform: ios
|
|
83
|
+
/* TODO: iOS (see #init) */
|
|
84
|
+
```
|
|
85
|
+
```
|
|
86
|
+
#arch: aarch64_use_c
|
|
87
|
+
#platform: ios
|
|
88
|
+
/* TODO: iOS (see #init) */
|
|
89
|
+
```
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Append a choice to the menu. The first item added becomes selected.
|
|
93
|
+
pub func add_item = (self, string title) {
|
|
94
|
+
```
|
|
95
|
+
#arch: c
|
|
96
|
+
#platform: macos
|
|
97
|
+
((void(*)(id, SEL, id))objc_msgSend)(
|
|
98
|
+
(id)self->handle, sel_registerName("addItemWithTitle:"),
|
|
99
|
+
((id(*)(id, SEL, const char*))objc_msgSend)(
|
|
100
|
+
(id)objc_getClass("NSString"), sel_registerName("stringWithUTF8String:"), title.ptr));
|
|
101
|
+
```
|
|
102
|
+
```
|
|
103
|
+
#arch: aarch64_use_c
|
|
104
|
+
#platform: macos
|
|
105
|
+
((void(*)(id, SEL, id))objc_msgSend)(
|
|
106
|
+
(id)self->handle, sel_registerName("addItemWithTitle:"),
|
|
107
|
+
((id(*)(id, SEL, const char*))objc_msgSend)(
|
|
108
|
+
(id)objc_getClass("NSString"), sel_registerName("stringWithUTF8String:"), title.ptr));
|
|
109
|
+
```
|
|
110
|
+
```
|
|
111
|
+
#arch: c
|
|
112
|
+
#platform: ios
|
|
113
|
+
/* TODO: iOS (see #init) */
|
|
114
|
+
```
|
|
115
|
+
```
|
|
116
|
+
#arch: aarch64_use_c
|
|
117
|
+
#platform: ios
|
|
118
|
+
/* TODO: iOS (see #init) */
|
|
119
|
+
```
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
pub func clear_items = (self) {
|
|
123
|
+
```
|
|
124
|
+
#arch: c
|
|
125
|
+
#platform: macos
|
|
126
|
+
((void(*)(id, SEL))objc_msgSend)(
|
|
127
|
+
(id)self->handle, sel_registerName("removeAllItems"));
|
|
128
|
+
```
|
|
129
|
+
```
|
|
130
|
+
#arch: aarch64_use_c
|
|
131
|
+
#platform: macos
|
|
132
|
+
((void(*)(id, SEL))objc_msgSend)(
|
|
133
|
+
(id)self->handle, sel_registerName("removeAllItems"));
|
|
134
|
+
```
|
|
135
|
+
```
|
|
136
|
+
#arch: c
|
|
137
|
+
#platform: ios
|
|
138
|
+
/* TODO: iOS (see #init) */
|
|
139
|
+
```
|
|
140
|
+
```
|
|
141
|
+
#arch: aarch64_use_c
|
|
142
|
+
#platform: ios
|
|
143
|
+
/* TODO: iOS (see #init) */
|
|
144
|
+
```
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
pub func select_index = (self, int index) {
|
|
148
|
+
```
|
|
149
|
+
#arch: c
|
|
150
|
+
#platform: macos
|
|
151
|
+
((void(*)(id, SEL, long))objc_msgSend)(
|
|
152
|
+
(id)self->handle, sel_registerName("selectItemAtIndex:"), (long)index);
|
|
153
|
+
```
|
|
154
|
+
```
|
|
155
|
+
#arch: aarch64_use_c
|
|
156
|
+
#platform: macos
|
|
157
|
+
((void(*)(id, SEL, long))objc_msgSend)(
|
|
158
|
+
(id)self->handle, sel_registerName("selectItemAtIndex:"), (long)index);
|
|
159
|
+
```
|
|
160
|
+
```
|
|
161
|
+
#arch: c
|
|
162
|
+
#platform: ios
|
|
163
|
+
/* TODO: iOS (see #init) */
|
|
164
|
+
```
|
|
165
|
+
```
|
|
166
|
+
#arch: aarch64_use_c
|
|
167
|
+
#platform: ios
|
|
168
|
+
/* TODO: iOS (see #init) */
|
|
169
|
+
```
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// The selected item's position, or -1 when nothing is selected.
|
|
173
|
+
pub func selected_index = (self, out int) {
|
|
174
|
+
```
|
|
175
|
+
#arch: c
|
|
176
|
+
#platform: macos
|
|
177
|
+
return (int)((long(*)(id, SEL))objc_msgSend)(
|
|
178
|
+
(id)self->handle, sel_registerName("indexOfSelectedItem"));
|
|
179
|
+
```
|
|
180
|
+
```
|
|
181
|
+
#arch: aarch64_use_c
|
|
182
|
+
#platform: macos
|
|
183
|
+
return (int)((long(*)(id, SEL))objc_msgSend)(
|
|
184
|
+
(id)self->handle, sel_registerName("indexOfSelectedItem"));
|
|
185
|
+
```
|
|
186
|
+
```
|
|
187
|
+
#arch: c
|
|
188
|
+
#platform: ios
|
|
189
|
+
/* TODO: iOS (see #init) */
|
|
190
|
+
return -1;
|
|
191
|
+
```
|
|
192
|
+
```
|
|
193
|
+
#arch: aarch64_use_c
|
|
194
|
+
#platform: ios
|
|
195
|
+
/* TODO: iOS (see #init) */
|
|
196
|
+
return -1;
|
|
197
|
+
```
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// The on_select desugar's drain (docs/HANDLERS.md): true when the user
|
|
201
|
+
// selected an item since the last drain (the record is consumed).
|
|
202
|
+
// User-driven only — AppKit sends the popup's action for user picks,
|
|
203
|
+
// not for programmatic ones. The handler body reads the item through
|
|
204
|
+
// selected_index().
|
|
205
|
+
pub func take_select = (self, out bool) {
|
|
206
|
+
```
|
|
207
|
+
#arch: c
|
|
208
|
+
#platform: macos
|
|
209
|
+
extern long nomen_select_take(unsigned long long);
|
|
210
|
+
return (long)nomen_select_take((unsigned long long)self->handle);
|
|
211
|
+
```
|
|
212
|
+
```
|
|
213
|
+
#arch: aarch64_use_c
|
|
214
|
+
#platform: macos
|
|
215
|
+
extern long nomen_select_take(unsigned long long);
|
|
216
|
+
return (long)nomen_select_take((unsigned long long)self->handle);
|
|
217
|
+
```
|
|
218
|
+
```
|
|
219
|
+
#arch: c
|
|
220
|
+
#platform: ios
|
|
221
|
+
/* TODO: iOS (see #init) */
|
|
222
|
+
return false;
|
|
223
|
+
```
|
|
224
|
+
```
|
|
225
|
+
#arch: aarch64_use_c
|
|
226
|
+
#platform: ios
|
|
227
|
+
/* TODO: iOS (see #init) */
|
|
228
|
+
return false;
|
|
229
|
+
```
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
pub func count = (self, out int) {
|
|
233
|
+
```
|
|
234
|
+
#arch: c
|
|
235
|
+
#platform: macos
|
|
236
|
+
return (int)((long(*)(id, SEL))objc_msgSend)(
|
|
237
|
+
(id)self->handle, sel_registerName("numberOfItems"));
|
|
238
|
+
```
|
|
239
|
+
```
|
|
240
|
+
#arch: aarch64_use_c
|
|
241
|
+
#platform: macos
|
|
242
|
+
return (int)((long(*)(id, SEL))objc_msgSend)(
|
|
243
|
+
(id)self->handle, sel_registerName("numberOfItems"));
|
|
244
|
+
```
|
|
245
|
+
```
|
|
246
|
+
#arch: c
|
|
247
|
+
#platform: ios
|
|
248
|
+
/* TODO: iOS (see #init) */
|
|
249
|
+
return 0;
|
|
250
|
+
```
|
|
251
|
+
```
|
|
252
|
+
#arch: aarch64_use_c
|
|
253
|
+
#platform: ios
|
|
254
|
+
/* TODO: iOS (see #init) */
|
|
255
|
+
return 0;
|
|
256
|
+
```
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
pub func set_hidden = (self, bool hidden) {
|
|
260
|
+
```
|
|
261
|
+
#arch: c
|
|
262
|
+
#platform: macos
|
|
263
|
+
((void(*)(id, SEL, BOOL))objc_msgSend)(
|
|
264
|
+
(id)self->handle, sel_registerName("setHidden:"), hidden ? 1 : 0);
|
|
265
|
+
```
|
|
266
|
+
```
|
|
267
|
+
#arch: aarch64_use_c
|
|
268
|
+
#platform: macos
|
|
269
|
+
((void(*)(id, SEL, BOOL))objc_msgSend)(
|
|
270
|
+
(id)self->handle, sel_registerName("setHidden:"), hidden ? 1 : 0);
|
|
271
|
+
```
|
|
272
|
+
```
|
|
273
|
+
#arch: c
|
|
274
|
+
#platform: ios
|
|
275
|
+
/* TODO: iOS (see #init) */
|
|
276
|
+
```
|
|
277
|
+
```
|
|
278
|
+
#arch: aarch64_use_c
|
|
279
|
+
#platform: ios
|
|
280
|
+
/* TODO: iOS (see #init) */
|
|
281
|
+
```
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// ── Control trait conformance ──
|
|
285
|
+
pub func intrinsic_size = (self, out Size) {
|
|
286
|
+
var [w, h] = native_intrinsic(self.handle)
|
|
287
|
+
var s = Size()
|
|
288
|
+
s.width = w
|
|
289
|
+
s.height = h
|
|
290
|
+
return s
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
pub func measure = (self, BoxConstraints constraints, out Size) {
|
|
294
|
+
var Size s = self.intrinsic_size()
|
|
295
|
+
if s.width > constraints.max_width {
|
|
296
|
+
s.width = constraints.max_width
|
|
297
|
+
}
|
|
298
|
+
if s.width < constraints.min_width {
|
|
299
|
+
s.width = constraints.min_width
|
|
300
|
+
}
|
|
301
|
+
if s.height > constraints.max_height {
|
|
302
|
+
s.height = constraints.max_height
|
|
303
|
+
}
|
|
304
|
+
if s.height < constraints.min_height {
|
|
305
|
+
s.height = constraints.min_height
|
|
306
|
+
}
|
|
307
|
+
return s
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
func #destroy = () {
|
|
311
|
+
```
|
|
312
|
+
#arch: c
|
|
313
|
+
#platform: macos
|
|
314
|
+
if (self->handle) {
|
|
315
|
+
((void(*)(id, SEL))objc_msgSend)((id)self->handle, sel_registerName("removeFromSuperview"));
|
|
316
|
+
((void(*)(id, SEL))objc_msgSend)((id)self->handle, sel_registerName("release"));
|
|
317
|
+
self->handle = 0;
|
|
318
|
+
}
|
|
319
|
+
```
|
|
320
|
+
```
|
|
321
|
+
#arch: aarch64_use_c
|
|
322
|
+
#platform: macos
|
|
323
|
+
if (self->handle) {
|
|
324
|
+
((void(*)(id, SEL))objc_msgSend)((id)self->handle, sel_registerName("removeFromSuperview"));
|
|
325
|
+
((void(*)(id, SEL))objc_msgSend)((id)self->handle, sel_registerName("release"));
|
|
326
|
+
self->handle = 0;
|
|
327
|
+
}
|
|
328
|
+
```
|
|
329
|
+
```
|
|
330
|
+
#arch: c
|
|
331
|
+
#platform: ios
|
|
332
|
+
/* TODO: iOS (see #init) */
|
|
333
|
+
```
|
|
334
|
+
```
|
|
335
|
+
#arch: aarch64_use_c
|
|
336
|
+
#platform: ios
|
|
337
|
+
/* TODO: iOS (see #init) */
|
|
338
|
+
```
|
|
339
|
+
}
|
|
340
|
+
}
|