1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
-- kui prelude: injected before every extension script.
-- Views are plain tables — the same IR the Rust builders lower into.
-- grid { row { text("name"), text("value") }, row { ... } }: a table
-- (docs/adr/0033) -- a column whose rows' children line up in columns,
-- each column as wide as its widest cell, so a label column sits at its
-- longest label with no width picked by hand. A cell's `width` sizes its
-- column (fit or a number is content, "grow" grows the column, a percent
-- takes its cut), a bare text is a cell held to its column, and the rows
-- are rows -- give them width = "grow" for the columns to grow into, and
-- their own gap, pad, bg, hover_bg, on_click. Every other key is the
-- column's. Named `grid` here because `table` is Lua's own.
-- text("plain", opts) or text({ "plain ", { "bold", bold = true, color = 0x.. } }, opts)
-- The options are copied, not written into: a style table a script hoists
-- (`local mono = { size = 14 }`) and hands to several texts is several
-- nodes, not one table that ends up holding the last string.
-- The stock toggles (docs/adr/0034): checkbox { label = "Mute", checked =
-- muted, on_click = "mute" }, radio { ... }, switch { ... }. The state is
-- the model's: a press posts on_click and the view flips it. A checkbox
-- also takes mixed = true, the select-all box over a partial selection.
-- `label` is the name and the text both unless `text` says otherwise.
-- radio_group { label = "Theme", radio { ... }, radio { ... } }: one Tab
-- stop whose arrows move the choice and press the radio they land on.
-- Takes every box row; a column by default.
-- slider { label = "Volume", value_now = v, value_min = 0, value_max = 100,
-- value_step = 5, on_change = "vol" }: the core turns the pointer and the
-- keys into {kind = "change", value, phase, tag} events; store `value` and
-- draw the slider at it.
-- Single-line input with chrome: input { label = "name", initial = "" }
-- The stock select: dropdown { label = "language", options = { "English",
-- "Deutsch", { label = "Latin", id = "la", enabled = false } }, current = 2 }.
-- A field showing the choice in force that, clicked, opens the core's own
-- menu of the options under it; the choice arrives as the {kind = "menu"}
-- event a menu row posts, on the field's key, its `item` the option's label
-- or id. `current` counts from 1, as a Lua list does; nil for none. Named
-- `dropdown` here because `select` is Lua's own.
-- Bare editor: edit { key = "note", initial = "", multiline = true,
-- autofocus = true, size = 14, ...spec props }. Read it back in view(env)
-- with env.edit_text(key) after a {kind = "changed"} event (ev.node_key).
-- image { id = handle, width = 16, sampling = "nearest", fit = "contain" }:
-- a registered image (the host registers it and passes the handle in as a
-- plain integer). `sampling` is "linear" (default) or "nearest"; `fit` is
-- "fill" (default), "contain" or "cover" -- how the pixels meet the box,
-- which is itself the same in every mode (docs/adr/0025).
-- fragment { id = handle, params = {0.1, 0.2, ...}, animate = true, ... }: a
-- box the registered WGSL `id` paints (the host registers it with
-- Core::add_fragment and passes the handle in as a plain integer). An
-- ordinary node otherwise -- it lays out, rounds, clips, fades, takes input
-- and may hold children, which paint over it -- but it has no intrinsic
-- size, so give it a width and height or `fill`. `params` is up to sixteen
-- numbers the shader reads as four vec4<f32>; `animate` asks for a frame
-- every frame, which a fragment reading `time` needs.
-- line { from = {x, y}, to = {x, y}, width = 2, color = 0x7f9cf5ff } or
-- line { points = {{x, y}, ...}, curve = true, ... }: a round-capped stroke
-- in the parent's box space, never in layout (it floats, sized to its own
-- bounding box). `width` is the stroke width, `color` the stroke colour;
-- `key`, `transition`, `opacity`, `on_layout` apply, and `on_click`,
-- `on_drag`, `on_hover`, `hoverable` hit by the stroke (docs/adr/0026).
-- `dash = {6, 4}` cuts it into 6 px marks with 4 px gaps, as seen (one
-- length is both, four are a dash-dot); a mark no longer than `width` is a
-- dot, and a gap the dots overlap closes; `dash_offset` starts that far
-- into the pattern.
-- polygon { points = {{x, y}, ...}, bg = 0xd8863bff }: a filled polygon
-- through up to eight points in the parent's box space, the fill in `bg`,
-- placed like a line (never in layout; floats, sized to its own bounding
-- box). The outline may be concave. `key`, `transition`, `opacity`,
-- `on_layout` apply, and `on_click`, `on_drag`, `on_hover`, `hoverable`
-- hit by the outline (docs/adr/0025 decision 6, docs/adr/0026).
-- path { d = "M60 60 L100 60 A40 40 0 0 1 60 100 Z", bg = 0xd8863bff,
-- fill_rule = "nonzero", width = 2, color = 0xffffffff }: any outline as SVG
-- path data (or `ops`, the flat op form), filled with `bg` by `fill_rule`
-- and stroked `width` wide in `color` when `width` is given, placed like a
-- line. Hit by its outline under the rule (docs/adr/0040). `rotate = 0.25`
-- turns it a quarter turn clockwise about `pivot = {x, y}` (the centre of
-- its box without one): the quad turns, the mask is drawn once (docs/adr/0041).
-- `dash` and `dash_offset` cut the stroke as a line's do.
-- cells { rows=, cols=, lines={"row text", ...}, runs={{row, col, len, fg,
-- bg, flags}, ...}, cursor_at={row, col}, cursor_shape="block", cursor_color=,
-- size=, family= }: a terminal's screen as one node (backlog C20). Rows and
-- columns are 0-based in runs and the cursor; a run's fg or bg of 0 keeps
-- the default.
-- audio { src = id, loop = true, volume = 0.5, paused = false, tag = {...},
-- key = "music" }: a playback retained by key while the view declares it
-- (present = playing, gone = stopped; volume/paused apply live). Draws
-- nothing. The host registers the sound and hands the id to the script.
-- titlebar { title = "app" } draws the standard title; with children it
-- hosts custom content between the drag inset and the window buttons.
-- menu_bar { menu = { { label = "File", items = { ... } } } }: the
-- application menu (docs/adr/0018-a-menu-bar-the-app-declares.md). `menu`
-- is what it is; where this sits is where its titles go when they have to
-- be drawn in the window. Nothing is drawn where the platform owns the bar
-- (macOS), so a view writes it once and is portable.
-- tooltip("hint") or tooltip { children }: a float hanging below the parent.
-- For the common hover-gated case use the `tooltip = "hint"` prop on a
-- row/column instead; the node form always draws.
-- latency_hud { at = { "end", "end" } }
-- fill { name = "todos/panel", params = { ... } }: the position a plugin
-- this script loaded draws in -- a place among its siblings, not a box
-- around anything, and keyed inside this script's own fill (ADR 0014).
-- It draws nothing itself. `name` is the full "namespace/slot" -- the
-- namespace given to env.add_extension and the slot in the plugin's own
-- vocabulary. Draws an empty position when nothing answers to the name.
--
-- Named `fill` and not `slot` because `slot` is view's second argument,
-- and a script that took it would shadow the constructor in the one
-- function that needs it. A fill is what the core calls this anyway: the
-- thing an extension draws.
-- devtools_tab { name = "syntax", label = "Tree-sitter", slot = "ts/panel" }
-- devtools_tab { name = "syntax", label = "Tree-sitter", view = function()
-- return column { text("identifier 12:4") }
-- end }
--
-- A tab in the core's devtools panel (ADR 0032), beside facts, events and
-- tree. The first form names a slot a plugin fills: the panel declares it
-- in the tab's body while the tab is on show. The second is the script's
-- own content: `view` is called only while the tab is on show -- so a tab
-- nobody looks at costs its declaration and nothing else -- and the tree
-- it returns is drawn over the tab's body, the script's to hear as any of
-- its nodes. `view` takes no arguments; close over the `env` the script's
-- view received. Not a node: declare it anywhere in the tree, every frame.
-- uniform_list(env, { key = "log", rows = 10000, row_h = 28, ... }, function(i)
-- return column { fill = true, on_click = { kind = "pick", row = i }, text("line " .. i) }
-- end)
--
-- A scrolling column of `rows` uniform rows that declares only the visible
-- ones, plus the two spacers that hold the height of the rest -- so the
-- frame costs a screenful however long the list is. `env.scroll_geometry`
-- is what it slices by, so the container needs the `key` this reads it back
-- under. Every other key of `opts` is the container's own; `scroll_y` and
-- `gap` are the widget's (put a row's spacing inside `row_h`).
--
-- `row(i)` returns row i's *contents*: the widget owns the row's own node,
-- `row_h` tall and keyed by the row's data `index`, so a row keeps its
-- hover, focus, edit buffer and tweens as the built range slides over it,
-- and a virtualised list and a full one agree on identity. A clickable row
-- puts its on_click on a `fill = true` child, as above -- or on the row's
-- own node: `row_props = function(i) return { on_click = ..., bg = ... } end`
-- in `opts` gives each row's node its props (backlog DX22), its `index`
-- and `height` staying the widget's.
--
-- The geometry is the previous frame's, so the first frame -- before any
-- layout has resolved the container -- slices by the viewport, and a resize
-- is one frame late and covered by `overscan` (two rows each side).
--
-- To reach a row that is not built, `reveal_row(env, key, i, row_h)`
-- before the list scrolls it to the middle when it does not show.
-- reveal_row(env, "log", i, 28)
--
-- Scrolls the `uniform_list` keyed "log" so row i shows, when it does
-- not: to the middle, so a jump lands with rows on both sides (backlog
-- DX22, Rust's `widgets::reveal_row`). Call it before the list, so the
-- frame that scrolls builds the rows it scrolled to; `env.reveal` finds
-- nothing for a row the list has not built. True when it scrolled; the
-- first frame, before the list has laid out, scrolls nothing. Assumes the
-- rows start at the list's content top, as they do without top padding.
-- How many whole rows of `row_h` the list keyed `key` shows as of the last
-- layout -- a page's stride; 0 before it has laid out.
-- splitter(env, { key = "divider", dir = "row", thickness = 4, on_drag = { kind = "split" } })
--
-- A divider between two panes that the pointer drags (backlog DX22, Rust's
-- `widgets::splitter`): `thickness` px across (4 unless said) and growing
-- along the rest of its parent, in the theme's border colour and its accent
-- while hovered or held, with the resize arrows, and `keep_focus`, so a
-- press on it leaves the keyboard with the editor beside it. `dir` is the
-- parent's: "row" (the default) for panes side by side, "column" for panes
-- stacked. The split is the handler's: a `drag` event carries `x`, `y` and
-- `parent`, and `(x - parent.x) / parent.w` is a row's new fraction.
-- local heights = row_heights(#lines, 20)
-- list(env, { key = "chat", heights = heights },
-- function(i, width) return env.measure_text(lines[i + 1], { size = 14 }, width).height + 8 end,
-- function(i) return text { pad = 4, lines[i + 1] } end)
--
-- A scrolling column of rows of *different* heights that declares only the
-- visible ones -- `uniform_list` where no single stride describes the list.
-- `heights` is a `row_heights(rows, estimate)` the script makes once and
-- keeps: the core's own prefix sums over the rows measured so far, with the
-- mean of those standing in for every other row. `set_len` it when rows are
-- appended, `clear` it when they change under the same indices.
--
-- `measure(i, width)` returns row i's height at that content width, and is
-- called only for rows the frame is about to build that `heights` has no
-- number for; `env.measure_text(s, style, width)` is layout's own answer for
-- a text row. What it returns is the height the row gets: the widget fixes
-- each row's node to it. `row(i)` returns row i's contents, as
-- `uniform_list`'s does, keyed by the row's data `index` (0-based).
--
-- Measuring moves the estimate, and with it every row above the window, so
-- the widget puts the row the window starts in back where it was
-- (`env.shift_scroll`) -- and, mid-glide on a container with a
-- `transition`, the row the glide is going to. The arithmetic is the core's
-- (`widgets::list` in Rust); this is the loop around the script's callback.
--
-- `env.set_scroll(key, 0, heights:offset_of(i))` puts row i at the top.