@native-sdk/cli 0.8.1 → 0.8.2
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/README.md +4 -4
- package/build.zig +49 -23
- package/package.json +10 -10
- package/packages/core/compile-surface/core.ts +16 -0
- package/packages/core/package-lock.json +2 -2
- package/packages/core/package.json +1 -1
- package/packages/core/sdk/core.d.ts +11 -0
- package/packages/core/sdk/core.ts +29 -2
- package/packages/core/sdk/events.d.ts +10 -0
- package/packages/core/sdk/events.ts +24 -4
- package/packages/core/src/checker.ts +1 -1
- package/packages/core/src/contract.ts +4 -1
- package/packages/core/src/devhost.ts +10 -1
- package/packages/core/src/diagnostics.ts +1 -1
- package/skill-data/core/SKILL.md +48 -20
- package/skill-data/core/references/app-model-runtime.md +2 -2
- package/skill-data/core/references/project-anatomy.md +22 -6
- package/skill-data/native-ui/SKILL.md +68 -27
- package/skill-data/ts-core/SKILL.md +13 -8
- package/skill-data/zig/SKILL.md +1 -1
- package/skills/native-sdk/SKILL.md +6 -5
- package/src/app_runner/ts_core_main.zig +2 -1
- package/src/embed/tests.zig +3 -1
- package/src/primitives/canvas/events.zig +8 -0
- package/src/primitives/canvas/root.zig +2 -0
- package/src/primitives/canvas/test_support.zig +1 -0
- package/src/primitives/canvas/ui.zig +53 -8
- package/src/primitives/canvas/ui_markup.zig +1 -0
- package/src/primitives/canvas/ui_markup_compiled.zig +32 -3
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +27 -0
- package/src/primitives/canvas/ui_markup_contract.zig +20 -3
- package/src/primitives/canvas/ui_markup_reflect.zig +41 -0
- package/src/primitives/canvas/ui_markup_view.zig +29 -3
- package/src/primitives/canvas/ui_markup_view_tests.zig +48 -1
- package/src/primitives/canvas/ui_schema.zig +5 -1
- package/src/primitives/canvas/ui_schema_tests.zig +3 -3
- package/src/primitives/canvas/ui_tests.zig +14 -0
- package/src/primitives/canvas/widget_access.zig +4 -3
- package/src/primitives/canvas/widget_invalidation.zig +11 -0
- package/src/primitives/canvas/widget_render.zig +81 -0
- package/src/primitives/canvas/widget_routing.zig +12 -7
- package/src/primitives/canvas/widget_runtime_tests.zig +132 -0
- package/src/primitives/canvas/widgets.zig +40 -0
- package/src/root.zig +1 -0
- package/src/runtime/automation_widget_dispatch.zig +19 -0
- package/src/runtime/canvas_limits.zig +5 -0
- package/src/runtime/canvas_widget_event_tests.zig +424 -8
- package/src/runtime/canvas_widget_events.zig +254 -7
- package/src/runtime/canvas_widget_state.zig +123 -1
- package/src/runtime/core.zig +6 -0
- package/src/runtime/effects.zig +27 -1
- package/src/runtime/effects_notification_tests.zig +65 -0
- package/src/runtime/gpu_surface_events.zig +60 -14
- package/src/runtime/tests.zig +1 -0
- package/src/runtime/ts_core_host.zig +16 -0
- package/src/runtime/ts_ui_app.zig +55 -2
- package/src/runtime/ui_app.zig +112 -0
- package/src/runtime/ui_app_tests.zig +356 -0
- package/src/runtime/view.zig +35 -0
- package/src/runtime/view_widget_tree.zig +12 -0
- package/tools/corewire/core_abi.zig +1 -0
- package/tools/corewire/emit.zig +55 -8
- package/tools/corewire/emit_facade.zig +63 -2
- package/tools/corewire/emit_profile.zig +4 -1
- package/tools/corewire/sidecar.zig +36 -6
|
@@ -2698,6 +2698,7 @@ test "runtime dispatches opted-in canvas widget drag events" {
|
|
|
2698
2698
|
raw_input_count: u32 = 0,
|
|
2699
2699
|
widget_pointer_count: u32 = 0,
|
|
2700
2700
|
widget_drag_count: u32 = 0,
|
|
2701
|
+
command_count: u32 = 0,
|
|
2701
2702
|
last_drag_source_id: canvas.ObjectId = 0,
|
|
2702
2703
|
last_drag_route_len: usize = 0,
|
|
2703
2704
|
last_drag_x: f32 = 0,
|
|
@@ -2713,6 +2714,7 @@ test "runtime dispatches opted-in canvas widget drag events" {
|
|
|
2713
2714
|
switch (event_value) {
|
|
2714
2715
|
.gpu_surface_input => self.raw_input_count += 1,
|
|
2715
2716
|
.canvas_widget_pointer => self.widget_pointer_count += 1,
|
|
2717
|
+
.command => self.command_count += 1,
|
|
2716
2718
|
.canvas_widget_drag => |drag_event| {
|
|
2717
2719
|
self.widget_drag_count += 1;
|
|
2718
2720
|
self.last_drag_source_id = if (drag_event.source) |source| source.id else 0;
|
|
@@ -2745,6 +2747,7 @@ test "runtime dispatches opted-in canvas widget drag events" {
|
|
|
2745
2747
|
.kind = .button,
|
|
2746
2748
|
.frame = geometry.RectF.init(12, 16, 96, 32),
|
|
2747
2749
|
.text = "Drag",
|
|
2750
|
+
.command = "drag.press",
|
|
2748
2751
|
.semantics = .{ .actions = .{ .drag = true } },
|
|
2749
2752
|
},
|
|
2750
2753
|
.{
|
|
@@ -2770,6 +2773,8 @@ test "runtime dispatches opted-in canvas widget drag events" {
|
|
|
2770
2773
|
try std.testing.expectEqual(@as(u32, 1), app_state.widget_pointer_count);
|
|
2771
2774
|
try std.testing.expectEqual(@as(u32, 1), app_state.raw_input_count);
|
|
2772
2775
|
|
|
2776
|
+
// A plain click on a draggable remains a press. It produces no terminal
|
|
2777
|
+
// drag and cannot leave a zero-origin landing armed for a later rebuild.
|
|
2773
2778
|
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
2774
2779
|
.window_id = 1,
|
|
2775
2780
|
.label = "canvas",
|
|
@@ -2777,27 +2782,433 @@ test "runtime dispatches opted-in canvas widget drag events" {
|
|
|
2777
2782
|
.x = 20,
|
|
2778
2783
|
.y = 28,
|
|
2779
2784
|
} });
|
|
2785
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
2786
|
+
.window_id = 1,
|
|
2787
|
+
.label = "canvas",
|
|
2788
|
+
.kind = .pointer_up,
|
|
2789
|
+
.x = 20,
|
|
2790
|
+
.y = 28,
|
|
2791
|
+
} });
|
|
2792
|
+
try std.testing.expectEqual(@as(u32, 1), app_state.command_count);
|
|
2793
|
+
try std.testing.expectEqual(@as(u32, 0), app_state.widget_drag_count);
|
|
2794
|
+
try std.testing.expect(!harness.runtime.views[0].canvas_widget_drag_layout_motion_armed);
|
|
2795
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_widget_drag_landing_source_id);
|
|
2796
|
+
|
|
2797
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
2798
|
+
.window_id = 1,
|
|
2799
|
+
.label = "canvas",
|
|
2800
|
+
.kind = .pointer_down,
|
|
2801
|
+
.x = 20,
|
|
2802
|
+
.y = 28,
|
|
2803
|
+
} });
|
|
2804
|
+
// Motion inside the slop stays observable to the low-level channel so it
|
|
2805
|
+
// owns text selection, but it activates no preview or landing state.
|
|
2780
2806
|
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
2781
2807
|
.window_id = 1,
|
|
2782
2808
|
.label = "canvas",
|
|
2783
2809
|
.kind = .pointer_drag,
|
|
2784
|
-
.x =
|
|
2810
|
+
.x = 24,
|
|
2785
2811
|
.y = 30,
|
|
2786
|
-
.delta_x = 44,
|
|
2787
2812
|
} });
|
|
2788
2813
|
try std.testing.expectEqual(@as(u32, 1), app_state.widget_drag_count);
|
|
2789
|
-
try std.testing.
|
|
2790
|
-
try std.testing.
|
|
2814
|
+
try std.testing.expect(harness.runtime.views[0].canvasWidgetRenderState().drag_preview_id == null);
|
|
2815
|
+
try std.testing.expect(!harness.runtime.views[0].canvas_widget_drag_layout_motion_armed);
|
|
2816
|
+
|
|
2817
|
+
try harness.runtime.dispatchPlatformEvent(app, .{
|
|
2818
|
+
.gpu_surface_input = .{
|
|
2819
|
+
.window_id = 1,
|
|
2820
|
+
.label = "canvas",
|
|
2821
|
+
.kind = .pointer_drag,
|
|
2822
|
+
.x = 64,
|
|
2823
|
+
.y = 30,
|
|
2824
|
+
// Physical hosts report per-event deltas (often zero); widget drag
|
|
2825
|
+
// displacement must come from the pointer-down origin instead.
|
|
2826
|
+
.delta_x = 0,
|
|
2827
|
+
.delta_y = 0,
|
|
2828
|
+
},
|
|
2829
|
+
});
|
|
2830
|
+
try std.testing.expectEqual(@as(u32, 2), app_state.widget_drag_count);
|
|
2831
|
+
try std.testing.expectEqual(@as(u32, 6), app_state.widget_pointer_count);
|
|
2832
|
+
try std.testing.expectEqual(@as(u32, 6), app_state.raw_input_count);
|
|
2791
2833
|
try std.testing.expectEqual(@as(canvas.ObjectId, 2), app_state.last_drag_source_id);
|
|
2792
2834
|
try std.testing.expectEqual(@as(usize, 3), app_state.last_drag_route_len);
|
|
2793
2835
|
try std.testing.expectEqual(@as(f32, 64), app_state.last_drag_x);
|
|
2794
2836
|
try std.testing.expectEqual(@as(f32, 44), app_state.last_drag_dx);
|
|
2837
|
+
const dragging_state = harness.runtime.views[0].canvasWidgetRenderState();
|
|
2838
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), dragging_state.drag_preview_id.?);
|
|
2839
|
+
try std.testing.expectEqual(@as(f32, 12), dragging_state.drag_preview_origin.?.x);
|
|
2840
|
+
try std.testing.expectEqual(@as(f32, 16), dragging_state.drag_preview_origin.?.y);
|
|
2841
|
+
try std.testing.expectEqual(@as(f32, 44), dragging_state.drag_preview_offset.dx);
|
|
2842
|
+
try std.testing.expectEqual(@as(f32, 2), dragging_state.drag_preview_offset.dy);
|
|
2843
|
+
|
|
2844
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
2845
|
+
.window_id = 1,
|
|
2846
|
+
.label = "canvas",
|
|
2847
|
+
.kind = .pointer_up,
|
|
2848
|
+
.x = 64,
|
|
2849
|
+
.y = 30,
|
|
2850
|
+
} });
|
|
2851
|
+
try std.testing.expectEqual(@as(u32, 3), app_state.widget_drag_count);
|
|
2852
|
+
// The captured release ended a real drag, so it cannot also activate the
|
|
2853
|
+
// source button's command/on_press path.
|
|
2854
|
+
try std.testing.expectEqual(@as(u32, 1), app_state.command_count);
|
|
2855
|
+
try std.testing.expect(harness.runtime.views[0].canvasWidgetRenderState().drag_preview_id == null);
|
|
2856
|
+
|
|
2857
|
+
// A drag-driven rebuild keeps truthful final layout geometry while the
|
|
2858
|
+
// moved keyed widget begins at its previously presented position and
|
|
2859
|
+
// springs to zero offset on recorded frame timestamps.
|
|
2860
|
+
const moved_children = [_]canvas.Widget{
|
|
2861
|
+
.{
|
|
2862
|
+
.id = 2,
|
|
2863
|
+
.kind = .button,
|
|
2864
|
+
.frame = geometry.RectF.init(12, 58, 96, 32),
|
|
2865
|
+
.text = "Drag",
|
|
2866
|
+
.semantics = .{ .actions = .{ .drag = true } },
|
|
2867
|
+
},
|
|
2868
|
+
children[1],
|
|
2869
|
+
};
|
|
2870
|
+
var moved_nodes: [4]canvas.WidgetLayoutNode = undefined;
|
|
2871
|
+
const moved_layout = try canvas.layoutWidgetTree(.{ .id = 1, .kind = .panel, .children = &moved_children }, geometry.RectF.init(0, 0, 240, 120), &moved_nodes);
|
|
2872
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", moved_layout);
|
|
2873
|
+
var motion_state = harness.runtime.views[0].canvasWidgetRenderState();
|
|
2874
|
+
try std.testing.expectEqual(@as(usize, 1), motion_state.layout_motions.len);
|
|
2875
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), motion_state.layout_motions[0].id);
|
|
2876
|
+
try std.testing.expectEqual(@as(f32, 44), motion_state.layout_motions[0].offset.dx);
|
|
2877
|
+
try std.testing.expectEqual(@as(f32, -40), motion_state.layout_motions[0].offset.dy);
|
|
2878
|
+
try harness.runtime.advanceCanvasWidgetDragLayoutMotionForFrame(0, 1_000_000_000);
|
|
2879
|
+
motion_state = harness.runtime.views[0].canvasWidgetRenderState();
|
|
2880
|
+
try std.testing.expectEqual(@as(f32, 44), motion_state.layout_motions[0].offset.dx);
|
|
2881
|
+
try std.testing.expectEqual(@as(f32, -40), motion_state.layout_motions[0].offset.dy);
|
|
2882
|
+
try harness.runtime.advanceCanvasWidgetDragLayoutMotionForFrame(0, 1_100_000_000);
|
|
2883
|
+
motion_state = harness.runtime.views[0].canvasWidgetRenderState();
|
|
2884
|
+
try std.testing.expect(@abs(motion_state.layout_motions[0].offset.dy) < 40);
|
|
2885
|
+
try harness.runtime.advanceCanvasWidgetDragLayoutMotionForFrame(0, 2_000_000_000);
|
|
2886
|
+
try std.testing.expectEqual(@as(usize, 0), harness.runtime.views[0].canvasWidgetRenderState().layout_motions.len);
|
|
2795
2887
|
|
|
2796
2888
|
const snapshot = harness.runtime.automationSnapshot("Widgets");
|
|
2797
2889
|
try std.testing.expect(snapshot.widgets[1].actions.drag);
|
|
2798
2890
|
try std.testing.expect(!snapshot.widgets[2].actions.drag);
|
|
2799
2891
|
}
|
|
2800
2892
|
|
|
2893
|
+
test "drag routing preserves a nested pointer route until pointer dispatch" {
|
|
2894
|
+
const TestApp = struct {
|
|
2895
|
+
pointer_target_id: canvas.ObjectId = 0,
|
|
2896
|
+
drag_source_id: canvas.ObjectId = 0,
|
|
2897
|
+
pointer_route: [5]canvas.WidgetEventRouteEntry = undefined,
|
|
2898
|
+
pointer_route_len: usize = 0,
|
|
2899
|
+
|
|
2900
|
+
fn app(self: *@This()) App {
|
|
2901
|
+
return .{ .context = self, .name = "gpu-widget-drag-routes", .source = platform.WebViewSource.html("<h1>GPU</h1>"), .event_fn = event };
|
|
2902
|
+
}
|
|
2903
|
+
|
|
2904
|
+
fn event(context: *anyopaque, runtime: *Runtime, event_value: Event) anyerror!void {
|
|
2905
|
+
_ = runtime;
|
|
2906
|
+
const self: *@This() = @ptrCast(@alignCast(context));
|
|
2907
|
+
switch (event_value) {
|
|
2908
|
+
.canvas_widget_pointer => |pointer_event| {
|
|
2909
|
+
if (pointer_event.pointer.phase != .move) return;
|
|
2910
|
+
self.pointer_target_id = if (pointer_event.target) |target| target.id else 0;
|
|
2911
|
+
self.pointer_route_len = @min(pointer_event.route.len, self.pointer_route.len);
|
|
2912
|
+
@memcpy(self.pointer_route[0..self.pointer_route_len], pointer_event.route[0..self.pointer_route_len]);
|
|
2913
|
+
},
|
|
2914
|
+
.canvas_widget_drag => |drag_event| {
|
|
2915
|
+
self.drag_source_id = if (drag_event.source) |source| source.id else 0;
|
|
2916
|
+
},
|
|
2917
|
+
else => {},
|
|
2918
|
+
}
|
|
2919
|
+
}
|
|
2920
|
+
};
|
|
2921
|
+
|
|
2922
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
2923
|
+
defer harness.destroy(std.testing.allocator);
|
|
2924
|
+
harness.null_platform.gpu_surfaces = true;
|
|
2925
|
+
var app_state: TestApp = .{};
|
|
2926
|
+
const app = app_state.app();
|
|
2927
|
+
try harness.start(app);
|
|
2928
|
+
|
|
2929
|
+
_ = try harness.runtime.createView(.{
|
|
2930
|
+
.window_id = 1,
|
|
2931
|
+
.label = "canvas",
|
|
2932
|
+
.kind = .gpu_surface,
|
|
2933
|
+
.frame = geometry.RectF.init(0, 0, 240, 120),
|
|
2934
|
+
});
|
|
2935
|
+
|
|
2936
|
+
const label = canvas.Widget{
|
|
2937
|
+
.id = 3,
|
|
2938
|
+
.kind = .text,
|
|
2939
|
+
.frame = geometry.RectF.init(0, 0, 80, 20),
|
|
2940
|
+
.text = "Drag label",
|
|
2941
|
+
};
|
|
2942
|
+
const source = canvas.Widget{
|
|
2943
|
+
.id = 2,
|
|
2944
|
+
.kind = .row,
|
|
2945
|
+
.frame = geometry.RectF.init(0, 0, 0, 40),
|
|
2946
|
+
.layout = .{ .padding = geometry.InsetsF.all(8) },
|
|
2947
|
+
.semantics = .{ .actions = .{ .drag = true } },
|
|
2948
|
+
.children = &.{label},
|
|
2949
|
+
};
|
|
2950
|
+
var nodes: [3]canvas.WidgetLayoutNode = undefined;
|
|
2951
|
+
const layout = try canvas.layoutWidgetTree(
|
|
2952
|
+
.{ .id = 1, .kind = .panel, .children = &.{source} },
|
|
2953
|
+
geometry.RectF.init(0, 0, 240, 120),
|
|
2954
|
+
&nodes,
|
|
2955
|
+
);
|
|
2956
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
2957
|
+
const point = (try harness.runtime.canvasWidgetLayout(1, "canvas")).findById(3).?.frame.normalized().center();
|
|
2958
|
+
|
|
2959
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
2960
|
+
.window_id = 1,
|
|
2961
|
+
.label = "canvas",
|
|
2962
|
+
.kind = .pointer_down,
|
|
2963
|
+
.x = point.x,
|
|
2964
|
+
.y = point.y,
|
|
2965
|
+
} });
|
|
2966
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
2967
|
+
.window_id = 1,
|
|
2968
|
+
.label = "canvas",
|
|
2969
|
+
.kind = .pointer_drag,
|
|
2970
|
+
.x = point.x + 12,
|
|
2971
|
+
.y = point.y,
|
|
2972
|
+
} });
|
|
2973
|
+
|
|
2974
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 3), app_state.pointer_target_id);
|
|
2975
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), app_state.drag_source_id);
|
|
2976
|
+
try std.testing.expectEqual(@as(usize, 5), app_state.pointer_route_len);
|
|
2977
|
+
try std.testing.expectEqual(canvas.WidgetEventPhase.capture, app_state.pointer_route[0].phase);
|
|
2978
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 1), app_state.pointer_route[0].id);
|
|
2979
|
+
try std.testing.expectEqual(canvas.WidgetEventPhase.capture, app_state.pointer_route[1].phase);
|
|
2980
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), app_state.pointer_route[1].id);
|
|
2981
|
+
try std.testing.expectEqual(canvas.WidgetEventPhase.target, app_state.pointer_route[2].phase);
|
|
2982
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 3), app_state.pointer_route[2].id);
|
|
2983
|
+
try std.testing.expectEqual(canvas.WidgetEventPhase.bubble, app_state.pointer_route[3].phase);
|
|
2984
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), app_state.pointer_route[3].id);
|
|
2985
|
+
try std.testing.expectEqual(canvas.WidgetEventPhase.bubble, app_state.pointer_route[4].phase);
|
|
2986
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 1), app_state.pointer_route[4].id);
|
|
2987
|
+
}
|
|
2988
|
+
|
|
2989
|
+
test "unmounted drag source still dispatches one captured cancel" {
|
|
2990
|
+
const TestApp = struct {
|
|
2991
|
+
widget_drag_count: u32 = 0,
|
|
2992
|
+
last_drag_phase: canvas.WidgetDragPhase = .change,
|
|
2993
|
+
last_drag_source_id: canvas.ObjectId = 0,
|
|
2994
|
+
last_drag_route_len: usize = 0,
|
|
2995
|
+
source_unmounted: bool = false,
|
|
2996
|
+
|
|
2997
|
+
fn app(self: *@This()) App {
|
|
2998
|
+
return .{ .context = self, .name = "gpu-widget-drag-unmount", .source = platform.WebViewSource.html("<h1>GPU</h1>"), .event_fn = event };
|
|
2999
|
+
}
|
|
3000
|
+
|
|
3001
|
+
fn event(context: *anyopaque, runtime: *Runtime, event_value: Event) anyerror!void {
|
|
3002
|
+
const self: *@This() = @ptrCast(@alignCast(context));
|
|
3003
|
+
switch (event_value) {
|
|
3004
|
+
.canvas_widget_drag => |drag_event| {
|
|
3005
|
+
self.widget_drag_count += 1;
|
|
3006
|
+
self.last_drag_phase = drag_event.drag.phase;
|
|
3007
|
+
self.last_drag_source_id = if (drag_event.source) |source| source.id else 0;
|
|
3008
|
+
self.last_drag_route_len = drag_event.route.len;
|
|
3009
|
+
if (drag_event.drag.phase == .change and !self.source_unmounted) {
|
|
3010
|
+
self.source_unmounted = true;
|
|
3011
|
+
var empty_nodes: [1]canvas.WidgetLayoutNode = undefined;
|
|
3012
|
+
const empty_layout = try canvas.layoutWidgetTree(
|
|
3013
|
+
.{ .id = 1, .kind = .panel },
|
|
3014
|
+
geometry.RectF.init(0, 0, 240, 120),
|
|
3015
|
+
&empty_nodes,
|
|
3016
|
+
);
|
|
3017
|
+
_ = try runtime.setCanvasWidgetLayout(1, "canvas", empty_layout);
|
|
3018
|
+
}
|
|
3019
|
+
},
|
|
3020
|
+
else => {},
|
|
3021
|
+
}
|
|
3022
|
+
}
|
|
3023
|
+
};
|
|
3024
|
+
|
|
3025
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
3026
|
+
defer harness.destroy(std.testing.allocator);
|
|
3027
|
+
harness.null_platform.gpu_surfaces = true;
|
|
3028
|
+
var app_state: TestApp = .{};
|
|
3029
|
+
const app = app_state.app();
|
|
3030
|
+
try harness.start(app);
|
|
3031
|
+
|
|
3032
|
+
_ = try harness.runtime.createView(.{
|
|
3033
|
+
.window_id = 1,
|
|
3034
|
+
.label = "canvas",
|
|
3035
|
+
.kind = .gpu_surface,
|
|
3036
|
+
.frame = geometry.RectF.init(0, 0, 240, 120),
|
|
3037
|
+
});
|
|
3038
|
+
const children = [_]canvas.Widget{.{
|
|
3039
|
+
.id = 2,
|
|
3040
|
+
.kind = .button,
|
|
3041
|
+
.frame = geometry.RectF.init(12, 16, 96, 32),
|
|
3042
|
+
.text = "Drag",
|
|
3043
|
+
.semantics = .{ .actions = .{ .drag = true } },
|
|
3044
|
+
}};
|
|
3045
|
+
var nodes: [2]canvas.WidgetLayoutNode = undefined;
|
|
3046
|
+
const layout = try canvas.layoutWidgetTree(.{ .id = 1, .kind = .panel, .children = &children }, geometry.RectF.init(0, 0, 240, 120), &nodes);
|
|
3047
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
3048
|
+
|
|
3049
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
3050
|
+
.window_id = 1,
|
|
3051
|
+
.label = "canvas",
|
|
3052
|
+
.kind = .pointer_down,
|
|
3053
|
+
.x = 20,
|
|
3054
|
+
.y = 28,
|
|
3055
|
+
} });
|
|
3056
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
3057
|
+
.window_id = 1,
|
|
3058
|
+
.label = "canvas",
|
|
3059
|
+
.kind = .pointer_drag,
|
|
3060
|
+
.x = 64,
|
|
3061
|
+
.y = 30,
|
|
3062
|
+
} });
|
|
3063
|
+
try std.testing.expectEqual(@as(u32, 1), app_state.widget_drag_count);
|
|
3064
|
+
try std.testing.expectEqual(canvas.WidgetDragPhase.change, app_state.last_drag_phase);
|
|
3065
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), harness.runtime.views[0].canvas_widget_drag_source_id);
|
|
3066
|
+
try std.testing.expect(!harness.runtime.views[0].canvas_widget_drag_source_attached);
|
|
3067
|
+
try std.testing.expect(harness.runtime.views[0].canvasWidgetRenderState().drag_preview_id == null);
|
|
3068
|
+
|
|
3069
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
3070
|
+
.window_id = 1,
|
|
3071
|
+
.label = "canvas",
|
|
3072
|
+
.kind = .pointer_up,
|
|
3073
|
+
.x = 70,
|
|
3074
|
+
.y = 32,
|
|
3075
|
+
} });
|
|
3076
|
+
try std.testing.expectEqual(@as(u32, 2), app_state.widget_drag_count);
|
|
3077
|
+
try std.testing.expectEqual(canvas.WidgetDragPhase.cancel, app_state.last_drag_phase);
|
|
3078
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), app_state.last_drag_source_id);
|
|
3079
|
+
try std.testing.expectEqual(@as(usize, 3), app_state.last_drag_route_len);
|
|
3080
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_widget_drag_source_id);
|
|
3081
|
+
try std.testing.expectEqual(@as(u64, 0), harness.runtime.views[0].canvas_widget_drag_pointer_id);
|
|
3082
|
+
|
|
3083
|
+
// The physical sequence is retired with the synthesized cancellation;
|
|
3084
|
+
// another terminal edge cannot deliver the captured route twice.
|
|
3085
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
3086
|
+
.window_id = 1,
|
|
3087
|
+
.label = "canvas",
|
|
3088
|
+
.kind = .pointer_cancel,
|
|
3089
|
+
.x = 70,
|
|
3090
|
+
.y = 32,
|
|
3091
|
+
} });
|
|
3092
|
+
try std.testing.expectEqual(@as(u32, 2), app_state.widget_drag_count);
|
|
3093
|
+
}
|
|
3094
|
+
|
|
3095
|
+
test "plain escape cancels an active canvas widget drag and release cannot revive it" {
|
|
3096
|
+
const TestApp = struct {
|
|
3097
|
+
widget_drag_count: u32 = 0,
|
|
3098
|
+
widget_keyboard_count: u32 = 0,
|
|
3099
|
+
last_drag_phase: canvas.WidgetDragPhase = .change,
|
|
3100
|
+
last_drag_point: geometry.PointF = .{},
|
|
3101
|
+
last_drag_delta: geometry.OffsetF = .{},
|
|
3102
|
+
|
|
3103
|
+
fn app(self: *@This()) App {
|
|
3104
|
+
return .{ .context = self, .name = "gpu-widget-drag-escape", .source = platform.WebViewSource.html("<h1>GPU</h1>"), .event_fn = event };
|
|
3105
|
+
}
|
|
3106
|
+
|
|
3107
|
+
fn event(context: *anyopaque, runtime: *Runtime, event_value: Event) anyerror!void {
|
|
3108
|
+
_ = runtime;
|
|
3109
|
+
const self: *@This() = @ptrCast(@alignCast(context));
|
|
3110
|
+
switch (event_value) {
|
|
3111
|
+
.canvas_widget_drag => |drag_event| {
|
|
3112
|
+
self.widget_drag_count += 1;
|
|
3113
|
+
self.last_drag_phase = drag_event.drag.phase;
|
|
3114
|
+
self.last_drag_point = drag_event.drag.point;
|
|
3115
|
+
self.last_drag_delta = drag_event.drag.delta;
|
|
3116
|
+
},
|
|
3117
|
+
.canvas_widget_keyboard => self.widget_keyboard_count += 1,
|
|
3118
|
+
else => {},
|
|
3119
|
+
}
|
|
3120
|
+
}
|
|
3121
|
+
};
|
|
3122
|
+
|
|
3123
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
3124
|
+
defer harness.destroy(std.testing.allocator);
|
|
3125
|
+
harness.null_platform.gpu_surfaces = true;
|
|
3126
|
+
var app_state: TestApp = .{};
|
|
3127
|
+
const app = app_state.app();
|
|
3128
|
+
try harness.start(app);
|
|
3129
|
+
|
|
3130
|
+
_ = try harness.runtime.createView(.{
|
|
3131
|
+
.window_id = 1,
|
|
3132
|
+
.label = "canvas",
|
|
3133
|
+
.kind = .gpu_surface,
|
|
3134
|
+
.frame = geometry.RectF.init(0, 0, 240, 120),
|
|
3135
|
+
});
|
|
3136
|
+
|
|
3137
|
+
const children = [_]canvas.Widget{.{
|
|
3138
|
+
.id = 2,
|
|
3139
|
+
.kind = .button,
|
|
3140
|
+
.frame = geometry.RectF.init(12, 16, 96, 32),
|
|
3141
|
+
.text = "Drag",
|
|
3142
|
+
.semantics = .{ .actions = .{ .drag = true } },
|
|
3143
|
+
}};
|
|
3144
|
+
var nodes: [2]canvas.WidgetLayoutNode = undefined;
|
|
3145
|
+
const layout = try canvas.layoutWidgetTree(.{ .id = 1, .kind = .panel, .children = &children }, geometry.RectF.init(0, 0, 240, 120), &nodes);
|
|
3146
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
3147
|
+
|
|
3148
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
3149
|
+
.window_id = 1,
|
|
3150
|
+
.label = "canvas",
|
|
3151
|
+
.kind = .pointer_down,
|
|
3152
|
+
.x = 20,
|
|
3153
|
+
.y = 28,
|
|
3154
|
+
} });
|
|
3155
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
3156
|
+
.window_id = 1,
|
|
3157
|
+
.label = "canvas",
|
|
3158
|
+
.kind = .pointer_drag,
|
|
3159
|
+
.x = 64,
|
|
3160
|
+
.y = 30,
|
|
3161
|
+
.delta_x = 44,
|
|
3162
|
+
.delta_y = 2,
|
|
3163
|
+
} });
|
|
3164
|
+
try std.testing.expectEqual(@as(u32, 1), app_state.widget_drag_count);
|
|
3165
|
+
try std.testing.expectEqual(canvas.WidgetDragPhase.change, app_state.last_drag_phase);
|
|
3166
|
+
|
|
3167
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
3168
|
+
.window_id = 1,
|
|
3169
|
+
.label = "canvas",
|
|
3170
|
+
.kind = .key_down,
|
|
3171
|
+
.key = "escape",
|
|
3172
|
+
} });
|
|
3173
|
+
try std.testing.expectEqual(@as(u32, 2), app_state.widget_drag_count);
|
|
3174
|
+
try std.testing.expectEqual(@as(u32, 0), app_state.widget_keyboard_count);
|
|
3175
|
+
try std.testing.expectEqual(canvas.WidgetDragPhase.cancel, app_state.last_drag_phase);
|
|
3176
|
+
try std.testing.expectEqualDeep(geometry.PointF.init(64, 30), app_state.last_drag_point);
|
|
3177
|
+
try std.testing.expectEqualDeep(geometry.OffsetF.init(44, 2), app_state.last_drag_delta);
|
|
3178
|
+
const cancelled_state = harness.runtime.views[0].canvasWidgetRenderState();
|
|
3179
|
+
try std.testing.expect(cancelled_state.drag_preview_id == null);
|
|
3180
|
+
try std.testing.expect(cancelled_state.pressed_id == null);
|
|
3181
|
+
|
|
3182
|
+
// The app's phase-2 rebuild restores the original keyed slot. Its
|
|
3183
|
+
// presentation begins exactly where the opaque floating card was when
|
|
3184
|
+
// Escape landed, then eases back to the source frame.
|
|
3185
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
3186
|
+
const landing_state = harness.runtime.views[0].canvasWidgetRenderState();
|
|
3187
|
+
try std.testing.expectEqual(@as(usize, 1), landing_state.layout_motions.len);
|
|
3188
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), landing_state.layout_motions[0].id);
|
|
3189
|
+
try std.testing.expectEqualDeep(geometry.OffsetF.init(44, 2), landing_state.layout_motions[0].offset);
|
|
3190
|
+
|
|
3191
|
+
// The still-held physical pointer no longer owns a press. Its remaining
|
|
3192
|
+
// motion and release cannot restart or commit the cancelled drag.
|
|
3193
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
3194
|
+
.window_id = 1,
|
|
3195
|
+
.label = "canvas",
|
|
3196
|
+
.kind = .pointer_drag,
|
|
3197
|
+
.x = 72,
|
|
3198
|
+
.y = 34,
|
|
3199
|
+
.delta_x = 52,
|
|
3200
|
+
.delta_y = 6,
|
|
3201
|
+
} });
|
|
3202
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
3203
|
+
.window_id = 1,
|
|
3204
|
+
.label = "canvas",
|
|
3205
|
+
.kind = .pointer_up,
|
|
3206
|
+
.x = 72,
|
|
3207
|
+
.y = 34,
|
|
3208
|
+
} });
|
|
3209
|
+
try std.testing.expectEqual(@as(u32, 2), app_state.widget_drag_count);
|
|
3210
|
+
}
|
|
3211
|
+
|
|
2801
3212
|
test "runtime resizes retained canvas resizable widgets from pointer drag" {
|
|
2802
3213
|
const TestApp = struct {
|
|
2803
3214
|
fn app(self: *@This()) App {
|
|
@@ -2830,6 +3241,7 @@ test "runtime resizes retained canvas resizable widgets from pointer drag" {
|
|
|
2830
3241
|
const layout = try canvas.layoutWidgetTree(.{ .id = 1, .kind = .stack, .children = &.{resizable} }, geometry.RectF.init(0, 0, 260, 120), &nodes);
|
|
2831
3242
|
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
2832
3243
|
_ = try harness.runtime.emitCanvasWidgetDisplayList(1, "canvas", .{});
|
|
3244
|
+
const baseline_command_count = (try harness.runtime.canvasDisplayList(1, "canvas")).commandCount();
|
|
2833
3245
|
|
|
2834
3246
|
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
2835
3247
|
.window_id = 1,
|
|
@@ -2852,6 +3264,9 @@ test "runtime resizes retained canvas resizable widgets from pointer drag" {
|
|
|
2852
3264
|
try std.testing.expectEqualDeep(geometry.RectF.init(10, 16, 150, 44), retained.findById(2).?.widget.frame);
|
|
2853
3265
|
|
|
2854
3266
|
var display_list = try harness.runtime.canvasDisplayList(1, "canvas");
|
|
3267
|
+
// Built-in resize semantics mutate retained geometry in place; they do
|
|
3268
|
+
// not also paint the generic translated drag preview.
|
|
3269
|
+
try std.testing.expectEqual(baseline_command_count, display_list.commandCount());
|
|
2855
3270
|
switch (display_list.findCommandById(testCanvasWidgetPartId(2, 5)).?.command) {
|
|
2856
3271
|
.draw_line => |line| try std.testing.expect(line.from.x > 152),
|
|
2857
3272
|
else => return error.TestUnexpectedResult,
|
|
@@ -2991,12 +3406,13 @@ test "runtime dispatches automation canvas widget actions" {
|
|
|
2991
3406
|
try std.testing.expectEqualStrings("enter", app_state.last_keyboard_key);
|
|
2992
3407
|
|
|
2993
3408
|
try dispatchAutomationWidgetAction(&harness.runtime, app, .{ .view_label = "canvas", .id = 2, .action = .drag, .value = "18 2" });
|
|
2994
|
-
|
|
3409
|
+
// Automation completes the gesture with the release event too.
|
|
3410
|
+
try std.testing.expectEqual(@as(u32, 2), app_state.widget_drag_count);
|
|
2995
3411
|
try std.testing.expectEqual(@as(canvas.ObjectId, 2), app_state.last_drag_source_id);
|
|
2996
3412
|
try std.testing.expectEqual(@as(f32, 18), app_state.last_drag_dx);
|
|
2997
3413
|
|
|
2998
3414
|
_ = try harness.runtime.dispatchCanvasWidgetAccessibilityAction(app, 1, "canvas", .{ .id = 2, .action = .drag, .text = "8 1" });
|
|
2999
|
-
try std.testing.expectEqual(@as(u32,
|
|
3415
|
+
try std.testing.expectEqual(@as(u32, 4), app_state.widget_drag_count);
|
|
3000
3416
|
try std.testing.expectEqual(@as(canvas.ObjectId, 2), app_state.last_drag_source_id);
|
|
3001
3417
|
try std.testing.expectEqual(@as(f32, 8), app_state.last_drag_dx);
|
|
3002
3418
|
|
|
@@ -3006,7 +3422,7 @@ test "runtime dispatches automation canvas widget actions" {
|
|
|
3006
3422
|
.id = 2,
|
|
3007
3423
|
.action = .drag,
|
|
3008
3424
|
} });
|
|
3009
|
-
try std.testing.expectEqual(@as(u32,
|
|
3425
|
+
try std.testing.expectEqual(@as(u32, 6), app_state.widget_drag_count);
|
|
3010
3426
|
try std.testing.expectEqual(@as(canvas.ObjectId, 2), app_state.last_drag_source_id);
|
|
3011
3427
|
try std.testing.expectEqual(@as(f32, 16), app_state.last_drag_dx);
|
|
3012
3428
|
|
|
@@ -3299,7 +3715,7 @@ test "runtime rejects automation canvas widget actions for scroll clipped target
|
|
|
3299
3715
|
try std.testing.expectEqual(@as(u32, 0), app_state.raw_input_count);
|
|
3300
3716
|
|
|
3301
3717
|
try dispatchAutomationWidgetAction(&harness.runtime, app, .{ .view_label = "canvas", .id = 3, .action = .drag, .value = "8 0" });
|
|
3302
|
-
try std.testing.expectEqual(@as(u32,
|
|
3718
|
+
try std.testing.expectEqual(@as(u32, 2), app_state.widget_drag_count);
|
|
3303
3719
|
try std.testing.expectEqual(@as(canvas.ObjectId, 3), app_state.last_drag_source_id);
|
|
3304
3720
|
|
|
3305
3721
|
const drop_children = [_]canvas.Widget{
|