nomen-lang 0.7.1 → 0.8.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 (50) hide show
  1. package/core/System/Buffer.nm +32 -0
  2. package/core/System/ClassBuffer.nm +24 -0
  3. package/core/System/Controls/Alert.nm +326 -0
  4. package/core/System/Controls/App.nm +147 -0
  5. package/core/System/Controls/Button.nm +119 -1
  6. package/core/System/Controls/CheckBox.nm +24 -0
  7. package/core/System/Controls/ColorPicker.nm +307 -0
  8. package/core/System/Controls/ComboBox.nm +430 -0
  9. package/core/System/Controls/Container.nm +837 -9
  10. package/core/System/Controls/Control.nm +443 -0
  11. package/core/System/Controls/DatePicker.nm +288 -0
  12. package/core/System/Controls/Form.nm +70 -0
  13. package/core/System/Controls/GroupBox.nm +267 -0
  14. package/core/System/Controls/ImageView.nm +311 -0
  15. package/core/System/Controls/LevelIndicator.nm +305 -0
  16. package/core/System/Controls/ListView.nm +633 -0
  17. package/core/System/Controls/Menu.nm +428 -0
  18. package/core/System/Controls/NumberInput.nm +56 -0
  19. package/core/System/Controls/OtpInput.nm +50 -0
  20. package/core/System/Controls/OutlineView.nm +598 -0
  21. package/core/System/Controls/Pagination.nm +142 -0
  22. package/core/System/Controls/Popover.nm +296 -0
  23. package/core/System/Controls/Progress.nm +348 -0
  24. package/core/System/Controls/Radio.nm +292 -0
  25. package/core/System/Controls/Scrollable.nm +584 -0
  26. package/core/System/Controls/SearchField.nm +326 -0
  27. package/core/System/Controls/SecureField.nm +344 -0
  28. package/core/System/Controls/Segmented.nm +380 -0
  29. package/core/System/Controls/Select.nm +340 -0
  30. package/core/System/Controls/Separator.nm +198 -0
  31. package/core/System/Controls/Sheet.nm +329 -0
  32. package/core/System/Controls/Slider.nm +315 -0
  33. package/core/System/Controls/Spinner.nm +287 -0
  34. package/core/System/Controls/SplitView.nm +509 -0
  35. package/core/System/Controls/Stepper.nm +349 -0
  36. package/core/System/Controls/Switch.nm +259 -0
  37. package/core/System/Controls/Table.nm +833 -0
  38. package/core/System/Controls/Tabs.nm +500 -0
  39. package/core/System/Controls/Text.nm +108 -11
  40. package/core/System/Controls/TextBox.nm +112 -1
  41. package/core/System/Controls/TextView.nm +329 -0
  42. package/core/System/Controls/Toggle.nm +346 -0
  43. package/core/System/Controls/Toolbar.nm +501 -0
  44. package/core/System/Controls/Tooltip.nm +76 -0
  45. package/core/System/Controls/Window.nm +1549 -91
  46. package/core/System/List.nm +34 -0
  47. package/core/System/Map.nm +21 -4
  48. package/core/System/Set.nm +14 -0
  49. package/dist/index.mjs +2556 -656
  50. package/package.json +1 -1
