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.
Files changed (80) hide show
  1. package/audit_runtime.c +12 -2
  2. package/core/System/Arena.nm +8 -1
  3. package/core/System/Buffer.nm +397 -8
  4. package/core/System/ClassBuffer.nm +156 -0
  5. package/core/System/Controls/Alert.nm +326 -0
  6. package/core/System/Controls/App.nm +147 -0
  7. package/core/System/Controls/Button.nm +119 -1
  8. package/core/System/Controls/CheckBox.nm +25 -1
  9. package/core/System/Controls/ColorPicker.nm +307 -0
  10. package/core/System/Controls/ComboBox.nm +430 -0
  11. package/core/System/Controls/Container.nm +843 -9
  12. package/core/System/Controls/Control.nm +443 -0
  13. package/core/System/Controls/DatePicker.nm +288 -0
  14. package/core/System/Controls/Form.nm +70 -0
  15. package/core/System/Controls/GroupBox.nm +267 -0
  16. package/core/System/Controls/ImageView.nm +311 -0
  17. package/core/System/Controls/LevelIndicator.nm +305 -0
  18. package/core/System/Controls/ListView.nm +633 -0
  19. package/core/System/Controls/Menu.nm +428 -0
  20. package/core/System/Controls/NumberInput.nm +56 -0
  21. package/core/System/Controls/OtpInput.nm +50 -0
  22. package/core/System/Controls/OutlineView.nm +598 -0
  23. package/core/System/Controls/Pagination.nm +142 -0
  24. package/core/System/Controls/Popover.nm +296 -0
  25. package/core/System/Controls/Progress.nm +348 -0
  26. package/core/System/Controls/Radio.nm +292 -0
  27. package/core/System/Controls/Scrollable.nm +584 -0
  28. package/core/System/Controls/SearchField.nm +326 -0
  29. package/core/System/Controls/SecureField.nm +344 -0
  30. package/core/System/Controls/Segmented.nm +380 -0
  31. package/core/System/Controls/Select.nm +340 -0
  32. package/core/System/Controls/Separator.nm +198 -0
  33. package/core/System/Controls/Sheet.nm +329 -0
  34. package/core/System/Controls/Slider.nm +315 -0
  35. package/core/System/Controls/Spinner.nm +287 -0
  36. package/core/System/Controls/SplitView.nm +509 -0
  37. package/core/System/Controls/Stepper.nm +349 -0
  38. package/core/System/Controls/Switch.nm +259 -0
  39. package/core/System/Controls/Table.nm +833 -0
  40. package/core/System/Controls/Tabs.nm +500 -0
  41. package/core/System/Controls/Text.nm +108 -11
  42. package/core/System/Controls/TextBox.nm +113 -2
  43. package/core/System/Controls/TextView.nm +329 -0
  44. package/core/System/Controls/Toggle.nm +346 -0
  45. package/core/System/Controls/Toolbar.nm +501 -0
  46. package/core/System/Controls/Tooltip.nm +76 -0
  47. package/core/System/Controls/Window.nm +1548 -91
  48. package/core/System/LinkedList.nm +8 -1
  49. package/core/System/List.nm +97 -7
  50. package/core/System/Map.nm +191 -18
  51. package/core/System/Mutex.nm +4 -4
  52. package/core/System/Random.nm +3 -4
  53. package/core/System/Set.nm +101 -13
  54. package/core/System/StableList.nm +371 -0
  55. package/core/System/Stream/Directory.nm +2 -2
  56. package/core/System/Stream/File.nm +2 -2
  57. package/core/System/Stream/Http.nm +2 -2
  58. package/core/System/String.nm +10 -5
  59. package/core/System/StringBuilder.nm +213 -2
  60. package/core/System/Text/CharIndex.nm +9 -9
  61. package/core/System/Text/Json.nm +60 -46
  62. package/core/System/Text/JsonTree.nm +120 -92
  63. package/core/System/Text/Regex.nm +23 -18
  64. package/core/System/Text/Utf8.nm +5 -5
  65. package/core/System/float.nm +36 -22
  66. package/core/System/int.nm +80 -28
  67. package/core/System/int16.nm +11 -0
  68. package/core/System/int32.nm +11 -0
  69. package/core/System/int64.nm +11 -0
  70. package/core/System/int8.nm +11 -0
  71. package/core/System/uint.nm +11 -0
  72. package/core/System/uint16.nm +11 -0
  73. package/core/System/uint32.nm +11 -0
  74. package/core/System/uint64.nm +11 -0
  75. package/core/System/uint8.nm +11 -0
  76. package/core/docs/System/StringBuilder.md +6 -0
  77. package/core/docs/System/Text/JsonTree.md +3 -2
  78. package/dist/index.mjs +38332 -30604
  79. package/package.json +1 -1
  80. package/src/bench_loop.nm +9 -9
