@native-sdk/cli 0.5.4 → 0.6.1
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 +50 -1
- package/build.zig +588 -32
- package/build.zig.zon +7 -0
- package/native-sdk.d.ts +3 -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 +280 -8
- package/packages/core/sdk/core.ts +481 -2
- 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 +599 -3
- package/packages/core/src/typed_ast.ts +51 -4
- package/packages/core/src/types.ts +34 -1
- package/skill-data/native-ui/SKILL.md +39 -2
- package/skill-data/ts-core/SKILL.md +4 -2
- package/src/app_runner/root.zig +32 -10
- 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/ui_host.zig +13 -0
- package/src/platform/linux/gtk_host.c +527 -13
- package/src/platform/linux/gtk_host.h +25 -0
- package/src/platform/linux/root.zig +280 -7
- package/src/platform/macos/appkit_host.h +104 -6
- package/src/platform/macos/appkit_host.m +1368 -74
- package/src/platform/macos/cef_host.mm +110 -1
- package/src/platform/macos/root.zig +287 -7
- package/src/platform/null_platform.zig +398 -4
- package/src/platform/null_platform_tests.zig +35 -0
- package/src/platform/root.zig +9 -0
- package/src/platform/types.zig +386 -14
- package/src/platform/windows/root.zig +298 -9
- package/src/platform/windows/webview2_host.cpp +330 -5
- 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 +1 -0
- package/src/primitives/canvas/text_tests.zig +39 -4
- package/src/primitives/canvas/tokens.zig +115 -12
- package/src/primitives/canvas/ui.zig +524 -5
- package/src/primitives/canvas/ui_markup.zig +195 -2
- package/src/primitives/canvas/ui_markup_compiled.zig +172 -1
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +133 -8
- package/src/primitives/canvas/ui_markup_contract.zig +88 -5
- package/src/primitives/canvas/ui_markup_contract_tests.zig +39 -1
- 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 +149 -0
- package/src/primitives/canvas/ui_markup_view.zig +191 -0
- package/src/primitives/canvas/ui_markup_view_tests.zig +403 -19
- package/src/primitives/canvas/ui_schema.zig +97 -17
- package/src/primitives/canvas/ui_schema_tests.zig +18 -11
- 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 +16 -0
- package/src/runtime/api.zig +76 -6
- 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 +1 -0
- 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_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 +268 -26
- 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 +73 -2
- package/src/runtime/effects.zig +6389 -54
- package/src/runtime/effects_channel_tests.zig +3519 -0
- package/src/runtime/effects_pty_tests.zig +1362 -0
- package/src/runtime/effects_tests.zig +14 -9
- package/src/runtime/effects_video_tests.zig +3609 -0
- package/src/runtime/flow.zig +25 -4
- package/src/runtime/gpu_surface_events.zig +475 -15
- 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 +25 -0
- package/src/runtime/runtime_event_tests.zig +20 -1
- package/src/runtime/session_journal.zig +367 -61
- package/src/runtime/session_record.zig +16 -0
- package/src/runtime/session_replay.zig +395 -11
- package/src/runtime/session_tests.zig +114 -19
- 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/tests.zig +6 -0
- package/src/runtime/ts_core_host.zig +980 -140
- package/src/runtime/ts_core_host_tests.zig +1059 -1
- package/src/runtime/ts_ui_app.zig +16 -5
- package/src/runtime/ui_app.zig +2338 -67
- 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 +268 -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_storage.zig +45 -2
- package/src/runtime/window_view_runtime.zig +34 -2
- package/src/runtime/window_views.zig +1 -0
- package/src/terminal_session_tests_root.zig +15 -0
- package/src/tooling/templates.zig +25 -7
|
@@ -26,22 +26,60 @@ pub const ScrollbarGeometry = struct {
|
|
|
26
26
|
thumb: geometry.RectF,
|
|
27
27
|
};
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
/// Emit the engine scrollbars for one scroll region: the vertical bar
|
|
30
|
+
/// on the right edge (part slots 2/3, exactly as before) and the
|
|
31
|
+
/// horizontal bar along the bottom edge (part slots 4/5), each drawn
|
|
32
|
+
/// only when its axis has scrollable range. When BOTH are visible each
|
|
33
|
+
/// track ends short of the shared corner by the other bar's thickness
|
|
34
|
+
/// plus the inset — the standard scroller corner gap, so the thumbs
|
|
35
|
+
/// never overlap.
|
|
36
|
+
pub fn emitScrollViewScrollbars(builder: *Builder, frame: geometry.RectF, vertical: WidgetScrollMetrics, horizontal: WidgetScrollMetrics, tokens: DesignTokens, id: ObjectId) Error!void {
|
|
37
|
+
try emitScrollViewScrollbarAxis(builder, frame, vertical, tokens, id, .vertical, scrollbarCornerReserve(frame, vertical, horizontal, tokens, .vertical), 2);
|
|
38
|
+
try emitScrollViewScrollbarAxis(builder, frame, horizontal, tokens, id, .horizontal, scrollbarCornerReserve(frame, vertical, horizontal, tokens, .horizontal), 4);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/// The corner gap each track reserves when both bars are visible: the
|
|
42
|
+
/// OTHER bar's thickness plus the edge inset, 0 when either bar is
|
|
43
|
+
/// absent.
|
|
44
|
+
fn scrollbarCornerReserve(frame: geometry.RectF, vertical: WidgetScrollMetrics, horizontal: WidgetScrollMetrics, tokens: DesignTokens, axis: token_model.ScrollAxis) f32 {
|
|
45
|
+
if (!scrollbarAxisVisible(vertical) or !scrollbarAxisVisible(horizontal)) return 0;
|
|
46
|
+
const inset = densityValue(tokens, 3);
|
|
47
|
+
const other: token_model.ScrollAxis = if (axis == .vertical) .horizontal else .vertical;
|
|
48
|
+
return scrollbarThickness(frame, tokens, other) + inset;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
fn scrollbarAxisVisible(metrics: WidgetScrollMetrics) bool {
|
|
52
|
+
const viewport = nonNegative(metrics.viewport_extent);
|
|
53
|
+
const content = nonNegative(metrics.content_extent);
|
|
54
|
+
return metrics.present and viewport > 0 and content > viewport;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/// Each bar's thickness derives from the dimension it spans ACROSS —
|
|
58
|
+
/// the vertical bar from the region's width (exactly the pre-axis
|
|
59
|
+
/// formula, so every existing vertical scrollbar renders byte-identical
|
|
60
|
+
/// pixels), the horizontal bar from its height (the mirror).
|
|
61
|
+
fn scrollbarThickness(frame: geometry.RectF, tokens: DesignTokens, axis: token_model.ScrollAxis) f32 {
|
|
62
|
+
const reference = if (axis == .vertical) frame.width else frame.height;
|
|
63
|
+
return @min(@max(densityValue(tokens, 3), reference * 0.0125), densityValue(tokens, 6));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
fn emitScrollViewScrollbarAxis(builder: *Builder, frame: geometry.RectF, metrics: WidgetScrollMetrics, tokens: DesignTokens, id: ObjectId, axis: token_model.ScrollAxis, reserved_end: f32, track_slot: ObjectId) Error!void {
|
|
67
|
+
const scrollbar = scrollViewScrollbarGeometryForAxis(frame, metrics, tokens, axis, reserved_end) orelse return;
|
|
31
68
|
const track = pixelSnapGeometryRect(tokens, scrollbar.track);
|
|
32
69
|
const thumb = pixelSnapGeometryRect(tokens, scrollbar.thumb);
|
|
33
70
|
const visual = tokens.controls.scrollbar;
|
|
34
|
-
const
|
|
71
|
+
const bar_thickness = if (axis == .vertical) track.width else track.height;
|
|
72
|
+
const radius = Radius.all(if (visual.radius) |value| nonNegative(value) else bar_thickness * 0.5);
|
|
35
73
|
const track_fill = visual.background orelse colorWithAlpha(tokens.colors.border, @min(tokens.colors.border.a, 0.22));
|
|
36
74
|
const thumb_fill = visual.foreground orelse visual.active_background orelse colorWithAlpha(tokens.colors.text_muted, 0.55);
|
|
37
75
|
try builder.fillRoundedRect(.{
|
|
38
|
-
.id = widgetPartId(id,
|
|
76
|
+
.id = widgetPartId(id, track_slot),
|
|
39
77
|
.rect = track,
|
|
40
78
|
.radius = radius,
|
|
41
79
|
.fill = colorFill(track_fill),
|
|
42
80
|
});
|
|
43
81
|
try builder.fillRoundedRect(.{
|
|
44
|
-
.id = widgetPartId(id,
|
|
82
|
+
.id = widgetPartId(id, track_slot + 1),
|
|
45
83
|
.rect = thumb,
|
|
46
84
|
.radius = radius,
|
|
47
85
|
.fill = colorFill(thumb_fill),
|
|
@@ -49,6 +87,10 @@ pub fn emitScrollViewScrollbar(builder: *Builder, frame: geometry.RectF, metrics
|
|
|
49
87
|
}
|
|
50
88
|
|
|
51
89
|
pub fn scrollViewScrollbarGeometry(frame: geometry.RectF, metrics: WidgetScrollMetrics, tokens: DesignTokens) ?ScrollbarGeometry {
|
|
90
|
+
return scrollViewScrollbarGeometryForAxis(frame, metrics, tokens, .vertical, 0);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
pub fn scrollViewScrollbarGeometryForAxis(frame: geometry.RectF, metrics: WidgetScrollMetrics, tokens: DesignTokens, axis: token_model.ScrollAxis, reserved_end: f32) ?ScrollbarGeometry {
|
|
52
94
|
if (!metrics.present) return null;
|
|
53
95
|
const viewport = nonNegative(metrics.viewport_extent);
|
|
54
96
|
const content = nonNegative(metrics.content_extent);
|
|
@@ -56,41 +98,80 @@ pub fn scrollViewScrollbarGeometry(frame: geometry.RectF, metrics: WidgetScrollM
|
|
|
56
98
|
if (frame.isEmpty() or viewport <= 0 or content <= viewport or max_offset <= 0) return null;
|
|
57
99
|
|
|
58
100
|
const inset = densityValue(tokens, 3);
|
|
59
|
-
const thickness =
|
|
60
|
-
const
|
|
61
|
-
if (
|
|
62
|
-
|
|
63
|
-
const track =
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
101
|
+
const thickness = scrollbarThickness(frame, tokens, axis);
|
|
102
|
+
const track_extent = @max(0, (if (axis == .vertical) frame.height else frame.width) - inset * 2 - nonNegative(reserved_end));
|
|
103
|
+
if (track_extent <= 0 or thickness <= 0) return null;
|
|
104
|
+
|
|
105
|
+
const track = switch (axis) {
|
|
106
|
+
.vertical => geometry.RectF.init(
|
|
107
|
+
frame.x + frame.width - inset - thickness,
|
|
108
|
+
frame.y + inset,
|
|
109
|
+
thickness,
|
|
110
|
+
track_extent,
|
|
111
|
+
),
|
|
112
|
+
.horizontal => geometry.RectF.init(
|
|
113
|
+
frame.x + inset,
|
|
114
|
+
frame.y + frame.height - inset - thickness,
|
|
115
|
+
track_extent,
|
|
116
|
+
thickness,
|
|
117
|
+
),
|
|
118
|
+
};
|
|
69
119
|
const thumb_ratio = std.math.clamp(viewport / content, 0, 1);
|
|
70
|
-
const min_thumb = @min(
|
|
71
|
-
const
|
|
72
|
-
const travel = @max(0,
|
|
120
|
+
const min_thumb = @min(track_extent, densityValue(tokens, 18));
|
|
121
|
+
const thumb_extent = @min(track_extent, @max(min_thumb, track_extent * thumb_ratio));
|
|
122
|
+
const travel = @max(0, track_extent - thumb_extent);
|
|
73
123
|
const offset_ratio = std.math.clamp(nonNegative(metrics.offset) / max_offset, 0, 1);
|
|
74
124
|
return .{
|
|
75
125
|
.track = track,
|
|
76
|
-
.thumb =
|
|
126
|
+
.thumb = switch (axis) {
|
|
127
|
+
.vertical => geometry.RectF.init(track.x, track.y + travel * offset_ratio, track.width, thumb_extent),
|
|
128
|
+
.horizontal => geometry.RectF.init(track.x + travel * offset_ratio, track.y, thumb_extent, track.height),
|
|
129
|
+
},
|
|
77
130
|
};
|
|
78
131
|
}
|
|
79
132
|
|
|
80
133
|
pub fn widgetScrollMetricsForWidget(widget: Widget, tokens: DesignTokens) WidgetScrollMetrics {
|
|
134
|
+
return widgetScrollAxisMetricsForWidget(widget, tokens, .vertical);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/// Per-axis metrics for a WIDGET-walk scroll view (static trees, docs
|
|
138
|
+
/// scenes — children carry their own frames). `present = false` on an
|
|
139
|
+
/// axis the region does not grant, mirroring the layout-walk metrics.
|
|
140
|
+
pub fn widgetScrollAxisMetricsForWidget(widget: Widget, tokens: DesignTokens, axis: token_model.ScrollAxis) WidgetScrollMetrics {
|
|
81
141
|
if (widget.kind != .scroll_view) return .{};
|
|
82
142
|
|
|
83
143
|
const viewport = widget.frame.inset(widget.layout.padding).normalized();
|
|
84
144
|
if (viewport.isEmpty()) return .{};
|
|
85
145
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
146
|
+
switch (axis) {
|
|
147
|
+
.vertical => {
|
|
148
|
+
if (!widget.layout.virtualized and !widget.scroll_axes.scrollsVertically()) return .{};
|
|
149
|
+
const content_extent = widgetScrollContentExtentForWidget(widget, viewport, tokens);
|
|
150
|
+
const max_offset = @max(0, content_extent - viewport.height);
|
|
151
|
+
return .{
|
|
152
|
+
.present = true,
|
|
153
|
+
.offset = std.math.clamp(nonNegative(widget.value), 0, max_offset),
|
|
154
|
+
.viewport_extent = viewport.height,
|
|
155
|
+
.content_extent = content_extent,
|
|
156
|
+
};
|
|
157
|
+
},
|
|
158
|
+
.horizontal => {
|
|
159
|
+
if (widget.layout.virtualized or !widget.scroll_axes.scrollsHorizontally()) return .{};
|
|
160
|
+
const offset = widget.value_x;
|
|
161
|
+
var right = viewport.maxX();
|
|
162
|
+
for (widget.children) |child| {
|
|
163
|
+
right = @max(right, child.frame.maxX() + offset);
|
|
164
|
+
}
|
|
165
|
+
const content_extent = @max(0, right - viewport.x);
|
|
166
|
+
const max_offset = @max(0, content_extent - viewport.width);
|
|
167
|
+
return .{
|
|
168
|
+
.present = true,
|
|
169
|
+
.offset = std.math.clamp(nonNegative(widget.value_x), 0, max_offset),
|
|
170
|
+
.viewport_extent = viewport.width,
|
|
171
|
+
.content_extent = content_extent,
|
|
172
|
+
};
|
|
173
|
+
},
|
|
174
|
+
}
|
|
94
175
|
}
|
|
95
176
|
|
|
96
177
|
fn widgetScrollContentExtentForWidget(widget: Widget, viewport: geometry.RectF, tokens: DesignTokens) f32 {
|
|
@@ -33,7 +33,28 @@ const isWidgetHiddenInAncestors = widget_tree.isWidgetHiddenInAncestors;
|
|
|
33
33
|
|
|
34
34
|
const max_widget_depth: usize = 32;
|
|
35
35
|
|
|
36
|
+
/// Which widgets a hit test may land on: the interactive policy is the
|
|
37
|
+
/// engine's classic one (presses, washes, cursor, text selection); the
|
|
38
|
+
/// hover policy additionally sees hover-Msg listeners, and ONLY the
|
|
39
|
+
/// hover-containment resolution uses it — so binding hover never moves
|
|
40
|
+
/// a wash or steals a click, even from an overlapping sibling.
|
|
41
|
+
pub const HitTestPolicy = enum {
|
|
42
|
+
interactive,
|
|
43
|
+
hover_msgs,
|
|
44
|
+
|
|
45
|
+
fn admits(comptime self: HitTestPolicy, widget: Widget) bool {
|
|
46
|
+
return switch (self) {
|
|
47
|
+
.interactive => widget_access.isHitTarget(widget),
|
|
48
|
+
.hover_msgs => widget_access.isHoverMsgHitTarget(widget),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
|
|
36
53
|
pub fn hitTestWidgetLayout(layout: anytype, point: geometry.PointF, tokens: DesignTokens) ?WidgetHit {
|
|
54
|
+
return hitTestWidgetLayoutWithPolicy(layout, point, tokens, .interactive);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
pub fn hitTestWidgetLayoutWithPolicy(layout: anytype, point: geometry.PointF, tokens: DesignTokens, comptime policy: HitTestPolicy) ?WidgetHit {
|
|
37
58
|
// Anchored floating surfaces paint in the late z-pass — topmost — so
|
|
38
59
|
// they hit-test FIRST, in reverse tree order (a nested anchored
|
|
39
60
|
// submenu has a higher node index than the surface it hangs from).
|
|
@@ -43,12 +64,12 @@ pub fn hitTestWidgetLayout(layout: anytype, point: geometry.PointF, tokens: Desi
|
|
|
43
64
|
if (!widget_tree.widgetIsAnchored(layout.nodes[index].widget)) continue;
|
|
44
65
|
if (isWidgetHiddenInAncestors(layout, index)) continue;
|
|
45
66
|
if (widget_tree.isWidgetConcealedByDisclosure(layout, index)) continue;
|
|
46
|
-
if (hitTestWidgetLayoutNode(layout, index, point, tokens)) |hit| return hit;
|
|
67
|
+
if (hitTestWidgetLayoutNode(layout, index, point, tokens, policy)) |hit| return hit;
|
|
47
68
|
}
|
|
48
|
-
return hitTestWidgetLayoutChildren(layout, null, point, tokens);
|
|
69
|
+
return hitTestWidgetLayoutChildren(layout, null, point, tokens, policy);
|
|
49
70
|
}
|
|
50
71
|
|
|
51
|
-
fn hitTestWidgetLayoutChildren(layout: anytype, parent_index: ?usize, point: geometry.PointF, tokens: DesignTokens) ?WidgetHit {
|
|
72
|
+
fn hitTestWidgetLayoutChildren(layout: anytype, parent_index: ?usize, point: geometry.PointF, tokens: DesignTokens, comptime policy: HitTestPolicy) ?WidgetHit {
|
|
52
73
|
const child_count = widget_tree.widgetLayoutDirectChildCount(layout, parent_index);
|
|
53
74
|
var tested: usize = 0;
|
|
54
75
|
var previous: ?widget_tree.WidgetPaintOrder = null;
|
|
@@ -57,14 +78,14 @@ fn hitTestWidgetLayoutChildren(layout: anytype, parent_index: ?usize, point: geo
|
|
|
57
78
|
// Anchored floating children live in the hoisted pre-pass above,
|
|
58
79
|
// never at their tree position.
|
|
59
80
|
if (!widget_tree.widgetIsAnchored(layout.nodes[child_index].widget)) {
|
|
60
|
-
if (hitTestWidgetLayoutNode(layout, child_index, point, tokens)) |hit| return hit;
|
|
81
|
+
if (hitTestWidgetLayoutNode(layout, child_index, point, tokens, policy)) |hit| return hit;
|
|
61
82
|
}
|
|
62
83
|
previous = .{ .layer = widget_tree.widgetPaintLayer(layout.nodes[child_index].widget, tokens), .index = child_index };
|
|
63
84
|
}
|
|
64
85
|
return null;
|
|
65
86
|
}
|
|
66
87
|
|
|
67
|
-
fn hitTestWidgetLayoutNode(layout: anytype, node_index: usize, point: geometry.PointF, tokens: DesignTokens) ?WidgetHit {
|
|
88
|
+
fn hitTestWidgetLayoutNode(layout: anytype, node_index: usize, point: geometry.PointF, tokens: DesignTokens, comptime policy: HitTestPolicy) ?WidgetHit {
|
|
68
89
|
if (node_index >= layout.nodes.len) return null;
|
|
69
90
|
const node = layout.nodes[node_index];
|
|
70
91
|
if (node.widget.semantics.hidden) return null;
|
|
@@ -79,10 +100,10 @@ fn hitTestWidgetLayoutNode(layout: anytype, node_index: usize, point: geometry.P
|
|
|
79
100
|
// shadows the widgets that actually occupy that space.
|
|
80
101
|
const content_interactive = !widget_tree.widgetKindDisclosureAnimated(node.widget.kind) or widget_tree.disclosureSettledOpen(layout, node_index);
|
|
81
102
|
if (content_interactive) {
|
|
82
|
-
if (hitTestWidgetLayoutChildren(layout, node_index, local_point, tokens)) |hit| return hit;
|
|
103
|
+
if (hitTestWidgetLayoutChildren(layout, node_index, local_point, tokens, policy)) |hit| return hit;
|
|
83
104
|
}
|
|
84
105
|
|
|
85
|
-
if (!
|
|
106
|
+
if (!policy.admits(node.widget)) return null;
|
|
86
107
|
if (!node.frame.normalized().containsPoint(local_point)) return null;
|
|
87
108
|
return widgetHitFromNode(node, node_index);
|
|
88
109
|
}
|
|
@@ -151,6 +172,37 @@ pub fn widgetHoverTargetForHit(layout: anytype, hit: WidgetHit) WidgetHit {
|
|
|
151
172
|
return target;
|
|
152
173
|
}
|
|
153
174
|
|
|
175
|
+
/// The hover-Msg containment chain for a raw hit: every widget on the
|
|
176
|
+
/// hit path (the target itself, then its ancestors) whose bound
|
|
177
|
+
/// hover-enter/hover-leave handlers are live
|
|
178
|
+
/// (`widget_access.widgetListensForHoverMsgs`), written into `output`
|
|
179
|
+
/// OUTERMOST FIRST — the DOM's mouseenter order, so a diff against the
|
|
180
|
+
/// previously delivered chain fires enters outermost-first and leaves
|
|
181
|
+
/// innermost-first by construction. Nested listeners each track their
|
|
182
|
+
/// own containment: moving from a listening card onto a listening row
|
|
183
|
+
/// inside it keeps the card's entry (the pointer never left the card),
|
|
184
|
+
/// exactly like the browser pair this models. The chain is empty for
|
|
185
|
+
/// apps that bind no hover handlers, so unbound trees pay nothing.
|
|
186
|
+
pub fn widgetHoverMsgChainFromNode(layout: anytype, node_index: usize, output: []ObjectId) []const ObjectId {
|
|
187
|
+
var chain: [max_widget_depth]ObjectId = undefined;
|
|
188
|
+
var chain_len: usize = 0;
|
|
189
|
+
var current: ?usize = node_index;
|
|
190
|
+
while (current) |index| {
|
|
191
|
+
if (index >= layout.nodes.len) break;
|
|
192
|
+
if (widget_access.widgetListensForHoverMsgs(layout.nodes[index].widget) and chain_len < chain.len) {
|
|
193
|
+
chain[chain_len] = layout.nodes[index].widget.id;
|
|
194
|
+
chain_len += 1;
|
|
195
|
+
}
|
|
196
|
+
current = layout.nodes[index].parent_index;
|
|
197
|
+
}
|
|
198
|
+
const len = @min(chain_len, output.len);
|
|
199
|
+
// The walk collected innermost-first; deliver outermost-first.
|
|
200
|
+
for (0..len) |index| {
|
|
201
|
+
output[index] = chain[chain_len - 1 - index];
|
|
202
|
+
}
|
|
203
|
+
return output[0..len];
|
|
204
|
+
}
|
|
205
|
+
|
|
154
206
|
/// The nearest ancestor of `node_index` with the given kind, as a hit.
|
|
155
207
|
fn widgetAncestorHitOfKind(layout: anytype, node_index: usize, kind: WidgetKind) ?WidgetHit {
|
|
156
208
|
var current: ?usize = if (node_index < layout.nodes.len) layout.nodes[node_index].parent_index else null;
|
|
@@ -91,6 +91,18 @@ pub const WidgetLayoutTree = struct {
|
|
|
91
91
|
return widget_routing.hitTestWidgetLayout(self, point, tokens);
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
+
/// The hover-Msg CONTAINMENT hit test: the interactive hit test's
|
|
95
|
+
/// resolution plus hover-Msg listeners (`HitTestPolicy.hover_msgs`).
|
|
96
|
+
/// Only enter/leave containment resolves through this — washes,
|
|
97
|
+
/// cursors, and presses never see hover-only listeners.
|
|
98
|
+
pub fn hitTestHover(self: WidgetLayoutTree, point: geometry.PointF) ?WidgetHit {
|
|
99
|
+
return widget_routing.hitTestWidgetLayoutWithPolicy(self, point, .{}, .hover_msgs);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
pub fn hitTestHoverWithTokens(self: WidgetLayoutTree, point: geometry.PointF, tokens: DesignTokens) ?WidgetHit {
|
|
103
|
+
return widget_routing.hitTestWidgetLayoutWithPolicy(self, point, tokens, .hover_msgs);
|
|
104
|
+
}
|
|
105
|
+
|
|
94
106
|
pub fn cursorForHit(self: WidgetLayoutTree, hit: ?WidgetHit) WidgetCursor {
|
|
95
107
|
_ = self;
|
|
96
108
|
return widget_access.cursorForWidgetHit(hit);
|
|
@@ -104,6 +116,17 @@ pub const WidgetLayoutTree = struct {
|
|
|
104
116
|
return widget_routing.widgetHoverTargetForHit(self, raw);
|
|
105
117
|
}
|
|
106
118
|
|
|
119
|
+
/// The hover-Msg containment chain for a raw hit (see
|
|
120
|
+
/// `widget_routing.widgetHoverMsgChainFromNode`): every live
|
|
121
|
+
/// hover-listening widget on the hit path, outermost first. Null
|
|
122
|
+
/// (or an off-tree) hit yields the empty chain — the pointer
|
|
123
|
+
/// stands inside no listener.
|
|
124
|
+
pub fn hoverMsgChainForHit(self: WidgetLayoutTree, hit: ?WidgetHit, output: []ObjectId) []const ObjectId {
|
|
125
|
+
const raw = hit orelse return output[0..0];
|
|
126
|
+
if (raw.index >= self.nodes.len) return output[0..0];
|
|
127
|
+
return widget_routing.widgetHoverMsgChainFromNode(self, raw.index, output);
|
|
128
|
+
}
|
|
129
|
+
|
|
107
130
|
pub fn routePointerEvent(self: WidgetLayoutTree, event: WidgetPointerEvent, output: []WidgetEventRouteEntry) Error!WidgetEventRoute {
|
|
108
131
|
return widget_routing.routeWidgetPointerEvent(self, event, .{}, output);
|
|
109
132
|
}
|
|
@@ -443,6 +443,41 @@ test "widget layout diff tracks added removed and layout changes by id" {
|
|
|
443
443
|
try expectRect(geometry.RectF.init(10, 50, 100, 20), invalidations[2].dirty_bounds);
|
|
444
444
|
}
|
|
445
445
|
|
|
446
|
+
test "widget layout diff marks a stream-size-only change paint dirty" {
|
|
447
|
+
// The LOADED report changes only `stream_size` on the video's media
|
|
448
|
+
// surface — same frame, same image id — but the rendering flips
|
|
449
|
+
// from a full-frame draw to bars plus a fitted quad, so the diff
|
|
450
|
+
// must invalidate or retained-pixel consumers keep the stale paint.
|
|
451
|
+
const previous_widget = Widget{
|
|
452
|
+
.id = 2,
|
|
453
|
+
.kind = .media_surface,
|
|
454
|
+
.frame = geometry.RectF.init(10, 10, 100, 40),
|
|
455
|
+
.image_id = 5,
|
|
456
|
+
.image_fit = .contain,
|
|
457
|
+
};
|
|
458
|
+
var next_widget = previous_widget;
|
|
459
|
+
next_widget.stream_size = .{ .width = 640, .height = 360 };
|
|
460
|
+
|
|
461
|
+
var previous_nodes: [1]WidgetLayoutNode = undefined;
|
|
462
|
+
var next_nodes: [1]WidgetLayoutNode = undefined;
|
|
463
|
+
const previous = try layoutWidgetTree(previous_widget, geometry.RectF.init(0, 0, 180, 100), &previous_nodes);
|
|
464
|
+
const next = try layoutWidgetTree(next_widget, geometry.RectF.init(0, 0, 180, 100), &next_nodes);
|
|
465
|
+
|
|
466
|
+
var invalidations_buffer: [2]WidgetInvalidation = undefined;
|
|
467
|
+
const invalidations = try WidgetLayoutTree.diff(previous, next, &invalidations_buffer);
|
|
468
|
+
try std.testing.expectEqual(@as(usize, 1), invalidations.len);
|
|
469
|
+
try std.testing.expectEqual(WidgetInvalidationKind.changed, invalidations[0].kind);
|
|
470
|
+
try std.testing.expect(invalidations[0].paint_dirty);
|
|
471
|
+
try std.testing.expect(!invalidations[0].layout_dirty);
|
|
472
|
+
|
|
473
|
+
// And identical stream sizes stay quiet: no phantom repaints per
|
|
474
|
+
// rebuild while a video plays.
|
|
475
|
+
var same_nodes: [1]WidgetLayoutNode = undefined;
|
|
476
|
+
const same = try layoutWidgetTree(next_widget, geometry.RectF.init(0, 0, 180, 100), &same_nodes);
|
|
477
|
+
const quiet = try WidgetLayoutTree.diff(next, same, &invalidations_buffer);
|
|
478
|
+
try std.testing.expectEqual(@as(usize, 0), quiet.len);
|
|
479
|
+
}
|
|
480
|
+
|
|
446
481
|
test "widget layout diff includes paint overdraw in dirty bounds" {
|
|
447
482
|
const panel_child = [_]Widget{.{
|
|
448
483
|
.id = 2,
|
|
@@ -571,6 +606,61 @@ test "widget render state dirty bounds tracks changed runtime states" {
|
|
|
571
606
|
try std.testing.expect(layout.renderStateDirtyBounds(.{ .focused_id = 99 }, .{ .focused_id = 100 }) == null);
|
|
572
607
|
}
|
|
573
608
|
|
|
609
|
+
test "widget render state dirty bounds tracks terminal logical focus" {
|
|
610
|
+
const rows = [_]canvas.TerminalRow{.{ .cells = &.{} }};
|
|
611
|
+
var grid = canvas.TerminalGrid{
|
|
612
|
+
.rows = &rows,
|
|
613
|
+
.background = Color.rgb8(0, 0, 0),
|
|
614
|
+
.foreground = Color.rgb8(255, 255, 255),
|
|
615
|
+
.cursor_color = Color.rgb8(255, 255, 255),
|
|
616
|
+
.selection_color = Color.rgb8(0, 128, 255),
|
|
617
|
+
.cursor = .{ .x = 0, .y = 0 },
|
|
618
|
+
};
|
|
619
|
+
const terminal = Widget{
|
|
620
|
+
.id = 9,
|
|
621
|
+
.kind = .terminal,
|
|
622
|
+
.frame = geometry.RectF.init(10, 12, 200, 100),
|
|
623
|
+
.terminal = .{ .pty = 1, .grid = &grid },
|
|
624
|
+
};
|
|
625
|
+
var nodes: [1]WidgetLayoutNode = undefined;
|
|
626
|
+
const layout = try layoutWidgetTree(terminal, terminal.frame, &nodes);
|
|
627
|
+
|
|
628
|
+
// Logical focus changes the live cursor from outline to fill even
|
|
629
|
+
// when focus-visible stays quiet, so the terminal frame is dirty.
|
|
630
|
+
try expectRect(
|
|
631
|
+
terminal.frame,
|
|
632
|
+
layout.renderStateDirtyBounds(.{}, .{ .focused_id = terminal.id }),
|
|
633
|
+
);
|
|
634
|
+
try expectRect(
|
|
635
|
+
terminal.frame,
|
|
636
|
+
layout.renderStateDirtyBounds(
|
|
637
|
+
.{ .focused_id = terminal.id },
|
|
638
|
+
.{ .keyboard_active = false, .focused_id = terminal.id },
|
|
639
|
+
),
|
|
640
|
+
);
|
|
641
|
+
|
|
642
|
+
// A static/baked focused state is the source of truth when neither
|
|
643
|
+
// render state carries a focus id. The keyboard gate still hollows
|
|
644
|
+
// that cursor, so the no-id path must report its frame dirty too.
|
|
645
|
+
var baked_terminal = terminal;
|
|
646
|
+
baked_terminal.state.focused = true;
|
|
647
|
+
var baked_nodes: [1]WidgetLayoutNode = undefined;
|
|
648
|
+
const baked_layout = try layoutWidgetTree(baked_terminal, baked_terminal.frame, &baked_nodes);
|
|
649
|
+
try expectRect(
|
|
650
|
+
baked_terminal.frame,
|
|
651
|
+
baked_layout.renderStateDirtyBounds(.{}, .{ .keyboard_active = false }),
|
|
652
|
+
);
|
|
653
|
+
|
|
654
|
+
// An ended cursor is hollow in both states: logical focus no longer
|
|
655
|
+
// changes pixels, so no damage is reported.
|
|
656
|
+
grid.running = false;
|
|
657
|
+
try std.testing.expect(layout.renderStateDirtyBounds(.{}, .{ .focused_id = terminal.id }) == null);
|
|
658
|
+
try std.testing.expect(layout.renderStateDirtyBounds(
|
|
659
|
+
.{ .focused_id = terminal.id },
|
|
660
|
+
.{ .keyboard_active = false, .focused_id = terminal.id },
|
|
661
|
+
) == null);
|
|
662
|
+
}
|
|
663
|
+
|
|
574
664
|
test "widget render state dirty bounds uses custom focus stroke tokens" {
|
|
575
665
|
const children = [_]Widget{.{
|
|
576
666
|
.id = 2,
|
|
@@ -2928,6 +3018,65 @@ test "hover target resolves composite row children to the row" {
|
|
|
2928
3018
|
try std.testing.expectEqual(WidgetCursor.arrow, layout.cursorForHit(caption_hover));
|
|
2929
3019
|
}
|
|
2930
3020
|
|
|
3021
|
+
test "hover msg chain collects nested listeners outermost first" {
|
|
3022
|
+
// A hover-listening card wrapping a hover-listening row: the chain
|
|
3023
|
+
// for a hit inside the row carries BOTH, card first (the DOM's
|
|
3024
|
+
// mouseenter order), because containment is per listener — the
|
|
3025
|
+
// pointer moving onto the row never left the card. The card is a
|
|
3026
|
+
// plain column (no hit-target kind), so the listener flag alone is
|
|
3027
|
+
// what makes it resolvable; a disabled listener stands down like it
|
|
3028
|
+
// does for presses.
|
|
3029
|
+
const label = Widget{ .id = 6, .kind = .text, .frame = geometry.RectF.init(0, 0, 100, 20), .text = "Row label" };
|
|
3030
|
+
const row = Widget{ .id = 5, .kind = .row, .frame = geometry.RectF.init(0, 0, 0, 40), .hover_msgs = true, .children = &.{label} };
|
|
3031
|
+
const plain = Widget{ .id = 4, .kind = .text, .frame = geometry.RectF.init(0, 0, 100, 20), .text = "Plain" };
|
|
3032
|
+
const card = Widget{ .id = 3, .kind = .column, .frame = geometry.RectF.init(0, 0, 0, 0), .layout = .{ .gap = 8, .padding = geometry.InsetsF.all(10) }, .hover_msgs = true, .children = &.{ plain, row } };
|
|
3033
|
+
const disabled_label = Widget{ .id = 7, .kind = .text, .frame = geometry.RectF.init(0, 0, 100, 20), .text = "Disabled" };
|
|
3034
|
+
const disabled = Widget{ .id = 8, .kind = .row, .frame = geometry.RectF.init(0, 0, 0, 30), .hover_msgs = true, .state = .{ .disabled = true }, .children = &.{disabled_label} };
|
|
3035
|
+
const bystander = Widget{ .id = 9, .kind = .text, .frame = geometry.RectF.init(0, 0, 100, 20), .text = "Bystander" };
|
|
3036
|
+
|
|
3037
|
+
var nodes: [10]WidgetLayoutNode = undefined;
|
|
3038
|
+
const layout = try layoutWidgetTree(.{ .kind = .column, .layout = .{ .gap = 12 }, .children = &.{ card, disabled, bystander } }, geometry.RectF.init(0, 0, 320, 260), &nodes);
|
|
3039
|
+
|
|
3040
|
+
var chain: [8]ObjectId = undefined;
|
|
3041
|
+
|
|
3042
|
+
// Inside the row: both listeners, outermost first.
|
|
3043
|
+
const label_frame = layout.findById(6).?.frame.normalized();
|
|
3044
|
+
const in_row = layout.hoverMsgChainForHit(layout.hitTestHover(label_frame.center()), &chain);
|
|
3045
|
+
try std.testing.expectEqualSlices(ObjectId, &.{ 3, 5 }, in_row);
|
|
3046
|
+
|
|
3047
|
+
// Over the card's own content outside the row: the card alone.
|
|
3048
|
+
const plain_frame = layout.findById(4).?.frame.normalized();
|
|
3049
|
+
const in_card = layout.hoverMsgChainForHit(layout.hitTestHover(plain_frame.center()), &chain);
|
|
3050
|
+
try std.testing.expectEqualSlices(ObjectId, &.{3}, in_card);
|
|
3051
|
+
|
|
3052
|
+
// A disabled listener never joins a chain (the hit test skips it,
|
|
3053
|
+
// and the walk predicate refuses it either way).
|
|
3054
|
+
const disabled_frame = layout.findById(8).?.frame.normalized();
|
|
3055
|
+
const over_disabled = layout.hoverMsgChainForHit(layout.hitTestHover(disabled_frame.center()), &chain);
|
|
3056
|
+
try std.testing.expectEqualSlices(ObjectId, &.{}, over_disabled);
|
|
3057
|
+
|
|
3058
|
+
// A hit with no listening ancestor — and the null hit — both yield
|
|
3059
|
+
// the empty chain.
|
|
3060
|
+
const bystander_frame = layout.findById(9).?.frame.normalized();
|
|
3061
|
+
try std.testing.expectEqualSlices(ObjectId, &.{}, layout.hoverMsgChainForHit(layout.hitTestHover(bystander_frame.center()), &chain));
|
|
3062
|
+
try std.testing.expectEqualSlices(ObjectId, &.{}, layout.hoverMsgChainForHit(null, &chain));
|
|
3063
|
+
|
|
3064
|
+
// Listening keeps presses falling through: the row claims no press,
|
|
3065
|
+
// so a click inside it lands on nothing (dead space) — hover-msgs
|
|
3066
|
+
// flips where hover attributes, never where clicks land.
|
|
3067
|
+
const press = layout.hitTestHover(label_frame.center()).?;
|
|
3068
|
+
try std.testing.expect(canvas.widgetPressTargetForHit(layout, press) == null);
|
|
3069
|
+
|
|
3070
|
+
// And the INTERACTIVE hit test never sees hover-only listeners at
|
|
3071
|
+
// all: the raw hit over the row's plain area resolves exactly as it
|
|
3072
|
+
// would without the bindings (nothing here — layout containers),
|
|
3073
|
+
// so no wash can ever appear where none appeared before.
|
|
3074
|
+
const row_frame = layout.findById(5).?.frame.normalized();
|
|
3075
|
+
const wash_probe = geometry.PointF.init(row_frame.maxX() - 2, row_frame.center().y);
|
|
3076
|
+
try std.testing.expect(layout.hitTest(wash_probe) == null);
|
|
3077
|
+
try std.testing.expectEqualSlices(ObjectId, &.{ 3, 5 }, layout.hoverMsgChainForHit(layout.hitTestHover(wash_probe), &chain));
|
|
3078
|
+
}
|
|
3079
|
+
|
|
2931
3080
|
test "widget emitter renders list item and segmented control states" {
|
|
2932
3081
|
const tokens = DesignTokens{
|
|
2933
3082
|
.colors = .{
|