@@ -0,0 +1,346 @@
1
+ /**
2
+ * A push-on/push-off button (a Button variant that holds its state)
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: NSButton with button type NSPushOnPushOffButton; iOS: a UIButton's
10
+ * selected state. Where `Button` is momentary, `Toggle` stays depressed
11
+ * until clicked again (toolbar-style).
12
+ **/
13
+ pub mv struct Toggle : Control {
14
+ var uint64 handle = 0
15
+
16
+ // The `#handle` hook synthesizes `NameHandle` — a copyable, non-owning
17
+ // twin (same public bare-self methods, no destroy) so closures can
18
+ // capture this control without moving it. See GUI.md, "Handles".
19
+ #handle = () {}
20
+
21
+ pub func #init = (self, Window window, string title) {
22
+ ```
23
+ #arch: c
24
+ #platform: macos
25
+ id btn = ((id(*)(id, SEL, CGRect))objc_msgSend)(
26
+ ((id(*)(id, SEL))objc_msgSend)((id)objc_getClass("NSButton"), sel_registerName("alloc")),
27
+ sel_registerName("initWithFrame:"),
28
+ ((CGRect(*)(double, double, double, double))CGRectMake)(0, 0, 100, 32));
29
+ ((void(*)(id, SEL, unsigned long))objc_msgSend)(
30
+ btn, sel_registerName("setButtonType:"), 1); // NSPushOnPushOffButton = 1
31
+ ((void(*)(id, SEL, long))objc_msgSend)(
32
+ btn, sel_registerName("setState:"), 0); // NSControlStateValueOff = 0
33
+ ((void(*)(id, SEL, id))objc_msgSend)(
34
+ btn, sel_registerName("setTitle:"),
35
+ ((id(*)(id, SEL, const char*))objc_msgSend)(
36
+ (id)objc_getClass("NSString"), sel_registerName("stringWithUTF8String:"), title.ptr));
37
+ id contentView = ((id(*)(id, SEL))objc_msgSend)(
38
+ (id)window->handle, sel_registerName("contentView"));
39
+ ((void(*)(id, SEL, id))objc_msgSend)(
40
+ contentView, sel_registerName("addSubview:"), btn);
41
+ self.handle = (uint64_t)btn;
42
+ extern void nomen_control_arm_clicks(unsigned long long);
43
+ nomen_control_arm_clicks((unsigned long long)btn);
44
+ ```
45
+ ```
46
+ #arch: aarch64_use_c
47
+ #platform: macos
48
+ id btn = ((id(*)(id, SEL, CGRect))objc_msgSend)(
49
+ ((id(*)(id, SEL))objc_msgSend)((id)objc_getClass("NSButton"), sel_registerName("alloc")),
50
+ sel_registerName("initWithFrame:"),
51
+ ((CGRect(*)(double, double, double, double))CGRectMake)(0, 0, 100, 32));
52
+ ((void(*)(id, SEL, unsigned long))objc_msgSend)(
53
+ btn, sel_registerName("setButtonType:"), 1); // NSPushOnPushOffButton = 1
54
+ ((void(*)(id, SEL, long))objc_msgSend)(
55
+ btn, sel_registerName("setState:"), 0); // NSControlStateValueOff = 0
56
+ ((void(*)(id, SEL, id))objc_msgSend)(
57
+ btn, sel_registerName("setTitle:"),
58
+ ((id(*)(id, SEL, const char*))objc_msgSend)(
59
+ (id)objc_getClass("NSString"), sel_registerName("stringWithUTF8String:"), title.ptr));
60
+ id contentView = ((id(*)(id, SEL))objc_msgSend)(
61
+ (id)window->handle, sel_registerName("contentView"));
62
+ ((void(*)(id, SEL, id))objc_msgSend)(
63
+ contentView, sel_registerName("addSubview:"), btn);
64
+ self->handle = (uint64_t)btn;
65
+ extern void nomen_control_arm_clicks(unsigned long long) __asm__("nomen_control_arm_clicks");
66
+ nomen_control_arm_clicks((unsigned long long)btn);
67
+ ```
68
+ ```
69
+ #arch: c
70
+ #platform: ios
71
+ id btn = ((id(*)(id, SEL, CGRect))objc_msgSend)(
72
+ ((id(*)(id, SEL))objc_msgSend)((id)objc_getClass("UIButton"), sel_registerName("alloc")),
73
+ sel_registerName("initWithFrame:"),
74
+ ((CGRect(*)(double, double, double, double))CGRectMake)(0, 0, 100, 32));
75
+ ((void(*)(id, SEL, unsigned long, id, id))objc_msgSend)(
76
+ btn, sel_registerName("setTitle:forState:"),
77
+ ((id(*)(id, SEL, const char*))objc_msgSend)(
78
+ (id)objc_getClass("NSString"), sel_registerName("stringWithUTF8String:"), title.ptr),
79
+ 0); // UIControlStateNormal = 0
80
+ ((void(*)(id, SEL, BOOL))objc_msgSend)(btn, sel_registerName("setSelected:"), 0);
81
+ id parentView = ((id(*)(id, SEL))objc_msgSend)(
82
+ ((id(*)(id, SEL))objc_msgSend)(
83
+ (id)window->handle, sel_registerName("rootViewController")),
84
+ sel_registerName("view"));
85
+ ((void(*)(id, SEL, id))objc_msgSend)(
86
+ parentView, sel_registerName("addSubview:"), btn);
87
+ self.handle = (uint64_t)btn;
88
+ ```
89
+ ```
90
+ #arch: aarch64_use_c
91
+ #platform: ios
92
+ id btn = ((id(*)(id, SEL, CGRect))objc_msgSend)(
93
+ ((id(*)(id, SEL))objc_msgSend)((id)objc_getClass("UIButton"), sel_registerName("alloc")),
94
+ sel_registerName("initWithFrame:"),
95
+ ((CGRect(*)(double, double, double, double))CGRectMake)(0, 0, 100, 32));
96
+ ((void(*)(id, SEL, unsigned long, id, id))objc_msgSend)(
97
+ btn, sel_registerName("setTitle:forState:"),
98
+ ((id(*)(id, SEL, const char*))objc_msgSend)(
99
+ (id)objc_getClass("NSString"), sel_registerName("stringWithUTF8String:"), title.ptr),
100
+ 0); // UIControlStateNormal = 0
101
+ ((void(*)(id, SEL, BOOL))objc_msgSend)(btn, sel_registerName("setSelected:"), 0);
102
+ id parentView = ((id(*)(id, SEL))objc_msgSend)(
103
+ ((id(*)(id, SEL))objc_msgSend)(
104
+ (id)window->handle, sel_registerName("rootViewController")),
105
+ sel_registerName("view"));
106
+ ((void(*)(id, SEL, id))objc_msgSend)(
107
+ parentView, sel_registerName("addSubview:"), btn);
108
+ self->handle = (uint64_t)btn;
109
+ ```
110
+ }
111
+
112
+ pub func set_frame = (ref self, int x, int y, int width, int height) {
113
+ ```
114
+ #arch: c
115
+ #platform: macos
116
+ ((void(*)(id, SEL, CGRect))objc_msgSend)(
117
+ (id)self->handle, sel_registerName("setFrame:"),
118
+ ((CGRect(*)(double, double, double, double))CGRectMake)((double)x, (double)y, (double)width, (double)height));
119
+ ```
120
+ ```
121
+ #arch: aarch64_use_c
122
+ #platform: macos
123
+ ((void(*)(id, SEL, CGRect))objc_msgSend)(
124
+ (id)self->handle, sel_registerName("setFrame:"),
125
+ ((CGRect(*)(double, double, double, double))CGRectMake)((double)x, (double)y, (double)width, (double)height));
126
+ ```
127
+ ```
128
+ #arch: c
129
+ #platform: ios
130
+ ((void(*)(id, SEL, CGRect))objc_msgSend)(
131
+ (id)self->handle, sel_registerName("setFrame:"),
132
+ ((CGRect(*)(double, double, double, double))CGRectMake)((double)x, (double)y, (double)width, (double)height));
133
+ ```
134
+ ```
135
+ #arch: aarch64_use_c
136
+ #platform: ios
137
+ ((void(*)(id, SEL, CGRect))objc_msgSend)(
138
+ (id)self->handle, sel_registerName("setFrame:"),
139
+ ((CGRect(*)(double, double, double, double))CGRectMake)((double)x, (double)y, (double)width, (double)height));
140
+ ```
141
+ }
142
+
143
+ pub func set_title = (self, string title) {
144
+ ```
145
+ #arch: c
146
+ #platform: macos
147
+ ((void(*)(id, SEL, id))objc_msgSend)(
148
+ (id)self->handle, sel_registerName("setTitle:"),
149
+ ((id(*)(id, SEL, const char*))objc_msgSend)(
150
+ (id)objc_getClass("NSString"), sel_registerName("stringWithUTF8String:"), title.ptr));
151
+ ```
152
+ ```
153
+ #arch: aarch64_use_c
154
+ #platform: macos
155
+ ((void(*)(id, SEL, id))objc_msgSend)(
156
+ (id)self->handle, sel_registerName("setTitle:"),
157
+ ((id(*)(id, SEL, const char*))objc_msgSend)(
158
+ (id)objc_getClass("NSString"), sel_registerName("stringWithUTF8String:"), title.ptr));
159
+ ```
160
+ ```
161
+ #arch: c
162
+ #platform: ios
163
+ ((void(*)(id, SEL, unsigned long, id, id))objc_msgSend)(
164
+ (id)self->handle, sel_registerName("setTitle:forState:"),
165
+ ((id(*)(id, SEL, const char*))objc_msgSend)(
166
+ (id)objc_getClass("NSString"), sel_registerName("stringWithUTF8String:"), title.ptr),
167
+ 0); // UIControlStateNormal = 0
168
+ ```
169
+ ```
170
+ #arch: aarch64_use_c
171
+ #platform: ios
172
+ ((void(*)(id, SEL, unsigned long, id, id))objc_msgSend)(
173
+ (id)self->handle, sel_registerName("setTitle:forState:"),
174
+ ((id(*)(id, SEL, const char*))objc_msgSend)(
175
+ (id)objc_getClass("NSString"), sel_registerName("stringWithUTF8String:"), title.ptr),
176
+ 0); // UIControlStateNormal = 0
177
+ ```
178
+ }
179
+
180
+ pub func set_checked = (self, bool checked) {
181
+ ```
182
+ #arch: c
183
+ #platform: macos
184
+ ((void(*)(id, SEL, long))objc_msgSend)(
185
+ (id)self->handle, sel_registerName("setState:"),
186
+ checked ? 1 : 0); // NSControlStateValueOn = 1, Off = 0
187
+ ```
188
+ ```
189
+ #arch: aarch64_use_c
190
+ #platform: macos
191
+ ((void(*)(id, SEL, long))objc_msgSend)(
192
+ (id)self->handle, sel_registerName("setState:"),
193
+ checked ? 1 : 0); // NSControlStateValueOn = 1, Off = 0
194
+ ```
195
+ ```
196
+ #arch: c
197
+ #platform: ios
198
+ ((void(*)(id, SEL, BOOL))objc_msgSend)(
199
+ (id)self->handle, sel_registerName("setSelected:"), checked ? 1 : 0);
200
+ ```
201
+ ```
202
+ #arch: aarch64_use_c
203
+ #platform: ios
204
+ ((void(*)(id, SEL, BOOL))objc_msgSend)(
205
+ (id)self->handle, sel_registerName("setSelected:"), checked ? 1 : 0);
206
+ ```
207
+ }
208
+
209
+ pub func is_checked = (self, out bool) {
210
+ ```
211
+ #arch: c
212
+ #platform: macos
213
+ long state = ((long(*)(id, SEL))objc_msgSend)(
214
+ (id)self->handle, sel_registerName("state"));
215
+ return state == 1; // NSControlStateValueOn = 1
216
+ ```
217
+ ```
218
+ #arch: aarch64_use_c
219
+ #platform: macos
220
+ long state = ((long(*)(id, SEL))objc_msgSend)(
221
+ (id)self->handle, sel_registerName("state"));
222
+ return state == 1; // NSControlStateValueOn = 1
223
+ ```
224
+ ```
225
+ #arch: c
226
+ #platform: ios
227
+ BOOL on = ((BOOL(*)(id, SEL))objc_msgSend)(
228
+ (id)self->handle, sel_registerName("isSelected"));
229
+ return on ? 1 : 0;
230
+ ```
231
+ ```
232
+ #arch: aarch64_use_c
233
+ #platform: ios
234
+ BOOL on = ((BOOL(*)(id, SEL))objc_msgSend)(
235
+ (id)self->handle, sel_registerName("isSelected"));
236
+ return on ? 1 : 0;
237
+ ```
238
+ }
239
+
240
+ pub func set_hidden = (self, bool hidden) {
241
+ ```
242
+ #arch: c
243
+ #platform: macos
244
+ ((void(*)(id, SEL, BOOL))objc_msgSend)(
245
+ (id)self->handle, sel_registerName("setHidden:"), hidden ? 1 : 0);
246
+ ```
247
+ ```
248
+ #arch: aarch64_use_c
249
+ #platform: macos
250
+ ((void(*)(id, SEL, BOOL))objc_msgSend)(
251
+ (id)self->handle, sel_registerName("setHidden:"), hidden ? 1 : 0);
252
+ ```
253
+ ```
254
+ #arch: c
255
+ #platform: ios
256
+ ((void(*)(id, SEL, BOOL))objc_msgSend)(
257
+ (id)self->handle, sel_registerName("setHidden:"), hidden ? 1 : 0);
258
+ ```
259
+ ```
260
+ #arch: aarch64_use_c
261
+ #platform: ios
262
+ ((void(*)(id, SEL, BOOL))objc_msgSend)(
263
+ (id)self->handle, sel_registerName("setHidden:"), hidden ? 1 : 0);
264
+ ```
265
+ }
266
+
267
+ // ── Control trait conformance ──
268
+ // Edge-triggered click poll: true exactly once per click (the record
269
+ // is consumed). Backed by the native target/action queue —
270
+ // nomen_control_arm_clicks arms this control in the constructor — so
271
+ // no coordinates and no hit-testing, and it works inside Scrollables.
272
+ pub func was_clicked = (self, out bool) {
273
+ return nomen_control_take_click(self.handle)
274
+ }
275
+
276
+ // The on_click desugar's drain (docs/HANDLERS.md): the synthesized pump
277
+ // arm polls this per frame. Same edge as was_clicked — register one way
278
+ // or the other, never both (first consumer wins).
279
+ pub func take_click = (self, out bool) {
280
+ return nomen_control_take_click(self.handle)
281
+ }
282
+
283
+ pub func intrinsic_size = (self, out Size) {
284
+ var [w, h] = native_intrinsic(self.handle)
285
+ var s = Size()
286
+ s.width = w
287
+ s.height = h
288
+ return s
289
+ }
290
+
291
+ pub func measure = (self, BoxConstraints constraints, out Size) {
292
+ var Size s = self.intrinsic_size()
293
+ if s.width > constraints.max_width {
294
+ s.width = constraints.max_width
295
+ }
296
+ if s.width < constraints.min_width {
297
+ s.width = constraints.min_width
298
+ }
299
+ if s.height > constraints.max_height {
300
+ s.height = constraints.max_height
301
+ }
302
+ if s.height < constraints.min_height {
303
+ s.height = constraints.min_height
304
+ }
305
+ return s
306
+ }
307
+
308
+ func #destroy = () {
309
+ ```
310
+ #arch: c
311
+ #platform: macos
312
+ if (self->handle) {
313
+ ((void(*)(id, SEL))objc_msgSend)((id)self->handle, sel_registerName("removeFromSuperview"));
314
+ ((void(*)(id, SEL))objc_msgSend)((id)self->handle, sel_registerName("release"));
315
+ self->handle = 0;
316
+ }
317
+ ```
318
+ ```
319
+ #arch: aarch64_use_c
320
+ #platform: macos
321
+ if (self->handle) {
322
+ ((void(*)(id, SEL))objc_msgSend)((id)self->handle, sel_registerName("removeFromSuperview"));
323
+ ((void(*)(id, SEL))objc_msgSend)((id)self->handle, sel_registerName("release"));
324
+ self->handle = 0;
325
+ }
326
+ ```
327
+ ```
328
+ #arch: c
329
+ #platform: ios
330
+ if (self->handle) {
331
+ ((void(*)(id, SEL))objc_msgSend)((id)self->handle, sel_registerName("removeFromSuperview"));
332
+ ((void(*)(id, SEL))objc_msgSend)((id)self->handle, sel_registerName("release"));
333
+ self->handle = 0;
334
+ }
335
+ ```
336
+ ```
337
+ #arch: aarch64_use_c
338
+ #platform: ios
339
+ if (self->handle) {
340
+ ((void(*)(id, SEL))objc_msgSend)((id)self->handle, sel_registerName("removeFromSuperview"));
341
+ ((void(*)(id, SEL))objc_msgSend)((id)self->handle, sel_registerName("release"));
342
+ self->handle = 0;
343
+ }
344
+ ```
345
+ }
346
+ }