@@ -0,0 +1,349 @@
1
+ /**
2
+ * A pair of up/down arrows that walk a numeric range
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
+ * Pair with a TextBox for the "number input" composition (gpui-kit's
10
+ * number-input is exactly that pairing).
11
+ **/
12
+ pub mv struct Stepper: Control {
13
+ var uint64 handle = 0
14
+
15
+ pub func #init = (self, Window window) {
16
+ ```
17
+ #arch: c
18
+ #platform: macos
19
+ id step = ((id(*)(id, SEL, CGRect))objc_msgSend)(
20
+ ((id(*)(id, SEL))objc_msgSend)((id)objc_getClass("NSStepper"), sel_registerName("alloc")),
21
+ sel_registerName("initWithFrame:"),
22
+ ((CGRect(*)(double, double, double, double))CGRectMake)(0, 0, 20, 24));
23
+ ((void(*)(id, SEL, double))objc_msgSend)(step, sel_registerName("setMinValue:"), 0.0);
24
+ ((void(*)(id, SEL, double))objc_msgSend)(step, sel_registerName("setMaxValue:"), 100.0);
25
+ ((void(*)(id, SEL, double))objc_msgSend)(step, sel_registerName("setIncrement:"), 1.0);
26
+ ((void(*)(id, SEL, double))objc_msgSend)(step, sel_registerName("setDoubleValue:"), 0.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:"), step);
31
+ self.handle = (uint64_t)step;
32
+ ```
33
+ ```
34
+ #arch: aarch64_use_c
35
+ #platform: macos
36
+ id step = ((id(*)(id, SEL, CGRect))objc_msgSend)(
37
+ ((id(*)(id, SEL))objc_msgSend)((id)objc_getClass("NSStepper"), sel_registerName("alloc")),
38
+ sel_registerName("initWithFrame:"),
39
+ ((CGRect(*)(double, double, double, double))CGRectMake)(0, 0, 20, 24));
40
+ ((void(*)(id, SEL, double))objc_msgSend)(step, sel_registerName("setMinValue:"), 0.0);
41
+ ((void(*)(id, SEL, double))objc_msgSend)(step, sel_registerName("setMaxValue:"), 100.0);
42
+ ((void(*)(id, SEL, double))objc_msgSend)(step, sel_registerName("setIncrement:"), 1.0);
43
+ ((void(*)(id, SEL, double))objc_msgSend)(step, sel_registerName("setDoubleValue:"), 0.0);
44
+ id contentView = ((id(*)(id, SEL))objc_msgSend)(
45
+ (id)window->handle, sel_registerName("contentView"));
46
+ ((void(*)(id, SEL, id))objc_msgSend)(
47
+ contentView, sel_registerName("addSubview:"), step);
48
+ self->handle = (uint64_t)step;
49
+ ```
50
+ ```
51
+ #arch: c
52
+ #platform: ios
53
+ id step = ((id(*)(id, SEL, CGRect))objc_msgSend)(
54
+ ((id(*)(id, SEL))objc_msgSend)((id)objc_getClass("UIStepper"), sel_registerName("alloc")),
55
+ sel_registerName("initWithFrame:"),
56
+ ((CGRect(*)(double, double, double, double))CGRectMake)(0, 0, 94, 29));
57
+ ((void(*)(id, SEL, double))objc_msgSend)(step, sel_registerName("setMinimumValue:"), 0.0);
58
+ ((void(*)(id, SEL, double))objc_msgSend)(step, sel_registerName("setMaximumValue:"), 100.0);
59
+ ((void(*)(id, SEL, double))objc_msgSend)(step, sel_registerName("setStepValue:"), 1.0);
60
+ ((void(*)(id, SEL, double))objc_msgSend)(step, sel_registerName("setValue:"), 0.0);
61
+ id parentView = ((id(*)(id, SEL))objc_msgSend)(
62
+ ((id(*)(id, SEL))objc_msgSend)(
63
+ (id)window->handle, sel_registerName("rootViewController")),
64
+ sel_registerName("view"));
65
+ ((void(*)(id, SEL, id))objc_msgSend)(
66
+ parentView, sel_registerName("addSubview:"), step);
67
+ self.handle = (uint64_t)step;
68
+ ```
69
+ ```
70
+ #arch: aarch64_use_c
71
+ #platform: ios
72
+ id step = ((id(*)(id, SEL, CGRect))objc_msgSend)(
73
+ ((id(*)(id, SEL))objc_msgSend)((id)objc_getClass("UIStepper"), sel_registerName("alloc")),
74
+ sel_registerName("initWithFrame:"),
75
+ ((CGRect(*)(double, double, double, double))CGRectMake)(0, 0, 94, 29));
76
+ ((void(*)(id, SEL, double))objc_msgSend)(step, sel_registerName("setMinimumValue:"), 0.0);
77
+ ((void(*)(id, SEL, double))objc_msgSend)(step, sel_registerName("setMaximumValue:"), 100.0);
78
+ ((void(*)(id, SEL, double))objc_msgSend)(step, sel_registerName("setStepValue:"), 1.0);
79
+ ((void(*)(id, SEL, double))objc_msgSend)(step, sel_registerName("setValue:"), 0.0);
80
+ id parentView = ((id(*)(id, SEL))objc_msgSend)(
81
+ ((id(*)(id, SEL))objc_msgSend)(
82
+ (id)window->handle, sel_registerName("rootViewController")),
83
+ sel_registerName("view"));
84
+ ((void(*)(id, SEL, id))objc_msgSend)(
85
+ parentView, sel_registerName("addSubview:"), step);
86
+ self->handle = (uint64_t)step;
87
+ ```
88
+ }
89
+
90
+ pub func set_frame = (ref self, int x, int y, int width, int height) {
91
+ ```
92
+ #arch: c
93
+ #platform: macos
94
+ ((void(*)(id, SEL, CGRect))objc_msgSend)(
95
+ (id)self->handle, sel_registerName("setFrame:"),
96
+ ((CGRect(*)(double, double, double, double))CGRectMake)((double)x, (double)y, (double)width, (double)height));
97
+ ```
98
+ ```
99
+ #arch: aarch64_use_c
100
+ #platform: macos
101
+ ((void(*)(id, SEL, CGRect))objc_msgSend)(
102
+ (id)self->handle, sel_registerName("setFrame:"),
103
+ ((CGRect(*)(double, double, double, double))CGRectMake)((double)x, (double)y, (double)width, (double)height));
104
+ ```
105
+ ```
106
+ #arch: c
107
+ #platform: ios
108
+ ((void(*)(id, SEL, CGRect))objc_msgSend)(
109
+ (id)self->handle, sel_registerName("setFrame:"),
110
+ ((CGRect(*)(double, double, double, double))CGRectMake)((double)x, (double)y, (double)width, (double)height));
111
+ ```
112
+ ```
113
+ #arch: aarch64_use_c
114
+ #platform: ios
115
+ ((void(*)(id, SEL, CGRect))objc_msgSend)(
116
+ (id)self->handle, sel_registerName("setFrame:"),
117
+ ((CGRect(*)(double, double, double, double))CGRectMake)((double)x, (double)y, (double)width, (double)height));
118
+ ```
119
+ }
120
+
121
+ pub func set_min = (self, float min) {
122
+ ```
123
+ #arch: c
124
+ #platform: macos
125
+ ((void(*)(id, SEL, double))objc_msgSend)(
126
+ (id)self->handle, sel_registerName("setMinValue:"), min);
127
+ ```
128
+ ```
129
+ #arch: aarch64_use_c
130
+ #platform: macos
131
+ ((void(*)(id, SEL, double))objc_msgSend)(
132
+ (id)self->handle, sel_registerName("setMinValue:"), min);
133
+ ```
134
+ ```
135
+ #arch: c
136
+ #platform: ios
137
+ ((void(*)(id, SEL, double))objc_msgSend)(
138
+ (id)self->handle, sel_registerName("setMinimumValue:"), min);
139
+ ```
140
+ ```
141
+ #arch: aarch64_use_c
142
+ #platform: ios
143
+ ((void(*)(id, SEL, double))objc_msgSend)(
144
+ (id)self->handle, sel_registerName("setMinimumValue:"), min);
145
+ ```
146
+ }
147
+
148
+ pub func set_max = (self, float max) {
149
+ ```
150
+ #arch: c
151
+ #platform: macos
152
+ ((void(*)(id, SEL, double))objc_msgSend)(
153
+ (id)self->handle, sel_registerName("setMaxValue:"), max);
154
+ ```
155
+ ```
156
+ #arch: aarch64_use_c
157
+ #platform: macos
158
+ ((void(*)(id, SEL, double))objc_msgSend)(
159
+ (id)self->handle, sel_registerName("setMaxValue:"), max);
160
+ ```
161
+ ```
162
+ #arch: c
163
+ #platform: ios
164
+ ((void(*)(id, SEL, double))objc_msgSend)(
165
+ (id)self->handle, sel_registerName("setMaximumValue:"), max);
166
+ ```
167
+ ```
168
+ #arch: aarch64_use_c
169
+ #platform: ios
170
+ ((void(*)(id, SEL, double))objc_msgSend)(
171
+ (id)self->handle, sel_registerName("setMaximumValue:"), max);
172
+ ```
173
+ }
174
+
175
+ // The per-click step size.
176
+ pub func set_increment = (self, float increment) {
177
+ ```
178
+ #arch: c
179
+ #platform: macos
180
+ ((void(*)(id, SEL, double))objc_msgSend)(
181
+ (id)self->handle, sel_registerName("setIncrement:"), increment);
182
+ ```
183
+ ```
184
+ #arch: aarch64_use_c
185
+ #platform: macos
186
+ ((void(*)(id, SEL, double))objc_msgSend)(
187
+ (id)self->handle, sel_registerName("setIncrement:"), increment);
188
+ ```
189
+ ```
190
+ #arch: c
191
+ #platform: ios
192
+ ((void(*)(id, SEL, double))objc_msgSend)(
193
+ (id)self->handle, sel_registerName("setStepValue:"), increment);
194
+ ```
195
+ ```
196
+ #arch: aarch64_use_c
197
+ #platform: ios
198
+ ((void(*)(id, SEL, double))objc_msgSend)(
199
+ (id)self->handle, sel_registerName("setStepValue:"), increment);
200
+ ```
201
+ }
202
+
203
+ pub func set_value = (self, float value) {
204
+ ```
205
+ #arch: c
206
+ #platform: macos
207
+ ((void(*)(id, SEL, double))objc_msgSend)(
208
+ (id)self->handle, sel_registerName("setDoubleValue:"), value);
209
+ ```
210
+ ```
211
+ #arch: aarch64_use_c
212
+ #platform: macos
213
+ ((void(*)(id, SEL, double))objc_msgSend)(
214
+ (id)self->handle, sel_registerName("setDoubleValue:"), value);
215
+ ```
216
+ ```
217
+ #arch: c
218
+ #platform: ios
219
+ ((void(*)(id, SEL, double))objc_msgSend)(
220
+ (id)self->handle, sel_registerName("setValue:"), value);
221
+ ```
222
+ ```
223
+ #arch: aarch64_use_c
224
+ #platform: ios
225
+ ((void(*)(id, SEL, double))objc_msgSend)(
226
+ (id)self->handle, sel_registerName("setValue:"), value);
227
+ ```
228
+ }
229
+
230
+ // The current value — polled per frame (each click lands between frames).
231
+ pub func value = (self, out float) {
232
+ ```
233
+ #arch: c
234
+ #platform: macos
235
+ return ((double(*)(id, SEL))objc_msgSend)(
236
+ (id)self->handle, sel_registerName("doubleValue"));
237
+ ```
238
+ ```
239
+ #arch: aarch64_use_c
240
+ #platform: macos
241
+ return ((double(*)(id, SEL))objc_msgSend)(
242
+ (id)self->handle, sel_registerName("doubleValue"));
243
+ ```
244
+ ```
245
+ #arch: c
246
+ #platform: ios
247
+ return ((double(*)(id, SEL))objc_msgSend)(
248
+ (id)self->handle, sel_registerName("value"));
249
+ ```
250
+ ```
251
+ #arch: aarch64_use_c
252
+ #platform: ios
253
+ return ((double(*)(id, SEL))objc_msgSend)(
254
+ (id)self->handle, sel_registerName("value"));
255
+ ```
256
+ }
257
+
258
+ pub func set_hidden = (self, bool hidden) {
259
+ ```
260
+ #arch: c
261
+ #platform: macos
262
+ ((void(*)(id, SEL, BOOL))objc_msgSend)(
263
+ (id)self->handle, sel_registerName("setHidden:"), hidden ? 1 : 0);
264
+ ```
265
+ ```
266
+ #arch: aarch64_use_c
267
+ #platform: macos
268
+ ((void(*)(id, SEL, BOOL))objc_msgSend)(
269
+ (id)self->handle, sel_registerName("setHidden:"), hidden ? 1 : 0);
270
+ ```
271
+ ```
272
+ #arch: c
273
+ #platform: ios
274
+ ((void(*)(id, SEL, BOOL))objc_msgSend)(
275
+ (id)self->handle, sel_registerName("setHidden:"), hidden ? 1 : 0);
276
+ ```
277
+ ```
278
+ #arch: aarch64_use_c
279
+ #platform: ios
280
+ ((void(*)(id, SEL, BOOL))objc_msgSend)(
281
+ (id)self->handle, sel_registerName("setHidden:"), hidden ? 1 : 0);
282
+ ```
283
+ }
284
+
285
+ // ── Control trait conformance ──
286
+ pub func intrinsic_size = (self, out Size) {
287
+ var [w, h] = native_intrinsic(self.handle)
288
+ var s = Size()
289
+ s.width = w
290
+ s.height = h
291
+ return s
292
+ }
293
+
294
+ pub func measure = (self, BoxConstraints constraints, out Size) {
295
+ var Size s = self.intrinsic_size()
296
+ if s.width > constraints.max_width {
297
+ s.width = constraints.max_width
298
+ }
299
+ if s.width < constraints.min_width {
300
+ s.width = constraints.min_width
301
+ }
302
+ if s.height > constraints.max_height {
303
+ s.height = constraints.max_height
304
+ }
305
+ if s.height < constraints.min_height {
306
+ s.height = constraints.min_height
307
+ }
308
+ return s
309
+ }
310
+
311
+ func #destroy = () {
312
+ ```
313
+ #arch: c
314
+ #platform: macos
315
+ if (self->handle) {
316
+ ((void(*)(id, SEL))objc_msgSend)((id)self->handle, sel_registerName("removeFromSuperview"));
317
+ ((void(*)(id, SEL))objc_msgSend)((id)self->handle, sel_registerName("release"));
318
+ self->handle = 0;
319
+ }
320
+ ```
321
+ ```
322
+ #arch: aarch64_use_c
323
+ #platform: macos
324
+ if (self->handle) {
325
+ ((void(*)(id, SEL))objc_msgSend)((id)self->handle, sel_registerName("removeFromSuperview"));
326
+ ((void(*)(id, SEL))objc_msgSend)((id)self->handle, sel_registerName("release"));
327
+ self->handle = 0;
328
+ }
329
+ ```
330
+ ```
331
+ #arch: c
332
+ #platform: ios
333
+ if (self->handle) {
334
+ ((void(*)(id, SEL))objc_msgSend)((id)self->handle, sel_registerName("removeFromSuperview"));
335
+ ((void(*)(id, SEL))objc_msgSend)((id)self->handle, sel_registerName("release"));
336
+ self->handle = 0;
337
+ }
338
+ ```
339
+ ```
340
+ #arch: aarch64_use_c
341
+ #platform: ios
342
+ if (self->handle) {
343
+ ((void(*)(id, SEL))objc_msgSend)((id)self->handle, sel_registerName("removeFromSuperview"));
344
+ ((void(*)(id, SEL))objc_msgSend)((id)self->handle, sel_registerName("release"));
345
+ self->handle = 0;
346
+ }
347
+ ```
348
+ }
349
+ }
@@ -0,0 +1,259 @@
1
+ /**
2
+ * A settings-style on/off toggle (the "missing switch")
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
+ * Pairs with CheckBox: check = task state, switch = preference.
10
+ **/
11
+ pub mv struct Switch: Control {
12
+ var uint64 handle = 0
13
+
14
+ pub func #init = (self, Window window) {
15
+ ```
16
+ #arch: c
17
+ #platform: macos
18
+ id sw = ((id(*)(id, SEL, CGRect))objc_msgSend)(
19
+ ((id(*)(id, SEL))objc_msgSend)((id)objc_getClass("NSSwitch"), sel_registerName("alloc")),
20
+ sel_registerName("initWithFrame:"),
21
+ ((CGRect(*)(double, double, double, double))CGRectMake)(0, 0, 40, 22));
22
+ ((void(*)(id, SEL, long))objc_msgSend)(
23
+ sw, sel_registerName("setState:"), 0); // NSControlStateValueOff = 0
24
+ id contentView = ((id(*)(id, SEL))objc_msgSend)(
25
+ (id)window->handle, sel_registerName("contentView"));
26
+ ((void(*)(id, SEL, id))objc_msgSend)(
27
+ contentView, sel_registerName("addSubview:"), sw);
28
+ self.handle = (uint64_t)sw;
29
+ ```
30
+ ```
31
+ #arch: aarch64_use_c
32
+ #platform: macos
33
+ id sw = ((id(*)(id, SEL, CGRect))objc_msgSend)(
34
+ ((id(*)(id, SEL))objc_msgSend)((id)objc_getClass("NSSwitch"), sel_registerName("alloc")),
35
+ sel_registerName("initWithFrame:"),
36
+ ((CGRect(*)(double, double, double, double))CGRectMake)(0, 0, 40, 22));
37
+ ((void(*)(id, SEL, long))objc_msgSend)(
38
+ sw, sel_registerName("setState:"), 0); // NSControlStateValueOff = 0
39
+ id contentView = ((id(*)(id, SEL))objc_msgSend)(
40
+ (id)window->handle, sel_registerName("contentView"));
41
+ ((void(*)(id, SEL, id))objc_msgSend)(
42
+ contentView, sel_registerName("addSubview:"), sw);
43
+ self->handle = (uint64_t)sw;
44
+ ```
45
+ ```
46
+ #arch: c
47
+ #platform: ios
48
+ id sw = ((id(*)(id, SEL, CGRect))objc_msgSend)(
49
+ ((id(*)(id, SEL))objc_msgSend)((id)objc_getClass("UISwitch"), sel_registerName("alloc")),
50
+ sel_registerName("initWithFrame:"),
51
+ ((CGRect(*)(double, double, double, double))CGRectMake)(0, 0, 51, 31));
52
+ id parentView = ((id(*)(id, SEL))objc_msgSend)(
53
+ ((id(*)(id, SEL))objc_msgSend)(
54
+ (id)window->handle, sel_registerName("rootViewController")),
55
+ sel_registerName("view"));
56
+ ((void(*)(id, SEL, id))objc_msgSend)(
57
+ parentView, sel_registerName("addSubview:"), sw);
58
+ self.handle = (uint64_t)sw;
59
+ ```
60
+ ```
61
+ #arch: aarch64_use_c
62
+ #platform: ios
63
+ id sw = ((id(*)(id, SEL, CGRect))objc_msgSend)(
64
+ ((id(*)(id, SEL))objc_msgSend)((id)objc_getClass("UISwitch"), sel_registerName("alloc")),
65
+ sel_registerName("initWithFrame:"),
66
+ ((CGRect(*)(double, double, double, double))CGRectMake)(0, 0, 51, 31));
67
+ id parentView = ((id(*)(id, SEL))objc_msgSend)(
68
+ ((id(*)(id, SEL))objc_msgSend)(
69
+ (id)window->handle, sel_registerName("rootViewController")),
70
+ sel_registerName("view"));
71
+ ((void(*)(id, SEL, id))objc_msgSend)(
72
+ parentView, sel_registerName("addSubview:"), sw);
73
+ self->handle = (uint64_t)sw;
74
+ ```
75
+ }
76
+
77
+ pub func set_frame = (ref self, int x, int y, int width, int height) {
78
+ ```
79
+ #arch: c
80
+ #platform: macos
81
+ ((void(*)(id, SEL, CGRect))objc_msgSend)(
82
+ (id)self->handle, sel_registerName("setFrame:"),
83
+ ((CGRect(*)(double, double, double, double))CGRectMake)((double)x, (double)y, (double)width, (double)height));
84
+ ```
85
+ ```
86
+ #arch: aarch64_use_c
87
+ #platform: macos
88
+ ((void(*)(id, SEL, CGRect))objc_msgSend)(
89
+ (id)self->handle, sel_registerName("setFrame:"),
90
+ ((CGRect(*)(double, double, double, double))CGRectMake)((double)x, (double)y, (double)width, (double)height));
91
+ ```
92
+ ```
93
+ #arch: c
94
+ #platform: ios
95
+ ((void(*)(id, SEL, CGRect))objc_msgSend)(
96
+ (id)self->handle, sel_registerName("setFrame:"),
97
+ ((CGRect(*)(double, double, double, double))CGRectMake)((double)x, (double)y, (double)width, (double)height));
98
+ ```
99
+ ```
100
+ #arch: aarch64_use_c
101
+ #platform: ios
102
+ ((void(*)(id, SEL, CGRect))objc_msgSend)(
103
+ (id)self->handle, sel_registerName("setFrame:"),
104
+ ((CGRect(*)(double, double, double, double))CGRectMake)((double)x, (double)y, (double)width, (double)height));
105
+ ```
106
+ }
107
+
108
+ pub func set_checked = (self, bool checked) {
109
+ ```
110
+ #arch: c
111
+ #platform: macos
112
+ ((void(*)(id, SEL, long))objc_msgSend)(
113
+ (id)self->handle, sel_registerName("setState:"),
114
+ checked ? 1 : 0); // NSControlStateValueOn = 1, Off = 0
115
+ ```
116
+ ```
117
+ #arch: aarch64_use_c
118
+ #platform: macos
119
+ ((void(*)(id, SEL, long))objc_msgSend)(
120
+ (id)self->handle, sel_registerName("setState:"),
121
+ checked ? 1 : 0); // NSControlStateValueOn = 1, Off = 0
122
+ ```
123
+ ```
124
+ #arch: c
125
+ #platform: ios
126
+ ((void(*)(id, SEL, BOOL))objc_msgSend)(
127
+ (id)self->handle, sel_registerName("setOn:"), checked ? 1 : 0);
128
+ ```
129
+ ```
130
+ #arch: aarch64_use_c
131
+ #platform: ios
132
+ ((void(*)(id, SEL, BOOL))objc_msgSend)(
133
+ (id)self->handle, sel_registerName("setOn:"), checked ? 1 : 0);
134
+ ```
135
+ }
136
+
137
+ pub func is_checked = (self, out bool) {
138
+ ```
139
+ #arch: c
140
+ #platform: macos
141
+ long state = ((long(*)(id, SEL))objc_msgSend)(
142
+ (id)self->handle, sel_registerName("state"));
143
+ return state == 1; // NSControlStateValueOn = 1
144
+ ```
145
+ ```
146
+ #arch: aarch64_use_c
147
+ #platform: macos
148
+ long state = ((long(*)(id, SEL))objc_msgSend)(
149
+ (id)self->handle, sel_registerName("state"));
150
+ return state == 1; // NSControlStateValueOn = 1
151
+ ```
152
+ ```
153
+ #arch: c
154
+ #platform: ios
155
+ BOOL on = ((BOOL(*)(id, SEL))objc_msgSend)(
156
+ (id)self->handle, sel_registerName("isOn"));
157
+ return on ? 1 : 0;
158
+ ```
159
+ ```
160
+ #arch: aarch64_use_c
161
+ #platform: ios
162
+ BOOL on = ((BOOL(*)(id, SEL))objc_msgSend)(
163
+ (id)self->handle, sel_registerName("isOn"));
164
+ return on ? 1 : 0;
165
+ ```
166
+ }
167
+
168
+ pub func set_hidden = (self, bool hidden) {
169
+ ```
170
+ #arch: c
171
+ #platform: macos
172
+ ((void(*)(id, SEL, BOOL))objc_msgSend)(
173
+ (id)self->handle, sel_registerName("setHidden:"), hidden ? 1 : 0);
174
+ ```
175
+ ```
176
+ #arch: aarch64_use_c
177
+ #platform: macos
178
+ ((void(*)(id, SEL, BOOL))objc_msgSend)(
179
+ (id)self->handle, sel_registerName("setHidden:"), hidden ? 1 : 0);
180
+ ```
181
+ ```
182
+ #arch: c
183
+ #platform: ios
184
+ ((void(*)(id, SEL, BOOL))objc_msgSend)(
185
+ (id)self->handle, sel_registerName("setHidden:"), hidden ? 1 : 0);
186
+ ```
187
+ ```
188
+ #arch: aarch64_use_c
189
+ #platform: ios
190
+ ((void(*)(id, SEL, BOOL))objc_msgSend)(
191
+ (id)self->handle, sel_registerName("setHidden:"), hidden ? 1 : 0);
192
+ ```
193
+ }
194
+
195
+ // ── Control trait conformance ──
196
+ pub func intrinsic_size = (self, out Size) {
197
+ var [w, h] = native_intrinsic(self.handle)
198
+ var s = Size()
199
+ s.width = w
200
+ s.height = h
201
+ return s
202
+ }
203
+
204
+ pub func measure = (self, BoxConstraints constraints, out Size) {
205
+ var Size s = self.intrinsic_size()
206
+ if s.width > constraints.max_width {
207
+ s.width = constraints.max_width
208
+ }
209
+ if s.width < constraints.min_width {
210
+ s.width = constraints.min_width
211
+ }
212
+ if s.height > constraints.max_height {
213
+ s.height = constraints.max_height
214
+ }
215
+ if s.height < constraints.min_height {
216
+ s.height = constraints.min_height
217
+ }
218
+ return s
219
+ }
220
+
221
+ func #destroy = () {
222
+ ```
223
+ #arch: c
224
+ #platform: macos
225
+ if (self->handle) {
226
+ ((void(*)(id, SEL))objc_msgSend)((id)self->handle, sel_registerName("removeFromSuperview"));
227
+ ((void(*)(id, SEL))objc_msgSend)((id)self->handle, sel_registerName("release"));
228
+ self->handle = 0;
229
+ }
230
+ ```
231
+ ```
232
+ #arch: aarch64_use_c
233
+ #platform: macos
234
+ if (self->handle) {
235
+ ((void(*)(id, SEL))objc_msgSend)((id)self->handle, sel_registerName("removeFromSuperview"));
236
+ ((void(*)(id, SEL))objc_msgSend)((id)self->handle, sel_registerName("release"));
237
+ self->handle = 0;
238
+ }
239
+ ```
240
+ ```
241
+ #arch: c
242
+ #platform: ios
243
+ if (self->handle) {
244
+ ((void(*)(id, SEL))objc_msgSend)((id)self->handle, sel_registerName("removeFromSuperview"));
245
+ ((void(*)(id, SEL))objc_msgSend)((id)self->handle, sel_registerName("release"));
246
+ self->handle = 0;
247
+ }
248
+ ```
249
+ ```
250
+ #arch: aarch64_use_c
251
+ #platform: ios
252
+ if (self->handle) {
253
+ ((void(*)(id, SEL))objc_msgSend)((id)self->handle, sel_registerName("removeFromSuperview"));
254
+ ((void(*)(id, SEL))objc_msgSend)((id)self->handle, sel_registerName("release"));
255
+ self->handle = 0;
256
+ }
257
+ ```
258
+ }
259
+ }