@native-sdk/cli 0.5.3 → 0.6.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/build/app.zig +91 -2
- package/build.zig +756 -5
- package/build.zig.zon +7 -0
- package/native-sdk.d.ts +19 -1
- package/package.json +9 -9
- package/packages/core/package-lock.json +2 -2
- package/packages/core/package.json +1 -1
- package/packages/core/rt/rt.zig +416 -9
- package/packages/core/sdk/core.ts +706 -5
- package/packages/core/sdk/events.ts +17 -8
- package/packages/core/src/checker.ts +305 -2
- package/packages/core/src/diagnostics.ts +12 -0
- package/packages/core/src/emitter.ts +3187 -264
- package/packages/core/src/typed_ast.ts +51 -4
- package/packages/core/src/types.ts +34 -1
- package/skill-data/native-ui/SKILL.md +42 -4
- package/skill-data/ts-core/SKILL.md +13 -3
- package/src/app_runner/root.zig +112 -10
- package/src/app_runner/ts_core_main.zig +4 -0
- package/src/automation/layout_fingerprint.zig +160 -0
- package/src/automation/protocol.zig +82 -33
- package/src/automation/root.zig +1 -0
- package/src/automation/server.zig +1 -1
- package/src/automation/snapshot.zig +68 -9
- package/src/automation/watcher.zig +1 -1
- package/src/embed/host.zig +5 -0
- package/src/embed/tests.zig +119 -1
- package/src/embed/ui_host.zig +13 -0
- package/src/platform/linux/gtk_host.c +639 -16
- package/src/platform/linux/gtk_host.h +25 -0
- package/src/platform/linux/root.zig +351 -7
- package/src/platform/macos/appkit_host.h +152 -8
- package/src/platform/macos/appkit_host.m +1816 -100
- package/src/platform/macos/cef_host.mm +372 -11
- package/src/platform/macos/root.zig +379 -11
- package/src/platform/null_platform.zig +696 -9
- package/src/platform/null_platform_tests.zig +35 -0
- package/src/platform/root.zig +42 -0
- package/src/platform/types.zig +524 -18
- package/src/platform/windows/root.zig +432 -9
- package/src/platform/windows/webview2_host.cpp +482 -45
- package/src/primitives/app_manifest/comptime_scene.zig +5 -0
- package/src/primitives/app_manifest/root.zig +1 -0
- package/src/primitives/app_manifest/types.zig +32 -0
- package/src/primitives/app_manifest/validation.zig +18 -0
- package/src/primitives/canvas/a11y_audit.zig +33 -11
- package/src/primitives/canvas/a11y_audit_tests.zig +20 -0
- package/src/primitives/canvas/drawing.zig +25 -0
- package/src/primitives/canvas/equality.zig +8 -0
- package/src/primitives/canvas/events.zig +103 -16
- package/src/primitives/canvas/frame.zig +125 -1
- package/src/primitives/canvas/layout_audit.zig +22 -5
- package/src/primitives/canvas/markdown_hostile_tests.zig +8 -4
- package/src/primitives/canvas/render_tests.zig +13 -10
- package/src/primitives/canvas/root.zig +48 -0
- package/src/primitives/canvas/terminal_box.zig +471 -0
- package/src/primitives/canvas/terminal_grid.zig +978 -0
- package/src/primitives/canvas/terminal_grid_tests.zig +1093 -0
- package/src/primitives/canvas/test_support.zig +1 -0
- package/src/primitives/canvas/tests.zig +2 -0
- package/src/primitives/canvas/text_tests.zig +39 -4
- package/src/primitives/canvas/tokens.zig +115 -12
- package/src/primitives/canvas/ui.zig +535 -12
- package/src/primitives/canvas/ui_markup.zig +253 -36
- package/src/primitives/canvas/ui_markup_binary.zig +4 -1
- package/src/primitives/canvas/ui_markup_compiled.zig +195 -9
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +188 -8
- package/src/primitives/canvas/ui_markup_contract.zig +89 -6
- package/src/primitives/canvas/ui_markup_contract_tests.zig +65 -1
- package/src/primitives/canvas/ui_markup_huge_document_tests.zig +154 -0
- package/src/primitives/canvas/ui_markup_huge_model_tests.zig +1 -0
- package/src/primitives/canvas/ui_markup_reflect.zig +75 -24
- package/src/primitives/canvas/ui_markup_tests.zig +178 -9
- package/src/primitives/canvas/ui_markup_view.zig +220 -11
- package/src/primitives/canvas/ui_markup_view_tests.zig +553 -28
- package/src/primitives/canvas/ui_schema.zig +110 -17
- package/src/primitives/canvas/ui_schema_tests.zig +18 -10
- package/src/primitives/canvas/ui_tests.zig +141 -9
- package/src/primitives/canvas/widget_access.zig +28 -2
- package/src/primitives/canvas/widget_anchored_tests.zig +48 -0
- package/src/primitives/canvas/widget_invalidation.zig +81 -1
- package/src/primitives/canvas/widget_layout.zig +59 -11
- package/src/primitives/canvas/widget_layout_tests.zig +125 -4
- package/src/primitives/canvas/widget_render.zig +272 -18
- package/src/primitives/canvas/widget_render_scroll.zig +108 -27
- package/src/primitives/canvas/widget_routing.zig +59 -7
- package/src/primitives/canvas/widget_runtime.zig +23 -0
- package/src/primitives/canvas/widget_runtime_tests.zig +149 -0
- package/src/primitives/canvas/widget_semantics.zig +119 -11
- package/src/primitives/canvas/widget_semantics_tests.zig +409 -0
- package/src/primitives/canvas/widget_tree.zig +17 -0
- package/src/primitives/canvas/widgets.zig +132 -0
- package/src/root.zig +23 -0
- package/src/runtime/api.zig +76 -5
- package/src/runtime/automation_commands.zig +20 -1
- package/src/runtime/automation_snapshot.zig +25 -1
- package/src/runtime/automation_widget_dispatch.zig +73 -8
- package/src/runtime/bridge_payload.zig +8 -0
- package/src/runtime/bridge_responses.zig +5 -0
- package/src/runtime/builtin_bridge.zig +9 -4
- package/src/runtime/canvas_font_tests.zig +439 -2
- package/src/runtime/canvas_fonts.zig +61 -6
- package/src/runtime/canvas_frame.zig +62 -7
- package/src/runtime/canvas_frame_animation_tests.zig +5 -4
- package/src/runtime/canvas_frame_helpers.zig +190 -1
- package/src/runtime/canvas_frame_invalidation_tests.zig +531 -0
- package/src/runtime/canvas_frame_patch_tests.zig +161 -10
- package/src/runtime/canvas_frame_retained_tests.zig +5 -2
- package/src/runtime/canvas_image_tests.zig +195 -0
- package/src/runtime/canvas_images.zig +45 -12
- package/src/runtime/canvas_widget_accessibility_tests.zig +1 -1
- package/src/runtime/canvas_widget_clipboard_tests.zig +40 -0
- package/src/runtime/canvas_widget_context_menu.zig +269 -32
- package/src/runtime/canvas_widget_context_menu_tests.zig +640 -14
- package/src/runtime/canvas_widget_display.zig +1 -1
- package/src/runtime/canvas_widget_event_tests.zig +1823 -0
- package/src/runtime/canvas_widget_events.zig +240 -24
- package/src/runtime/canvas_widget_runtime.zig +213 -29
- package/src/runtime/canvas_widget_scroll_driver_tests.zig +170 -7
- package/src/runtime/canvas_widget_scroll_drivers.zig +151 -17
- package/src/runtime/canvas_widget_scroll_tests.zig +435 -23
- package/src/runtime/canvas_widget_state.zig +6 -0
- package/src/runtime/canvas_widget_text_tests.zig +1 -1
- package/src/runtime/core.zig +131 -13
- package/src/runtime/effects.zig +8136 -180
- package/src/runtime/effects_channel_tests.zig +3519 -0
- package/src/runtime/effects_fetch_tests.zig +89 -1
- package/src/runtime/effects_file_tests.zig +41 -1
- package/src/runtime/effects_image_tests.zig +1304 -0
- package/src/runtime/effects_pty_tests.zig +1362 -0
- package/src/runtime/effects_tests.zig +167 -9
- package/src/runtime/effects_video_tests.zig +3609 -0
- package/src/runtime/flow.zig +42 -4
- package/src/runtime/gpu_surface_events.zig +473 -13
- package/src/runtime/media_surface.zig +116 -11
- package/src/runtime/media_surface_tests.zig +61 -0
- package/src/runtime/pty.zig +1252 -0
- package/src/runtime/pty_windows.zig +1780 -0
- package/src/runtime/root.zig +36 -0
- package/src/runtime/runtime_event_tests.zig +20 -1
- package/src/runtime/session_blobs.zig +689 -0
- package/src/runtime/session_journal.zig +432 -62
- package/src/runtime/session_record.zig +43 -2
- package/src/runtime/session_replay.zig +556 -20
- package/src/runtime/session_tests.zig +2087 -1
- package/src/runtime/shell_layout.zig +7 -0
- package/src/runtime/terminal_session.zig +1569 -0
- package/src/runtime/terminal_session_tests.zig +450 -0
- package/src/runtime/terminal_vt_ghostty.zig +15 -0
- package/src/runtime/terminal_vt_stub.zig +13 -0
- package/src/runtime/testdata/fonts/NotoSansSC-Receipt.ttf +0 -0
- package/src/runtime/testdata/fonts/OFL.txt +93 -0
- package/src/runtime/tests.zig +8 -0
- package/src/runtime/ts_core_host.zig +1320 -45
- package/src/runtime/ts_core_host_tests.zig +1100 -1
- package/src/runtime/ts_ui_app.zig +23 -5
- package/src/runtime/ui_app.zig +2444 -69
- package/src/runtime/ui_app_tests.zig +3171 -744
- package/src/runtime/ui_app_virtual_variable_tests.zig +4 -2
- package/src/runtime/ui_app_window_tests.zig +736 -0
- package/src/runtime/view.zig +190 -2
- package/src/runtime/view_widget_scroll.zig +218 -68
- package/src/runtime/view_widget_text.zig +11 -2
- package/src/runtime/view_widget_tree.zig +111 -3
- package/src/runtime/window_command_bridge_tests.zig +117 -0
- package/src/runtime/window_storage.zig +77 -2
- package/src/runtime/window_view_runtime.zig +34 -2
- package/src/runtime/window_views.zig +62 -1
- package/src/terminal_session_tests_root.zig +15 -0
- package/src/tooling/manifest.zig +75 -0
- package/src/tooling/raw_manifest.zig +2 -0
- package/src/tooling/templates.zig +244 -8
|
@@ -52,6 +52,38 @@ fn warnStackContainerGap(kind: WidgetKind, gap: f32) void {
|
|
|
52
52
|
);
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
/// Debug-build diagnostics for scroll-axis combinations that only a
|
|
56
|
+
/// DYNAMIC value can produce (markup validation already rejects the
|
|
57
|
+
/// literal spellings): a horizontal grant on a virtualized region is
|
|
58
|
+
/// ignored — windowed virtualization prices rows, not columns — and a
|
|
59
|
+
/// `value_x` without a horizontal grant is silently inert. Warn and
|
|
60
|
+
/// keep building; the runtime behavior (vertical scrolling, offset
|
|
61
|
+
/// ignored) is well-defined either way.
|
|
62
|
+
fn warnInertScrollAxis(kind: WidgetKind, options: ElementOptionsShape) void {
|
|
63
|
+
if (builtin.mode != .Debug) return;
|
|
64
|
+
if (kind != .scroll_view) return;
|
|
65
|
+
if (options.virtualized and options.axis != .vertical) {
|
|
66
|
+
ui_log.warn(
|
|
67
|
+
"axis={s} is ignored on a virtualized scroll: windowed virtualization prices rows, not columns, so the region scrolls vertically",
|
|
68
|
+
.{@tagName(options.axis)},
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
if (options.value_x != 0 and (options.virtualized or !options.axis.scrollsHorizontally())) {
|
|
72
|
+
ui_log.warn(
|
|
73
|
+
"value_x does nothing without a horizontal axis grant: declare axis horizontal (or both) on the scroll region, or drop the offset",
|
|
74
|
+
.{},
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/// The slice of `ElementOptions` the scroll-axis diagnostic reads —
|
|
80
|
+
/// declared outside the generic `Ui` so the warning helper can too.
|
|
81
|
+
const ElementOptionsShape = struct {
|
|
82
|
+
virtualized: bool,
|
|
83
|
+
axis: canvas.ScrollAxes,
|
|
84
|
+
value_x: f32,
|
|
85
|
+
};
|
|
86
|
+
|
|
55
87
|
/// Debug-build diagnostic for a set `wrap` on anything but a plain text
|
|
56
88
|
/// leaf. `ElementOptions.wrap` is text-leaf line policy only — rows and
|
|
57
89
|
/// columns never flow-wrap their children (that is the layout system's
|
|
@@ -96,12 +128,16 @@ fn warnTextSizeKind(kind: WidgetKind, size: canvas.WidgetSize) void {
|
|
|
96
128
|
/// (`automate screenshot`), mobile embeds, provider-less measurement.
|
|
97
129
|
/// Markup literals get the same lesson as a validation error; this
|
|
98
130
|
/// diagnostic is the net for DYNAMIC strings (model-derived text
|
|
99
|
-
/// reaches no static check) and Zig-authored literals.
|
|
100
|
-
///
|
|
101
|
-
///
|
|
102
|
-
///
|
|
103
|
-
///
|
|
104
|
-
///
|
|
131
|
+
/// reaches no static check) and Zig-authored literals. The check
|
|
132
|
+
/// knows only bundled coverage — a builder has no view of the
|
|
133
|
+
/// runtime's font registry — so a run whose tokens point at a
|
|
134
|
+
/// registered face covering the codepoint renders real glyphs and
|
|
135
|
+
/// still logs here; that imprecision is one reason this logs at
|
|
136
|
+
/// .debug. Logs the first uncovered codepoint per text run and keeps
|
|
137
|
+
/// building — live macOS rendering falls back through CoreText, so
|
|
138
|
+
/// this must never fail an app, and .debug (the
|
|
139
|
+
/// `logAxisChildrenOverflow` precedent) because a .warn inside a
|
|
140
|
+
/// test-built view would fail the whole suite for a rendering nit.
|
|
105
141
|
fn warnUncoveredText(kind: WidgetKind, text: []const u8) void {
|
|
106
142
|
if (builtin.mode != .Debug) return;
|
|
107
143
|
var index: usize = 0;
|
|
@@ -111,7 +147,7 @@ fn warnUncoveredText(kind: WidgetKind, text: []const u8) void {
|
|
|
111
147
|
const codepoint = std.unicode.utf8Decode(text[index .. index + len]) catch return;
|
|
112
148
|
if (codepoint >= 0x20 and codepoint != 0x7F and !font_coverage.covers(codepoint)) {
|
|
113
149
|
ui_log.debug(
|
|
114
|
-
"{s} text contains \"{s}\" (U+{X:0>4}), outside the bundled font's coverage - it renders as a tofu box on the reference/screenshot and mobile paths; use a vector icon (icon option, <icon name>) or plain words",
|
|
150
|
+
"{s} text contains \"{s}\" (U+{X:0>4}), outside the bundled font's coverage - it renders as a tofu box on the reference/screenshot and mobile paths unless a registered font covers it; register a font (UiApp Options.fonts), use a vector icon (icon option, <icon name>), or plain words",
|
|
115
151
|
.{ @tagName(kind), text[index .. index + len], codepoint },
|
|
116
152
|
);
|
|
117
153
|
return;
|
|
@@ -227,6 +263,16 @@ pub const MarkupFragmentDiagnostic = struct {
|
|
|
227
263
|
/// markup imports), or null while the fragment matches its compiled
|
|
228
264
|
/// baseline. `report` carries a reloaded-but-unbuildable fragment's
|
|
229
265
|
/// teaching diagnostic back to the app loop's markup diagnostic channel.
|
|
266
|
+
/// The terminal grid lookup the app loop installs on the builder before
|
|
267
|
+
/// each build (`Ui.terminal_lookup`): finalize resolves each `.terminal`
|
|
268
|
+
/// widget's bound pty key through it to the session store's published
|
|
269
|
+
/// `TerminalGrid` snapshot. Untyped context so the builder core never
|
|
270
|
+
/// imports the runtime — the same seam shape as `MarkupFragmentHost`.
|
|
271
|
+
pub const TerminalGridLookup = struct {
|
|
272
|
+
context: *anyopaque,
|
|
273
|
+
resolve: *const fn (context: *anyopaque, pty: u64) ?*const canvas.TerminalGrid,
|
|
274
|
+
};
|
|
275
|
+
|
|
230
276
|
pub const MarkupFragmentHost = struct {
|
|
231
277
|
context: *anyopaque,
|
|
232
278
|
override: *const fn (context: *anyopaque, key: *const anyopaque) ?*const anyopaque,
|
|
@@ -292,6 +338,22 @@ pub const UiHandlerEvent = enum {
|
|
|
292
338
|
/// prepending a batch causes on its own, since the offset grows by
|
|
293
339
|
/// the prepended extent to keep the viewport anchored.
|
|
294
340
|
reach_start,
|
|
341
|
+
/// Terminal view-state changes (wheel/keyboard scrollback, the
|
|
342
|
+
/// layout-derived grid resize), dispatched with the TerminalState
|
|
343
|
+
/// the runtime already applied — echoing its `scrollback` back into
|
|
344
|
+
/// the attribute never fights the terminal reconcile rule.
|
|
345
|
+
terminal,
|
|
346
|
+
/// The pointer entered the widget's hit region (the Elm
|
|
347
|
+
/// onMouseEnter convention): a discrete containment edge the
|
|
348
|
+
/// runtime derives from the same resolution the hover wash uses,
|
|
349
|
+
/// dispatched once per entry — never per move. Every enter is
|
|
350
|
+
/// paired with an eventual `.hover_leave` while the app runs.
|
|
351
|
+
hover_enter,
|
|
352
|
+
/// The pointer left the widget's hit region — by moving out, by
|
|
353
|
+
/// the pointer leaving the window, by the widget unmounting or a
|
|
354
|
+
/// scroll/rebuild moving it out from under a stationary pointer,
|
|
355
|
+
/// or by a dismissal removing the surface under the pointer.
|
|
356
|
+
hover_leave,
|
|
295
357
|
};
|
|
296
358
|
|
|
297
359
|
/// A color design token referenced by name (the fields of
|
|
@@ -395,6 +457,15 @@ pub fn Ui(comptime Msg: type) type {
|
|
|
395
457
|
/// `Tree.context_menu_fallback`. 0 (the default) synthesizes
|
|
396
458
|
/// nothing.
|
|
397
459
|
context_menu_fallback_target: ObjectId = 0,
|
|
460
|
+
/// The secondary click's pointer location (view-local canvas
|
|
461
|
+
/// points, the same space widget frames resolve in), set alongside
|
|
462
|
+
/// `context_menu_fallback_target`: the synthesized surface anchors
|
|
463
|
+
/// at this point — like every native context menu — instead of a
|
|
464
|
+
/// target-widget edge, so a menu opened on a wide row opens at the
|
|
465
|
+
/// click, not the row's corner. Null keeps the legacy
|
|
466
|
+
/// below-the-target anchor (a fallback opened without pointer
|
|
467
|
+
/// provenance).
|
|
468
|
+
context_menu_fallback_point: ?geometry.PointF = null,
|
|
398
469
|
/// Set by `finalizeNode` when the fallback target was found and a
|
|
399
470
|
/// surface was synthesized; copied onto the returned `Tree`.
|
|
400
471
|
context_menu_fallback_result: ?Tree.ContextMenuFallback = null,
|
|
@@ -407,6 +478,26 @@ pub fn Ui(comptime Msg: type) type {
|
|
|
407
478
|
/// and the seam stays untyped (`anyopaque` document pointers)
|
|
408
479
|
/// so the builder core never imports the markup engine.
|
|
409
480
|
markup_fragment_host: ?MarkupFragmentHost = null,
|
|
481
|
+
/// Live video playback state for the house transport chrome:
|
|
482
|
+
/// the app loop stamps the channel's snapshot here before each
|
|
483
|
+
/// build, so `video` renders honest play/pause, elapsed, and
|
|
484
|
+
/// seek state without the model carrying any of it. Defaults
|
|
485
|
+
/// (inactive) outside an app loop, where the chrome renders
|
|
486
|
+
/// disabled.
|
|
487
|
+
video_state: VideoPlaybackState = .{},
|
|
488
|
+
/// Terminal grid lookup for `.terminal` widgets: the app loop
|
|
489
|
+
/// installs it before each build, and finalize resolves every
|
|
490
|
+
/// bound pty key to the session store's published snapshot.
|
|
491
|
+
/// Null outside an app loop (bare builders, tests that stamp
|
|
492
|
+
/// grids by hand), where terminals render unbound.
|
|
493
|
+
terminal_lookup: ?TerminalGridLookup = null,
|
|
494
|
+
/// The `<video src>` declaration this build recorded (see
|
|
495
|
+
/// `video`): last-wins, mirroring `loadVideo`'s replace
|
|
496
|
+
/// semantics — one player is the whole playback surface. The
|
|
497
|
+
/// app loop reads it after the build and reconciles it into the
|
|
498
|
+
/// video channel; null means no src-bearing video was declared
|
|
499
|
+
/// (surface-only chrome declares nothing).
|
|
500
|
+
video_declaration: ?VideoDeclaration = null,
|
|
410
501
|
|
|
411
502
|
pub const ElementOptions = struct {
|
|
412
503
|
/// Sibling-scoped identity: the widget id hashes the parent
|
|
@@ -441,6 +532,25 @@ pub fn Ui(comptime Msg: type) type {
|
|
|
441
532
|
text: []const u8 = "",
|
|
442
533
|
placeholder: []const u8 = "",
|
|
443
534
|
value: f32 = 0,
|
|
535
|
+
/// HORIZONTAL scroll offset for a horizontal-capable
|
|
536
|
+
/// `scroll` container (markup `value-x`) — the sideways
|
|
537
|
+
/// counterpart of `value`. Follows the same source-wins
|
|
538
|
+
/// reconcile rule: echo the `on_scroll` state's `offset_x`
|
|
539
|
+
/// back here and the runtime-owned offset survives
|
|
540
|
+
/// rebuilds; change it model-side to scroll
|
|
541
|
+
/// programmatically. Meaningless on every other element.
|
|
542
|
+
value_x: f32 = 0,
|
|
543
|
+
/// Which axes a `scroll` container scrolls (markup `axis`):
|
|
544
|
+
/// `.vertical` (the default — every scroll region before
|
|
545
|
+
/// axis declarations existed), `.horizontal`, or `.both`.
|
|
546
|
+
/// Horizontal grants opt the region into wheel/trackpad
|
|
547
|
+
/// `delta_x`, the bottom-edge scrollbar, and the horizontal
|
|
548
|
+
/// keymap (Left/Right lines, and on horizontal-only regions
|
|
549
|
+
/// Home/End/PageUp/PageDown too). Virtualized containers
|
|
550
|
+
/// ignore a horizontal grant — windowed virtualization
|
|
551
|
+
/// prices rows, not columns. Meaningless on non-scroll
|
|
552
|
+
/// elements.
|
|
553
|
+
axis: canvas.ScrollAxes = .vertical,
|
|
444
554
|
checked: bool = false,
|
|
445
555
|
selected: bool = false,
|
|
446
556
|
/// Disclosure state for tree rows (`role = .treeitem`): null
|
|
@@ -637,6 +747,21 @@ pub fn Ui(comptime Msg: type) type {
|
|
|
637
747
|
/// Gap in points between anchor edge and surface (`anchor`
|
|
638
748
|
/// only).
|
|
639
749
|
anchor_offset: f32 = 4,
|
|
750
|
+
/// The `.terminal` element's pty binding: the MODEL-OWNED
|
|
751
|
+
/// u64 effect key the app's `ptySpawn` named (markup
|
|
752
|
+
/// `pty={binding}` — ids are model data, never markup
|
|
753
|
+
/// literals). 0 is the unbound sentinel: the terminal
|
|
754
|
+
/// paints the honest empty surface. Meaningless on every
|
|
755
|
+
/// other element.
|
|
756
|
+
pty: u64 = 0,
|
|
757
|
+
/// The `.terminal` element's scrollback offset in rows
|
|
758
|
+
/// above the live screen (markup `scrollback=`), following
|
|
759
|
+
/// the scroll `value` source-wins reconcile rule: echo the
|
|
760
|
+
/// `on_terminal` state's `scrollback` back here and the
|
|
761
|
+
/// runtime-owned position survives rebuilds; change it
|
|
762
|
+
/// model-side to scroll programmatically. 0 is pinned to
|
|
763
|
+
/// the live bottom. Meaningless on every other element.
|
|
764
|
+
scrollback: u32 = 0,
|
|
640
765
|
on_press: ?Msg = null,
|
|
641
766
|
/// Double-click Msg (builder-only): dispatched on a release
|
|
642
767
|
/// whose click count reached 2, in place of `on_press` for
|
|
@@ -688,6 +813,36 @@ pub fn Ui(comptime Msg: type) type {
|
|
|
688
813
|
/// alternative. Like `on_press`, binding it makes the element
|
|
689
814
|
/// a hit target and press claimer.
|
|
690
815
|
on_hold: ?Msg = null,
|
|
816
|
+
/// Pointer hover-enter Msg (the Elm onMouseEnter
|
|
817
|
+
/// convention): dispatched once when the pointer enters
|
|
818
|
+
/// the element's hit region — a discrete containment edge,
|
|
819
|
+
/// never per move. Binding it (or `on_hover_leave`) makes
|
|
820
|
+
/// the element hover-hittable the way `on_press` makes it
|
|
821
|
+
/// pressable, WITHOUT claiming presses or painting any
|
|
822
|
+
/// hover wash — hover feedback stays with acting controls;
|
|
823
|
+
/// a quiet content tile that binds hover stays quiet.
|
|
824
|
+
/// Hover comes from mouse/trackpad pointers only; touch
|
|
825
|
+
/// input never synthesizes it.
|
|
826
|
+
on_hover_enter: ?Msg = null,
|
|
827
|
+
/// Pointer hover-leave Msg, the paired exit edge: fires
|
|
828
|
+
/// when the pointer leaves the element's hit region — by
|
|
829
|
+
/// moving out, by leaving the window, by the element
|
|
830
|
+
/// unmounting, or by a scroll/rebuild moving the element
|
|
831
|
+
/// out from under a stationary pointer (the same
|
|
832
|
+
/// resolution the hover wash uses). Every dispatched
|
|
833
|
+
/// enter is answered by exactly one eventual leave while
|
|
834
|
+
/// the app runs; the leave Msg is CAPTURED while the
|
|
835
|
+
/// element stands — payload slices deep-copied into
|
|
836
|
+
/// app-owned bytes, refreshed as rebuilds change the
|
|
837
|
+
/// binding, retained from the last build that bound one —
|
|
838
|
+
/// so an element removed (or unbound) mid-hover still
|
|
839
|
+
/// delivers its pair. The one uncapturable payload shape is
|
|
840
|
+
/// a single-item pointer, which no markup can construct — a
|
|
841
|
+
/// Zig view binding one DISABLES the pair for that element
|
|
842
|
+
/// with a warning (no enter dispatches, because its paired
|
|
843
|
+
/// leave could dangle); bind a slice or scalar payload
|
|
844
|
+
/// instead.
|
|
845
|
+
on_hover_leave: ?Msg = null,
|
|
691
846
|
/// Message constructor for text edits: called with each
|
|
692
847
|
/// `TextInputEvent` on text-entry widgets. Pair with `inputMsg`.
|
|
693
848
|
on_input: ?InputMsgFn = null,
|
|
@@ -718,6 +873,15 @@ pub fn Ui(comptime Msg: type) type {
|
|
|
718
873
|
/// so echoing it back into `value` on the next rebuild never
|
|
719
874
|
/// fights the scroll reconcile rule.
|
|
720
875
|
on_scroll: ?ScrollMsgFn = null,
|
|
876
|
+
/// Message constructor for terminal view-state changes on a
|
|
877
|
+
/// `terminal` element: called with the post-change
|
|
878
|
+
/// `canvas.TerminalState` (scrollback, history, cols, rows)
|
|
879
|
+
/// after every runtime-applied change — wheel and keyboard
|
|
880
|
+
/// scrollback, and the layout-derived grid resize. Pair
|
|
881
|
+
/// with `terminalMsg`. The delivered state is what the
|
|
882
|
+
/// runtime already applied, so echoing `scrollback` back
|
|
883
|
+
/// never fights the terminal reconcile rule.
|
|
884
|
+
on_terminal: ?TerminalMsgFn = null,
|
|
721
885
|
/// Context menu for this widget: right/ctrl-click (or a touch
|
|
722
886
|
/// long-press) presents these items through the platform's
|
|
723
887
|
/// native menu (macOS `NSMenu`); selecting one dispatches its
|
|
@@ -742,6 +906,7 @@ pub fn Ui(comptime Msg: type) type {
|
|
|
742
906
|
pub const ValueMsgFn = *const fn (value: f32) Msg;
|
|
743
907
|
pub const LinkMsgFn = *const fn (link: []const u8) Msg;
|
|
744
908
|
pub const ScrollMsgFn = *const fn (scroll: canvas.ScrollState) Msg;
|
|
909
|
+
pub const TerminalMsgFn = *const fn (state: canvas.TerminalState) Msg;
|
|
745
910
|
|
|
746
911
|
pub const Node = struct {
|
|
747
912
|
widget: Widget = .{ .kind = .stack },
|
|
@@ -761,12 +926,15 @@ pub fn Ui(comptime Msg: type) type {
|
|
|
761
926
|
on_submit: ?Msg = null,
|
|
762
927
|
on_dismiss: ?Msg = null,
|
|
763
928
|
on_hold: ?Msg = null,
|
|
929
|
+
on_hover_enter: ?Msg = null,
|
|
930
|
+
on_hover_leave: ?Msg = null,
|
|
764
931
|
on_reach_end: ?Msg = null,
|
|
765
932
|
on_reach_start: ?Msg = null,
|
|
766
933
|
on_input: ?InputMsgFn = null,
|
|
767
934
|
on_value: ?ValueMsgFn = null,
|
|
768
935
|
on_resize: ?ValueMsgFn = null,
|
|
769
936
|
on_scroll: ?ScrollMsgFn = null,
|
|
937
|
+
on_terminal: ?TerminalMsgFn = null,
|
|
770
938
|
context_menu: []const ContextMenuItem = &.{},
|
|
771
939
|
nodes: []const Node = &.{},
|
|
772
940
|
/// Markup authoring provenance, stamped by the markup engines
|
|
@@ -786,6 +954,7 @@ pub fn Ui(comptime Msg: type) type {
|
|
|
786
954
|
input: InputMsgFn,
|
|
787
955
|
value: ValueMsgFn,
|
|
788
956
|
scroll: ScrollMsgFn,
|
|
957
|
+
terminal: TerminalMsgFn,
|
|
789
958
|
/// Per-item context-menu messages, indexed like the
|
|
790
959
|
/// widget's `context_menu` items (null = inert entry:
|
|
791
960
|
/// separator or msg-less item).
|
|
@@ -949,6 +1118,48 @@ pub fn Ui(comptime Msg: type) type {
|
|
|
949
1118
|
}.make;
|
|
950
1119
|
}
|
|
951
1120
|
|
|
1121
|
+
/// Comptime message constructor for `on_terminal`:
|
|
1122
|
+
/// `terminalMsg(.term_state)` yields a function building
|
|
1123
|
+
/// `Msg{ .term_state = state }` from the post-change
|
|
1124
|
+
/// `canvas.TerminalState`.
|
|
1125
|
+
pub fn terminalMsg(comptime tag: std.meta.Tag(Msg)) TerminalMsgFn {
|
|
1126
|
+
return struct {
|
|
1127
|
+
fn make(state: canvas.TerminalState) Msg {
|
|
1128
|
+
return @unionInit(Msg, @tagName(tag), state);
|
|
1129
|
+
}
|
|
1130
|
+
}.make;
|
|
1131
|
+
}
|
|
1132
|
+
|
|
1133
|
+
/// Comptime message constructor for `on_terminal` over a DECLARED
|
|
1134
|
+
/// terminal-state record (`ui_markup_reflect.declaredTerminalStateRecord`
|
|
1135
|
+
/// — the transpiled-core shape, where the emitted module declares
|
|
1136
|
+
/// its own mirror of `canvas.TerminalState` and type identity
|
|
1137
|
+
/// cannot cross the emission boundary). Fields map by name (the
|
|
1138
|
+
/// TS spellings are identical) and each numeric field widens the
|
|
1139
|
+
/// way the payload declares it.
|
|
1140
|
+
pub fn translatedTerminalMsg(comptime tag: std.meta.Tag(Msg), comptime Payload: type) TerminalMsgFn {
|
|
1141
|
+
return struct {
|
|
1142
|
+
fn num(comptime N: type, value: anytype) N {
|
|
1143
|
+
// Saturating, never trapping: a transpiled core may
|
|
1144
|
+
// declare a field narrower than the runtime value
|
|
1145
|
+
// (`cols: u8` cannot hold the 320-column max, a
|
|
1146
|
+
// small `history` cannot hold a long scrollback), and
|
|
1147
|
+
// an `@intCast` would panic the app on the first such
|
|
1148
|
+
// report. The clamp keeps every representable value
|
|
1149
|
+
// exact and pins the rest at the field's ceiling.
|
|
1150
|
+
return if (@typeInfo(N) == .float) @floatFromInt(value) else std.math.lossyCast(N, value);
|
|
1151
|
+
}
|
|
1152
|
+
|
|
1153
|
+
fn make(state: canvas.TerminalState) Msg {
|
|
1154
|
+
var payload: Payload = undefined;
|
|
1155
|
+
inline for (@typeInfo(Payload).@"struct".fields) |field| {
|
|
1156
|
+
@field(payload, field.name) = num(field.type, @field(state, field.name));
|
|
1157
|
+
}
|
|
1158
|
+
return @unionInit(Msg, @tagName(tag), payload);
|
|
1159
|
+
}
|
|
1160
|
+
}.make;
|
|
1161
|
+
}
|
|
1162
|
+
|
|
952
1163
|
/// Comptime message constructor for `on_link`: `linkMsg(.open_url)`
|
|
953
1164
|
/// yields a function building `Msg{ .open_url = link }`. The link
|
|
954
1165
|
/// slice lives in the view arena (or the caller's markdown source),
|
|
@@ -1048,6 +1259,17 @@ pub fn Ui(comptime Msg: type) type {
|
|
|
1048
1259
|
|
|
1049
1260
|
/// Typed dispatch for scroll offset changes: builds the message
|
|
1050
1261
|
/// through the widget's `on_scroll` constructor.
|
|
1262
|
+
/// Terminal view-state changes route the applied state
|
|
1263
|
+
/// through the widget's `on_terminal` constructor.
|
|
1264
|
+
pub fn msgForTerminal(self: Tree, id: ObjectId, state: canvas.TerminalState) ?Msg {
|
|
1265
|
+
for (self.handlers) |handler| {
|
|
1266
|
+
if (handler.id == id and handler.event == .terminal and handler.action == .terminal) {
|
|
1267
|
+
return handler.action.terminal(state);
|
|
1268
|
+
}
|
|
1269
|
+
}
|
|
1270
|
+
return null;
|
|
1271
|
+
}
|
|
1272
|
+
|
|
1051
1273
|
pub fn msgForScroll(self: Tree, id: ObjectId, scroll_state: canvas.ScrollState) ?Msg {
|
|
1052
1274
|
for (self.handlers) |handler| {
|
|
1053
1275
|
if (handler.id == id and handler.event == .scroll and handler.action == .scroll) {
|
|
@@ -1215,8 +1437,10 @@ pub fn Ui(comptime Msg: type) type {
|
|
|
1215
1437
|
pub fn el(self: *Self, kind: WidgetKind, options: ElementOptions, children: anytype) Node {
|
|
1216
1438
|
if (options.on_dismiss != null) warnDismissHandlerKind(kind);
|
|
1217
1439
|
if (options.on_resize != null) warnResizeHandlerKind(kind);
|
|
1440
|
+
var widget = widgetFromOptions(kind, options);
|
|
1441
|
+
if (kind == .media_surface) self.stampVideoSurfaceFit(&widget);
|
|
1218
1442
|
return .{
|
|
1219
|
-
.widget =
|
|
1443
|
+
.widget = widget,
|
|
1220
1444
|
.key = options.key,
|
|
1221
1445
|
.global_key = options.global_key,
|
|
1222
1446
|
.wrap = options.wrap,
|
|
@@ -1228,12 +1452,15 @@ pub fn Ui(comptime Msg: type) type {
|
|
|
1228
1452
|
.on_submit = options.on_submit,
|
|
1229
1453
|
.on_dismiss = options.on_dismiss,
|
|
1230
1454
|
.on_hold = options.on_hold,
|
|
1455
|
+
.on_hover_enter = options.on_hover_enter,
|
|
1456
|
+
.on_hover_leave = options.on_hover_leave,
|
|
1231
1457
|
.on_reach_end = options.on_reach_end,
|
|
1232
1458
|
.on_reach_start = options.on_reach_start,
|
|
1233
1459
|
.on_input = options.on_input,
|
|
1234
1460
|
.on_value = options.on_value,
|
|
1235
1461
|
.on_resize = options.on_resize,
|
|
1236
1462
|
.on_scroll = options.on_scroll,
|
|
1463
|
+
.on_terminal = options.on_terminal,
|
|
1237
1464
|
.context_menu = self.dupeContextMenuItems(options.context_menu),
|
|
1238
1465
|
.nodes = self.childNodes(children),
|
|
1239
1466
|
};
|
|
@@ -1742,6 +1969,25 @@ pub fn Ui(comptime Msg: type) type {
|
|
|
1742
1969
|
return self.el(.image, options, .{});
|
|
1743
1970
|
}
|
|
1744
1971
|
|
|
1972
|
+
/// The terminal leaf (markup `<terminal pty={key}>`): paints the
|
|
1973
|
+
/// framework-owned emulator session behind the MODEL-OWNED pty
|
|
1974
|
+
/// effect key in `options.pty` (the key `fx.ptySpawn` named; 0
|
|
1975
|
+
/// renders the honest empty surface) and routes keys, IME text,
|
|
1976
|
+
/// and wheel scrollback to it when focused. `options.scrollback`
|
|
1977
|
+
/// echoes the app-visible view state back (the scroll `value`
|
|
1978
|
+
/// source-wins rule) and `options.on_terminal` hears it change
|
|
1979
|
+
/// (`canvas.TerminalState`). Size it like a media surface:
|
|
1980
|
+
/// definite width/height or flex grow — the runtime derives the
|
|
1981
|
+
/// pty's cols/rows FROM the frame the layout resolves. The text
|
|
1982
|
+
/// channel is RUNTIME-OWNED (the live screen text rides it for
|
|
1983
|
+
/// assistive tech and the session fingerprint): an authored
|
|
1984
|
+
/// `text` would be overwritten every frame, so name the terminal
|
|
1985
|
+
/// with `semantics.label` (markup `label=`, which its a11y lint
|
|
1986
|
+
/// requires).
|
|
1987
|
+
pub fn terminal(self: *Self, options: ElementOptions) Node {
|
|
1988
|
+
return self.el(.terminal, options, .{});
|
|
1989
|
+
}
|
|
1990
|
+
|
|
1745
1991
|
/// The media surface leaf (markup `<media-surface surface={id}>`):
|
|
1746
1992
|
/// composites a texture PRODUCED OUTSIDE the widget tree — a
|
|
1747
1993
|
/// video decoder, a camera pipeline, an external renderer —
|
|
@@ -1759,6 +2005,230 @@ pub fn Ui(comptime Msg: type) type {
|
|
|
1759
2005
|
return self.el(.media_surface, options, .{});
|
|
1760
2006
|
}
|
|
1761
2007
|
|
|
2008
|
+
/// CONTAIN is the video surface's one fit mode: every media
|
|
2009
|
+
/// surface the video channel feeds — the framework-owned
|
|
2010
|
+
/// `<video>` surface always, an app-claimed surface while its
|
|
2011
|
+
/// playback is live — letterboxes the decoded frame instead of
|
|
2012
|
+
/// stretching it. Stamped on every construction path (`el` runs
|
|
2013
|
+
/// this for the builder, both markup engines, and the house
|
|
2014
|
+
/// `<video>` chrome), with the stream's reported dimensions
|
|
2015
|
+
/// riding `Widget.stream_size` once the LOADED event has
|
|
2016
|
+
/// spoken, so the emit computes the fitted quad from journaled
|
|
2017
|
+
/// truth. The dimensions land ONLY on the surface the active
|
|
2018
|
+
/// playback actually feeds: a source-less `<video>` shown while
|
|
2019
|
+
/// a manual load targets some other surface keeps its
|
|
2020
|
+
/// full-frame placeholder instead of borrowing that unrelated
|
|
2021
|
+
/// stream's geometry. Camera or app-producer surfaces are
|
|
2022
|
+
/// untouched: their producers own their geometry (and
|
|
2023
|
+
/// `image_src` keeps its ordinary source-crop meaning).
|
|
2024
|
+
fn stampVideoSurfaceFit(self: *const Self, widget: *Widget) void {
|
|
2025
|
+
if (widget.image_id == 0) return;
|
|
2026
|
+
const state = self.video_state;
|
|
2027
|
+
const is_playback_target = state.surface != 0 and widget.image_id == state.surface;
|
|
2028
|
+
if (!is_playback_target and widget.image_id != canvas.video_playback_surface_id) return;
|
|
2029
|
+
widget.image_fit = .contain;
|
|
2030
|
+
if (is_playback_target and state.width > 0 and state.height > 0) {
|
|
2031
|
+
widget.stream_size = .{
|
|
2032
|
+
.width = @floatFromInt(state.width),
|
|
2033
|
+
.height = @floatFromInt(state.height),
|
|
2034
|
+
};
|
|
2035
|
+
}
|
|
2036
|
+
}
|
|
2037
|
+
|
|
2038
|
+
/// The live playback state the house video chrome renders (see
|
|
2039
|
+
/// `Ui.video_state`): what the video channel has honestly
|
|
2040
|
+
/// reported, never what the model believes.
|
|
2041
|
+
pub const VideoPlaybackState = struct {
|
|
2042
|
+
active: bool = false,
|
|
2043
|
+
playing: bool = false,
|
|
2044
|
+
buffering: bool = false,
|
|
2045
|
+
/// The playback reached its non-looping natural end: the
|
|
2046
|
+
/// player is retired, so seeking is dead (the scrub
|
|
2047
|
+
/// disables) while Play stays live — the runtime restarts
|
|
2048
|
+
/// the playback from the start on it.
|
|
2049
|
+
completed: bool = false,
|
|
2050
|
+
position_ms: u64 = 0,
|
|
2051
|
+
duration_ms: u64 = 0,
|
|
2052
|
+
/// The media-surface id the ACTIVE playback feeds (0 while
|
|
2053
|
+
/// none): `canvas.video_playback_surface_id` for a declared
|
|
2054
|
+
/// `<video>`, the app's own id for a `loadVideo` claim. The
|
|
2055
|
+
/// builder stamps CONTAIN fit on the matching surface —
|
|
2056
|
+
/// video frames letterbox, never stretch.
|
|
2057
|
+
surface: u64 = 0,
|
|
2058
|
+
/// The stream's reported dimensions (the LOADED event's
|
|
2059
|
+
/// journaled report; 0 until it lands): the geometry the
|
|
2060
|
+
/// video surface's fitted draw is computed from.
|
|
2061
|
+
width: u64 = 0,
|
|
2062
|
+
height: u64 = 0,
|
|
2063
|
+
};
|
|
2064
|
+
|
|
2065
|
+
/// One build's recorded `<video src>` declaration (see
|
|
2066
|
+
/// `Ui.video_declaration`): the source string plus the flags
|
|
2067
|
+
/// that shape a fresh load. `src` is arena-copied by `video`,
|
|
2068
|
+
/// so it outlives the build exactly as long as the tree does.
|
|
2069
|
+
pub const VideoDeclaration = struct {
|
|
2070
|
+
src: []const u8 = "",
|
|
2071
|
+
controls: bool = false,
|
|
2072
|
+
autoplay: bool = true,
|
|
2073
|
+
loop: bool = false,
|
|
2074
|
+
muted: bool = false,
|
|
2075
|
+
};
|
|
2076
|
+
|
|
2077
|
+
pub const VideoOptions = struct {
|
|
2078
|
+
/// Playback source: an app-assets path or an http(s) URL —
|
|
2079
|
+
/// the `loadVideo` cascade's resolution order. Empty
|
|
2080
|
+
/// declares nothing: the element is surface-only chrome
|
|
2081
|
+
/// over whatever playback the app loaded itself.
|
|
2082
|
+
src: []const u8 = "",
|
|
2083
|
+
/// Compose the house transport chrome (play/pause, elapsed,
|
|
2084
|
+
/// seek slider, duration) under the playback surface.
|
|
2085
|
+
controls: bool = false,
|
|
2086
|
+
/// Start playing as soon as the load lands (the fresh
|
|
2087
|
+
/// load's behavior; `loadVideo`'s default).
|
|
2088
|
+
autoplay: bool = true,
|
|
2089
|
+
/// Wrap from the natural end back to zero and keep playing.
|
|
2090
|
+
loop: bool = false,
|
|
2091
|
+
/// Start with the audio track muted.
|
|
2092
|
+
muted: bool = false,
|
|
2093
|
+
key: ?UiKey = null,
|
|
2094
|
+
global_key: ?UiKey = null,
|
|
2095
|
+
/// Definite surface width/height (same contract as
|
|
2096
|
+
/// `ElementOptions.width`/`height`); the surface has no
|
|
2097
|
+
/// intrinsic size, so size it definitely or flex `grow`.
|
|
2098
|
+
width: f32 = 0,
|
|
2099
|
+
height: f32 = 0,
|
|
2100
|
+
grow: f32 = 0,
|
|
2101
|
+
/// Accessible name of the playback surface (the image
|
|
2102
|
+
/// leaf's alt-equivalent label rule).
|
|
2103
|
+
label: []const u8 = "",
|
|
2104
|
+
};
|
|
2105
|
+
|
|
2106
|
+
/// The video playback element (markup `<video>`): a leaf
|
|
2107
|
+
/// compositing the app's SINGLE video playback — decoded
|
|
2108
|
+
/// platform-side into the framework-owned playback surface
|
|
2109
|
+
/// (`canvas.video_playback_surface_id`) — with optional house
|
|
2110
|
+
/// transport chrome, all from existing widgets. A nonempty
|
|
2111
|
+
/// `src` RECORDS the declaration on the builder (last-wins,
|
|
2112
|
+
/// mirroring `loadVideo`'s replace semantics); the app loop
|
|
2113
|
+
/// reconciles it into the video channel after the build, so
|
|
2114
|
+
/// declaring the element IS the playback. The chrome carries no
|
|
2115
|
+
/// app Msgs: its controls are stamped with `video_control`
|
|
2116
|
+
/// verbs the runtime consumes directly.
|
|
2117
|
+
pub fn video(self: *Self, options: VideoOptions) Node {
|
|
2118
|
+
if (options.src.len > 0) {
|
|
2119
|
+
const stored_src = self.arena.dupe(u8, options.src) catch {
|
|
2120
|
+
self.failed = true;
|
|
2121
|
+
return self.el(.column, .{}, .{});
|
|
2122
|
+
};
|
|
2123
|
+
self.video_declaration = .{
|
|
2124
|
+
.src = stored_src,
|
|
2125
|
+
.controls = options.controls,
|
|
2126
|
+
.autoplay = options.autoplay,
|
|
2127
|
+
.loop = options.loop,
|
|
2128
|
+
.muted = options.muted,
|
|
2129
|
+
};
|
|
2130
|
+
}
|
|
2131
|
+
if (!options.controls) {
|
|
2132
|
+
// Surface-only: the simplest tree — the media surface
|
|
2133
|
+
// itself carries the sizing and identity.
|
|
2134
|
+
return self.el(.media_surface, .{
|
|
2135
|
+
.key = options.key,
|
|
2136
|
+
.global_key = options.global_key,
|
|
2137
|
+
.image = canvas.video_playback_surface_id,
|
|
2138
|
+
.width = options.width,
|
|
2139
|
+
.height = options.height,
|
|
2140
|
+
.grow = options.grow,
|
|
2141
|
+
.semantics = .{ .label = options.label },
|
|
2142
|
+
}, .{});
|
|
2143
|
+
}
|
|
2144
|
+
// The surface absorbs the element's height above the
|
|
2145
|
+
// transport bar; the column carries the declared sizing.
|
|
2146
|
+
const surface = self.el(.media_surface, .{
|
|
2147
|
+
.image = canvas.video_playback_surface_id,
|
|
2148
|
+
.grow = 1,
|
|
2149
|
+
.semantics = .{ .label = options.label },
|
|
2150
|
+
}, .{});
|
|
2151
|
+
const state = self.video_state;
|
|
2152
|
+
// The transport bar, styled like the house now-playing bar:
|
|
2153
|
+
// one sm ghost icon button whose glyph follows playback
|
|
2154
|
+
// state, fixed clip-overflow time columns (a stamp like
|
|
2155
|
+
// "1:22" must never ellipsize into "1…"), and a growing
|
|
2156
|
+
// seek slider. Runtime-consumed: `video_control` verbs
|
|
2157
|
+
// instead of app Msgs.
|
|
2158
|
+
var toggle_button = self.el(.button, .{
|
|
2159
|
+
.variant = .ghost,
|
|
2160
|
+
.size = .sm,
|
|
2161
|
+
.icon = if (state.playing) "pause" else "play",
|
|
2162
|
+
.disabled = !state.active,
|
|
2163
|
+
.semantics = .{ .label = if (state.playing) "Pause" else "Play" },
|
|
2164
|
+
}, .{});
|
|
2165
|
+
toggle_button.widget.video_control = .toggle;
|
|
2166
|
+
const elapsed = self.text(.{
|
|
2167
|
+
.size = .sm,
|
|
2168
|
+
.width = 46,
|
|
2169
|
+
.wrap = false,
|
|
2170
|
+
.overflow = .clip,
|
|
2171
|
+
.style_tokens = .{ .foreground = .text_muted },
|
|
2172
|
+
}, self.formatVideoTime(state.position_ms));
|
|
2173
|
+
const fraction: f32 = if (state.duration_ms == 0)
|
|
2174
|
+
0
|
|
2175
|
+
else
|
|
2176
|
+
@floatCast(@as(f64, @floatFromInt(state.position_ms)) / @as(f64, @floatFromInt(state.duration_ms)));
|
|
2177
|
+
var scrub = self.el(.slider, .{
|
|
2178
|
+
.grow = 1,
|
|
2179
|
+
.value = fraction,
|
|
2180
|
+
// A completed playback's player is retired: a seek
|
|
2181
|
+
// would refuse and the thumb spring back, so the
|
|
2182
|
+
// scrub disables — Play (which restarts) is the live
|
|
2183
|
+
// affordance.
|
|
2184
|
+
.disabled = !state.active or state.completed,
|
|
2185
|
+
.semantics = .{ .label = "Seek" },
|
|
2186
|
+
}, .{});
|
|
2187
|
+
scrub.widget.video_control = .scrub;
|
|
2188
|
+
const duration = self.text(.{
|
|
2189
|
+
.size = .sm,
|
|
2190
|
+
.width = 46,
|
|
2191
|
+
.wrap = false,
|
|
2192
|
+
.overflow = .clip,
|
|
2193
|
+
.style_tokens = .{ .foreground = .text_muted },
|
|
2194
|
+
}, self.formatVideoTime(state.duration_ms));
|
|
2195
|
+
const controls_row = self.el(.row, .{
|
|
2196
|
+
.padding = 8,
|
|
2197
|
+
.gap = 8,
|
|
2198
|
+
.cross = .center,
|
|
2199
|
+
.style_tokens = .{ .background = .surface },
|
|
2200
|
+
}, .{ toggle_button, elapsed, scrub, duration });
|
|
2201
|
+
var wrap = self.el(.column, .{
|
|
2202
|
+
.key = options.key,
|
|
2203
|
+
.global_key = options.global_key,
|
|
2204
|
+
.width = options.width,
|
|
2205
|
+
.height = options.height,
|
|
2206
|
+
.grow = options.grow,
|
|
2207
|
+
.gap = 0,
|
|
2208
|
+
}, .{ surface, controls_row });
|
|
2209
|
+
// The controls-bearing form keeps the bare surface's
|
|
2210
|
+
// no-intrinsic-size contract: the transport bar must never
|
|
2211
|
+
// size the element (an unsized <video controls> in a hug
|
|
2212
|
+
// container would otherwise render as a controls-only
|
|
2213
|
+
// strip), and it clips away entirely when the layout grants
|
|
2214
|
+
// the element nothing.
|
|
2215
|
+
wrap.widget.layout.zero_intrinsic = true;
|
|
2216
|
+
wrap.widget.layout.clip_content = true;
|
|
2217
|
+
return wrap;
|
|
2218
|
+
}
|
|
2219
|
+
|
|
2220
|
+
/// A playback time readout: h:mm:ss at an hour and beyond,
|
|
2221
|
+
/// m:ss below it — the fixed-format stamp the chrome's clipped
|
|
2222
|
+
/// time columns render.
|
|
2223
|
+
fn formatVideoTime(self: *Self, ms: u64) []const u8 {
|
|
2224
|
+
const total_seconds = ms / 1000;
|
|
2225
|
+
const seconds = total_seconds % 60;
|
|
2226
|
+
const minutes = (total_seconds / 60) % 60;
|
|
2227
|
+
const hours = total_seconds / 3600;
|
|
2228
|
+
if (hours > 0) return self.fmt("{d}:{d:0>2}:{d:0>2}", .{ hours, minutes, seconds });
|
|
2229
|
+
return self.fmt("{d}:{d:0>2}", .{ minutes, seconds });
|
|
2230
|
+
}
|
|
2231
|
+
|
|
1762
2232
|
/// A built-in vector icon leaf: `name` is one of
|
|
1763
2233
|
/// `canvas.icons.known_icon_names` (compile error otherwise), so
|
|
1764
2234
|
/// icon references never rot. Size comes from `options.size` /
|
|
@@ -2452,6 +2922,13 @@ pub fn Ui(comptime Msg: type) type {
|
|
|
2452
2922
|
// press, and the classic list-row shape (press to open, hold
|
|
2453
2923
|
// for the menu) pairs the two on one element.
|
|
2454
2924
|
if (node.on_hold != null) widget.semantics.actions.press = true;
|
|
2925
|
+
// Hover family: binding either edge makes the element
|
|
2926
|
+
// hover-hittable (`Widget.hover_msgs` — the chart
|
|
2927
|
+
// hover-details shape, a hit target that claims no
|
|
2928
|
+
// presses), never pressable: hover is not an action a
|
|
2929
|
+
// screen reader can invoke, so no semantic action is
|
|
2930
|
+
// stamped.
|
|
2931
|
+
if (node.on_hover_enter != null or node.on_hover_leave != null) widget.hover_msgs = true;
|
|
2455
2932
|
if (node.on_input != null) widget.semantics.actions.set_text = true;
|
|
2456
2933
|
if (widget.kind == .slider and (node.on_value != null or node.on_change != null)) {
|
|
2457
2934
|
widget.semantics.actions.increment = true;
|
|
@@ -2488,6 +2965,8 @@ pub fn Ui(comptime Msg: type) type {
|
|
|
2488
2965
|
appendHandler(handlers, handler_len, widget.id, .submit, node.on_submit);
|
|
2489
2966
|
appendHandler(handlers, handler_len, widget.id, .dismiss, node.on_dismiss);
|
|
2490
2967
|
appendHandler(handlers, handler_len, widget.id, .hold, node.on_hold);
|
|
2968
|
+
appendHandler(handlers, handler_len, widget.id, .hover_enter, node.on_hover_enter);
|
|
2969
|
+
appendHandler(handlers, handler_len, widget.id, .hover_leave, node.on_hover_leave);
|
|
2491
2970
|
appendHandler(handlers, handler_len, widget.id, .reach_end, node.on_reach_end);
|
|
2492
2971
|
appendHandler(handlers, handler_len, widget.id, .reach_start, node.on_reach_start);
|
|
2493
2972
|
if (node.on_input) |make| {
|
|
@@ -2506,6 +2985,32 @@ pub fn Ui(comptime Msg: type) type {
|
|
|
2506
2985
|
handlers[handler_len.*] = .{ .id = widget.id, .event = .scroll, .action = .{ .scroll = make } };
|
|
2507
2986
|
handler_len.* += 1;
|
|
2508
2987
|
}
|
|
2988
|
+
if (node.on_terminal) |make| {
|
|
2989
|
+
handlers[handler_len.*] = .{ .id = widget.id, .event = .terminal, .action = .{ .terminal = make } };
|
|
2990
|
+
handler_len.* += 1;
|
|
2991
|
+
}
|
|
2992
|
+
if (widget.kind == .terminal) {
|
|
2993
|
+
// Resolve the bound pty's published grid snapshot (the
|
|
2994
|
+
// app loop installs the lookup before each build; a
|
|
2995
|
+
// bare builder has none and the widget stays unbound).
|
|
2996
|
+
if (widget.terminal.pty != 0) {
|
|
2997
|
+
if (self.terminal_lookup) |lookup| {
|
|
2998
|
+
widget.terminal.grid = lookup.resolve(lookup.context, widget.terminal.pty);
|
|
2999
|
+
}
|
|
3000
|
+
}
|
|
3001
|
+
// The live screen text IS the terminal's semantic
|
|
3002
|
+
// CONTENT: it rides the widget's text (the value the
|
|
3003
|
+
// textbox exposes and the session fingerprint hashes),
|
|
3004
|
+
// NOT the accessible name. The author's `label` stays
|
|
3005
|
+
// the stable control NAME — clobbering it with the whole
|
|
3006
|
+
// screen would rename the control after its output every
|
|
3007
|
+
// frame and strand keyboard navigation. With no author
|
|
3008
|
+
// label, `semanticLabel` falls back to this text, so an
|
|
3009
|
+
// unnamed terminal still reads its screen.
|
|
3010
|
+
if (widget.terminal.grid) |grid| {
|
|
3011
|
+
if (grid.screen_text.len > 0) widget.text = grid.screen_text;
|
|
3012
|
+
}
|
|
3013
|
+
}
|
|
2509
3014
|
if (node.context_menu.len > 0) {
|
|
2510
3015
|
// Split the declared items: labels ride the widget (the
|
|
2511
3016
|
// runtime builds the platform request from them), messages
|
|
@@ -2537,9 +3042,11 @@ pub fn Ui(comptime Msg: type) type {
|
|
|
2537
3042
|
}
|
|
2538
3043
|
|
|
2539
3044
|
/// Synthesize the anchored context-menu fallback surface as a
|
|
2540
|
-
/// child of `widget`: a `dropdown_menu` floating
|
|
2541
|
-
///
|
|
2542
|
-
///
|
|
3045
|
+
/// child of `widget`: a `dropdown_menu` floating at the click
|
|
3046
|
+
/// point (`context_menu_fallback_point`; below the target when no
|
|
3047
|
+
/// point was recorded) with one `menu_item` per declared item
|
|
3048
|
+
/// (`separator`s keep their slots). Items carry press semantics
|
|
3049
|
+
/// but no handler
|
|
2543
3050
|
/// entries — the app loop maps their presses through the
|
|
2544
3051
|
/// target's existing `.context_menu` handler, the same entry a
|
|
2545
3052
|
/// native selection resolves.
|
|
@@ -2573,7 +3080,16 @@ pub fn Ui(comptime Msg: type) type {
|
|
|
2573
3080
|
.semantics = .{ .label = "Context menu" },
|
|
2574
3081
|
.children = item_widgets,
|
|
2575
3082
|
};
|
|
2576
|
-
|
|
3083
|
+
// Anchor at the recorded click point when the request carried
|
|
3084
|
+
// one (offset 0: the surface corner sits at the pointer, the
|
|
3085
|
+
// native-menu convention); the widget-edge anchor remains the
|
|
3086
|
+
// pointer-less floor. Either way the anchored-surface edge
|
|
3087
|
+
// rules apply: flip above the anchor when the surface would
|
|
3088
|
+
// cross the bottom edge, clamp into the window.
|
|
3089
|
+
surface.layout.anchor = if (self.context_menu_fallback_point) |point|
|
|
3090
|
+
.{ .placement = .below, .alignment = .start, .offset = 0, .point = point }
|
|
3091
|
+
else
|
|
3092
|
+
.{ .placement = .below, .alignment = .start };
|
|
2577
3093
|
const children = try self.arena.alloc(Widget, widget.children.len + 1);
|
|
2578
3094
|
@memcpy(children[0..widget.children.len], widget.children);
|
|
2579
3095
|
children[widget.children.len] = surface;
|
|
@@ -2600,12 +3116,15 @@ pub fn Ui(comptime Msg: type) type {
|
|
|
2600
3116
|
if (node.on_submit != null) total += 1;
|
|
2601
3117
|
if (node.on_dismiss != null) total += 1;
|
|
2602
3118
|
if (node.on_hold != null) total += 1;
|
|
3119
|
+
if (node.on_hover_enter != null) total += 1;
|
|
3120
|
+
if (node.on_hover_leave != null) total += 1;
|
|
2603
3121
|
if (node.on_reach_end != null) total += 1;
|
|
2604
3122
|
if (node.on_reach_start != null) total += 1;
|
|
2605
3123
|
if (node.on_input != null) total += 1;
|
|
2606
3124
|
if (node.on_value != null) total += 1;
|
|
2607
3125
|
if (node.on_resize != null) total += 1;
|
|
2608
3126
|
if (node.on_scroll != null) total += 1;
|
|
3127
|
+
if (node.on_terminal != null) total += 1;
|
|
2609
3128
|
if (node.context_menu.len > 0) total += 1;
|
|
2610
3129
|
for (node.nodes) |child| total += countHandlers(child);
|
|
2611
3130
|
return total;
|
|
@@ -2681,6 +3200,7 @@ pub fn Ui(comptime Msg: type) type {
|
|
|
2681
3200
|
fn widgetFromOptions(kind: WidgetKind, options: ElementOptions) Widget {
|
|
2682
3201
|
warnStackContainerGap(kind, options.gap);
|
|
2683
3202
|
warnUnknownIconName(options.icon);
|
|
3203
|
+
warnInertScrollAxis(kind, .{ .virtualized = options.virtualized, .axis = options.axis, .value_x = options.value_x });
|
|
2684
3204
|
var widget: Widget = .{
|
|
2685
3205
|
.kind = kind,
|
|
2686
3206
|
.frame = options.frame,
|
|
@@ -2695,6 +3215,9 @@ pub fn Ui(comptime Msg: type) type {
|
|
|
2695
3215
|
.autofocus = options.autofocus,
|
|
2696
3216
|
.image_id = options.image,
|
|
2697
3217
|
.value = options.value,
|
|
3218
|
+
.value_x = options.value_x,
|
|
3219
|
+
.terminal = .{ .pty = options.pty, .scrollback = options.scrollback },
|
|
3220
|
+
.scroll_axes = options.axis,
|
|
2698
3221
|
.variant = options.variant,
|
|
2699
3222
|
.size = options.size,
|
|
2700
3223
|
.state = .{
|