@native-sdk/cli 0.9.1 → 0.9.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.
Files changed (130) hide show
  1. package/build/app.zig +26 -9
  2. package/build.zig +55 -0
  3. package/package.json +9 -9
  4. package/packages/core/package-lock.json +2 -2
  5. package/packages/core/package.json +1 -1
  6. package/packages/core/sdk/core.ts +3 -1
  7. package/skill-data/native-ui/SKILL.md +7 -7
  8. package/skill-data/ts-core/SKILL.md +1 -1
  9. package/src/app_runner/root.zig +93 -6
  10. package/src/app_runner/ts_core_main.zig +4 -4
  11. package/src/app_runner/window_placement.zig +63 -0
  12. package/src/embed/app_exports.zig +2 -1
  13. package/src/embed/conversions.zig +1 -0
  14. package/src/embed/host.zig +10 -3
  15. package/src/embed/root.zig +1 -0
  16. package/src/embed/tests.zig +13 -1
  17. package/src/embed/types.zig +2 -0
  18. package/src/embed/ui_host.zig +26 -2
  19. package/src/platform/android/NativeSdkActivity.java +49 -4
  20. package/src/platform/android/android_host.c +3 -3
  21. package/src/platform/android/native_sdk_app.h +1 -1
  22. package/src/platform/ios/apple_image_fit.h +38 -0
  23. package/src/platform/ios/files.zig +1 -0
  24. package/src/platform/ios/native_sdk_app.h +1 -1
  25. package/src/platform/ios/uikit_host.m +28 -5
  26. package/src/platform/linux/cef_host.cpp +10 -2
  27. package/src/platform/linux/gtk_host.c +43 -10
  28. package/src/platform/linux/gtk_host.h +3 -3
  29. package/src/platform/linux/root.zig +22 -7
  30. package/src/platform/macos/appkit_host.h +7 -4
  31. package/src/platform/macos/appkit_host.m +192 -40
  32. package/src/platform/macos/cef_host.mm +132 -34
  33. package/src/platform/macos/image_fit_test.m +44 -0
  34. package/src/platform/macos/root.zig +154 -9
  35. package/src/platform/null_platform.zig +17 -3
  36. package/src/platform/null_platform_tests.zig +58 -4
  37. package/src/platform/root.zig +2 -0
  38. package/src/platform/types.zig +69 -19
  39. package/src/platform/windows/root.zig +22 -7
  40. package/src/platform/windows/webview2_host.cpp +31 -6
  41. package/src/primitives/app_manifest/root.zig +3 -0
  42. package/src/primitives/app_manifest/tests.zig +24 -0
  43. package/src/primitives/app_manifest/types.zig +13 -0
  44. package/src/primitives/app_manifest/validation.zig +24 -0
  45. package/src/primitives/canvas/a11y_audit.zig +9 -7
  46. package/src/primitives/canvas/a11y_audit_tests.zig +24 -0
  47. package/src/primitives/canvas/events.zig +50 -0
  48. package/src/primitives/canvas/layout_audit.zig +6 -6
  49. package/src/primitives/canvas/markdown.zig +4 -0
  50. package/src/primitives/canvas/markdown_tests.zig +1 -0
  51. package/src/primitives/canvas/png.zig +138 -0
  52. package/src/primitives/canvas/root.zig +13 -2
  53. package/src/primitives/canvas/text_span_tests.zig +5 -3
  54. package/src/primitives/canvas/text_spans.zig +2 -0
  55. package/src/primitives/canvas/text_tests.zig +20 -0
  56. package/src/primitives/canvas/ui.zig +55 -2
  57. package/src/primitives/canvas/ui_markup.zig +40 -13
  58. package/src/primitives/canvas/ui_markup_binary.zig +8 -6
  59. package/src/primitives/canvas/ui_markup_binary_tests.zig +14 -4
  60. package/src/primitives/canvas/ui_markup_compiled.zig +5 -1
  61. package/src/primitives/canvas/ui_markup_compiled_tests.zig +52 -0
  62. package/src/primitives/canvas/ui_markup_tests.zig +11 -2
  63. package/src/primitives/canvas/ui_markup_view.zig +8 -2
  64. package/src/primitives/canvas/ui_markup_view_tests.zig +49 -4
  65. package/src/primitives/canvas/ui_schema.zig +17 -13
  66. package/src/primitives/canvas/ui_tests.zig +47 -0
  67. package/src/primitives/canvas/widget_access.zig +3 -3
  68. package/src/primitives/canvas/widget_anchored_tests.zig +106 -0
  69. package/src/primitives/canvas/widget_builtin_tests.zig +580 -32
  70. package/src/primitives/canvas/widget_invalidation.zig +33 -6
  71. package/src/primitives/canvas/widget_layout.zig +333 -126
  72. package/src/primitives/canvas/widget_layout_tests.zig +169 -0
  73. package/src/primitives/canvas/widget_metrics.zig +7 -8
  74. package/src/primitives/canvas/widget_render.zig +76 -44
  75. package/src/primitives/canvas/widget_render_controls.zig +110 -32
  76. package/src/primitives/canvas/widget_render_style.zig +58 -18
  77. package/src/primitives/canvas/widget_render_surfaces.zig +45 -14
  78. package/src/primitives/canvas/widget_routing.zig +40 -34
  79. package/src/primitives/canvas/widget_runtime.zig +11 -2
  80. package/src/primitives/canvas/widget_runtime_tests.zig +10 -14
  81. package/src/primitives/canvas/widget_semantics.zig +8 -3
  82. package/src/primitives/canvas/widget_semantics_tests.zig +6 -2
  83. package/src/primitives/canvas/widget_tree.zig +99 -5
  84. package/src/primitives/canvas/widgets.zig +20 -7
  85. package/src/root.zig +3 -0
  86. package/src/runtime/api.zig +6 -0
  87. package/src/runtime/automation_widget_dispatch.zig +48 -6
  88. package/src/runtime/builtin_bridge.zig +5 -2
  89. package/src/runtime/canvas_frame_packet_tests.zig +22 -13
  90. package/src/runtime/canvas_image_tests.zig +146 -2
  91. package/src/runtime/canvas_images.zig +35 -16
  92. package/src/runtime/canvas_limits.zig +13 -3
  93. package/src/runtime/canvas_widget_accessibility_tests.zig +279 -4
  94. package/src/runtime/canvas_widget_anchored_tests.zig +54 -0
  95. package/src/runtime/canvas_widget_control_tests.zig +31 -1
  96. package/src/runtime/canvas_widget_events.zig +151 -26
  97. package/src/runtime/canvas_widget_floating_tests.zig +48 -0
  98. package/src/runtime/canvas_widget_runtime.zig +322 -102
  99. package/src/runtime/canvas_widget_scroll_driver_tests.zig +34 -0
  100. package/src/runtime/canvas_widget_scroll_drivers.zig +12 -10
  101. package/src/runtime/canvas_widget_scroll_tests.zig +193 -2
  102. package/src/runtime/canvas_widget_semantics_tests.zig +337 -3
  103. package/src/runtime/canvas_widget_split_tree_tests.zig +55 -0
  104. package/src/runtime/canvas_widget_state.zig +33 -7
  105. package/src/runtime/core.zig +16 -0
  106. package/src/runtime/effects.zig +14 -14
  107. package/src/runtime/effects_image_tests.zig +91 -0
  108. package/src/runtime/gpu_surface_events.zig +25 -2
  109. package/src/runtime/root.zig +2 -0
  110. package/src/runtime/session_replay.zig +13 -8
  111. package/src/runtime/session_tests.zig +111 -4
  112. package/src/runtime/shell_layout_tests.zig +12 -0
  113. package/src/runtime/ts_core_host_tests.zig +47 -0
  114. package/src/runtime/ui_app.zig +9 -3
  115. package/src/runtime/ui_app_tests.zig +119 -19
  116. package/src/runtime/ui_app_window_tests.zig +13 -1
  117. package/src/runtime/view.zig +3 -0
  118. package/src/runtime/view_widget_control.zig +18 -0
  119. package/src/runtime/view_widget_scroll.zig +112 -18
  120. package/src/runtime/view_widget_tree.zig +110 -13
  121. package/src/runtime/widget_bridge.zig +2 -0
  122. package/src/runtime/window_command_bridge_tests.zig +86 -0
  123. package/src/runtime/window_storage.zig +16 -1
  124. package/src/runtime/window_views.zig +1 -0
  125. package/src/tooling/ios.zig +3 -0
  126. package/src/tooling/manifest.zig +90 -2
  127. package/src/tooling/package.zig +67 -2
  128. package/src/tooling/raw_manifest.zig +10 -0
  129. package/src/tooling/templates.zig +128 -18
  130. package/src/tooling/web_engine.zig +1 -1
@@ -663,8 +663,32 @@ test "runtime moves focused grouped canvas controls with arrow keys" {
663
663
 
664
664
  test "runtime moves focus within house grouped component controls" {
665
665
  const TestApp = struct {
666
+ radio_group_navigation: bool = false,
667
+ radio_group_selection: bool = false,
668
+
666
669
  fn app(self: *@This()) App {
667
- return .{ .context = self, .name = "gpu-widget-house-group-navigation", .source = platform.WebViewSource.html("<h1>Hello</h1>") };
670
+ return .{
671
+ .context = self,
672
+ .name = "gpu-widget-house-group-navigation",
673
+ .source = platform.WebViewSource.html("<h1>Hello</h1>"),
674
+ .event_fn = event,
675
+ };
676
+ }
677
+
678
+ fn event(context: *anyopaque, runtime: *Runtime, event_value: Event) anyerror!void {
679
+ _ = runtime;
680
+ const self: *@This() = @ptrCast(@alignCast(context));
681
+ switch (event_value) {
682
+ .canvas_widget_keyboard => |keyboard_event| {
683
+ if (keyboard_event.target) |target| {
684
+ if (target.kind == .radio) {
685
+ self.radio_group_navigation = keyboard_event.keyboard.radio_group_navigation;
686
+ self.radio_group_selection = keyboard_event.keyboard.radio_group_selection;
687
+ }
688
+ }
689
+ },
690
+ else => {},
691
+ }
668
692
  }
669
693
  };
670
694
 
@@ -699,16 +723,24 @@ test "runtime moves focus within house grouped component controls" {
699
723
  .{ .id = 41, .kind = .segmented_control, .text = "Open" },
700
724
  .{ .id = 42, .kind = .segmented_control, .text = "Closed" },
701
725
  };
702
- const radio_buttons = [_]canvas.Widget{
703
- .{ .id = 51, .kind = .radio, .text = "Card" },
726
+ const first_radio = [_]canvas.Widget{
727
+ .{ .id = 51, .kind = .radio, .text = "Card", .state = .{ .selected = true } },
728
+ };
729
+ const second_radio = [_]canvas.Widget{
704
730
  .{ .id = 52, .kind = .radio, .text = "List" },
705
731
  };
732
+ // The rows are deliberate: radios need not be direct children of
733
+ // the radio group to share navigation, selection, or Tab behavior.
734
+ const radio_rows = [_]canvas.Widget{
735
+ .{ .kind = .row, .children = &first_radio },
736
+ .{ .kind = .column, .children = &second_radio },
737
+ };
706
738
  const top_children = [_]canvas.Widget{
707
739
  .{ .id = 10, .kind = .button_group, .frame = geometry.RectF.init(12, 12, 180, 34), .layout = builtinShadcnGroupLayout(), .children = &button_group_buttons },
708
740
  .{ .id = 20, .kind = .pagination, .frame = geometry.RectF.init(12, 56, 220, 34), .layout = builtinShadcnGroupLayout(), .children = &pagination_buttons },
709
741
  .{ .id = 30, .kind = .toggle_group, .frame = geometry.RectF.init(12, 100, 160, 34), .layout = builtinShadcnGroupLayout(), .children = &toggle_buttons },
710
742
  .{ .id = 40, .kind = .tabs, .frame = geometry.RectF.init(12, 144, 180, 34), .layout = builtinShadcnGroupLayout(), .children = &tab_buttons },
711
- .{ .id = 50, .kind = .radio_group, .frame = geometry.RectF.init(12, 188, 180, 34), .layout = builtinShadcnGroupLayout(), .children = &radio_buttons },
743
+ .{ .id = 50, .kind = .radio_group, .frame = geometry.RectF.init(12, 188, 180, 34), .layout = builtinShadcnGroupLayout(), .semantics = .{ .label = "View" }, .children = &radio_rows },
712
744
  .{ .id = 90, .kind = .button, .frame = geometry.RectF.init(248, 12, 84, 34), .text = "Alone" },
713
745
  };
714
746
  var nodes: [24]canvas.WidgetLayoutNode = undefined;
@@ -735,15 +767,258 @@ test "runtime moves focus within house grouped component controls" {
735
767
  try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{ .window_id = 1, .label = "canvas", .kind = .key_down, .key = "arrowright" } });
736
768
  try std.testing.expectEqual(@as(canvas.ObjectId, 42), harness.runtime.views[0].canvas_widget_focused_id);
737
769
 
770
+ // An unchecked radio already at Home is still selected, even though
771
+ // focus stays in place. A second Home is owned by the group but does
772
+ // not request selection again (and therefore cannot re-fire change).
773
+ _ = try runtimeViewSetCanvasWidgetSelected(&harness.runtime.views[0], 51, false);
738
774
  harness.runtime.views[0].canvas_widget_focused_id = 51;
775
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{ .window_id = 1, .label = "canvas", .kind = .key_down, .key = "home" } });
776
+ try std.testing.expectEqual(@as(canvas.ObjectId, 51), harness.runtime.views[0].canvas_widget_focused_id);
777
+ var retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
778
+ try std.testing.expect(retained.findById(51).?.widget.state.selected);
779
+ try std.testing.expect(app_state.radio_group_navigation);
780
+ try std.testing.expect(app_state.radio_group_selection);
781
+
782
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{ .window_id = 1, .label = "canvas", .kind = .key_down, .key = "home" } });
783
+ try std.testing.expect(app_state.radio_group_navigation);
784
+ try std.testing.expect(!app_state.radio_group_selection);
785
+
739
786
  try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{ .window_id = 1, .label = "canvas", .kind = .key_down, .key = "arrowright" } });
740
787
  try std.testing.expectEqual(@as(canvas.ObjectId, 52), harness.runtime.views[0].canvas_widget_focused_id);
788
+ retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
789
+ try std.testing.expect(!retained.findById(51).?.widget.state.selected);
790
+ try std.testing.expect(retained.findById(52).?.widget.state.selected);
791
+ const group_semantics = runtimeViewWidgetSemantics(&harness.runtime.views[0]);
792
+ try std.testing.expectEqual(canvas.WidgetRole.radiogroup, canvasWidgetSemanticsById(group_semantics, 50).?.role);
793
+ const a11y_snapshot = harness.runtime.automationSnapshot("Widgets");
794
+ var a11y_buffer: [4096]u8 = undefined;
795
+ var a11y_writer = std.Io.Writer.fixed(&a11y_buffer);
796
+ try automation.snapshot.writeA11yText(a11y_snapshot, &a11y_writer);
797
+ try std.testing.expect(std.mem.indexOf(u8, a11y_writer.buffered(), "@w1/canvas#50 role=radiogroup") != null);
798
+
799
+ // Home/End walk the whole nearest group scope and selection follows.
800
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{ .window_id = 1, .label = "canvas", .kind = .key_down, .key = "home" } });
801
+ try std.testing.expectEqual(@as(canvas.ObjectId, 51), harness.runtime.views[0].canvas_widget_focused_id);
802
+ retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
803
+ try std.testing.expect(retained.findById(51).?.widget.state.selected);
804
+ try std.testing.expect(!retained.findById(52).?.widget.state.selected);
805
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{ .window_id = 1, .label = "canvas", .kind = .key_down, .key = "end" } });
806
+ try std.testing.expectEqual(@as(canvas.ObjectId, 52), harness.runtime.views[0].canvas_widget_focused_id);
807
+ retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
808
+ try std.testing.expect(!retained.findById(51).?.widget.state.selected);
809
+ try std.testing.expect(retained.findById(52).?.widget.state.selected);
810
+
811
+ // Radio arrows wrap at both scope edges, and selection follows the
812
+ // wrapped focus just as it does for an in-range move.
813
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{ .window_id = 1, .label = "canvas", .kind = .key_down, .key = "arrowright" } });
814
+ try std.testing.expectEqual(@as(canvas.ObjectId, 51), harness.runtime.views[0].canvas_widget_focused_id);
815
+ retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
816
+ try std.testing.expect(retained.findById(51).?.widget.state.selected);
817
+ try std.testing.expect(!retained.findById(52).?.widget.state.selected);
818
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{ .window_id = 1, .label = "canvas", .kind = .key_down, .key = "arrowleft" } });
819
+ try std.testing.expectEqual(@as(canvas.ObjectId, 52), harness.runtime.views[0].canvas_widget_focused_id);
820
+ retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
821
+ try std.testing.expect(!retained.findById(51).?.widget.state.selected);
822
+ try std.testing.expect(retained.findById(52).?.widget.state.selected);
823
+
824
+ // One Tab stop: entering lands on the selected radio, leaving skips
825
+ // the rest, and backward entry from below returns to that selection.
826
+ harness.runtime.views[0].canvas_widget_focused_id = 42;
827
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{ .window_id = 1, .label = "canvas", .kind = .key_down, .key = "tab" } });
828
+ try std.testing.expectEqual(@as(canvas.ObjectId, 52), harness.runtime.views[0].canvas_widget_focused_id);
829
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{ .window_id = 1, .label = "canvas", .kind = .key_down, .key = "tab" } });
830
+ try std.testing.expectEqual(@as(canvas.ObjectId, 90), harness.runtime.views[0].canvas_widget_focused_id);
831
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{ .window_id = 1, .label = "canvas", .kind = .key_down, .key = "tab", .modifiers = .{ .shift = true } } });
832
+ try std.testing.expectEqual(@as(canvas.ObjectId, 52), harness.runtime.views[0].canvas_widget_focused_id);
833
+
834
+ // With no selected radio, group entry deterministically chooses the
835
+ // first focusable descendant instead.
836
+ _ = try runtimeViewSetCanvasWidgetSelected(&harness.runtime.views[0], 52, false);
837
+ harness.runtime.views[0].canvas_widget_focused_id = 42;
838
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{ .window_id = 1, .label = "canvas", .kind = .key_down, .key = "tab" } });
839
+ try std.testing.expectEqual(@as(canvas.ObjectId, 51), harness.runtime.views[0].canvas_widget_focused_id);
741
840
 
742
841
  harness.runtime.views[0].canvas_widget_focused_id = 90;
743
842
  try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{ .window_id = 1, .label = "canvas", .kind = .key_down, .key = "arrowleft" } });
744
843
  try std.testing.expectEqual(@as(canvas.ObjectId, 90), harness.runtime.views[0].canvas_widget_focused_id);
745
844
  }
746
845
 
846
+ test "radio group Tab entry falls back when its selection is fixed-clipped" {
847
+ const TestApp = struct {
848
+ fn app(self: *@This()) App {
849
+ return .{ .context = self, .name = "gpu-widget-radio-fixed-clip-tab", .source = platform.WebViewSource.html("<h1>Hello</h1>") };
850
+ }
851
+ };
852
+
853
+ const harness = try TestHarness().create(std.testing.allocator, .{});
854
+ defer harness.destroy(std.testing.allocator);
855
+ harness.null_platform.gpu_surfaces = true;
856
+ var app_state: TestApp = .{};
857
+ const app = app_state.app();
858
+ try harness.start(app);
859
+
860
+ _ = try harness.runtime.createView(.{
861
+ .window_id = 1,
862
+ .label = "canvas",
863
+ .kind = .gpu_surface,
864
+ .frame = geometry.RectF.init(0, 0, 220, 80),
865
+ });
866
+
867
+ const radios = [_]canvas.Widget{
868
+ .{ .id = 3, .kind = .radio, .frame = geometry.RectF.init(0, 0, 48, 32), .text = "Visible" },
869
+ .{ .id = 4, .kind = .radio, .frame = geometry.RectF.init(0, 0, 48, 32), .text = "Clipped", .state = .{ .selected = true } },
870
+ };
871
+ const children = [_]canvas.Widget{
872
+ .{ .id = 2, .kind = .button, .frame = geometry.RectF.init(0, 0, 40, 32), .text = "Before" },
873
+ .{ .id = 10, .kind = .radio_group, .frame = geometry.RectF.init(52, 0, 48, 32), .layout = .{ .clip_content = true }, .semantics = .{ .label = "View" }, .children = &radios },
874
+ .{ .id = 5, .kind = .button, .frame = geometry.RectF.init(112, 0, 40, 32), .text = "After" },
875
+ };
876
+ var nodes: [6]canvas.WidgetLayoutNode = undefined;
877
+ const layout = try canvas.layoutWidgetTree(.{ .id = 1, .kind = .stack, .children = &children }, geometry.RectF.init(0, 0, 220, 80), &nodes);
878
+ _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
879
+
880
+ // The selected radio is the logical entry, but the fixed clip cannot
881
+ // scroll it into view. Tab therefore uses the visible group member
882
+ // and the next Tab still leaves the composite in one step.
883
+ harness.runtime.views[0].canvas_widget_focused_id = 2;
884
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{ .window_id = 1, .label = "canvas", .kind = .key_down, .key = "tab" } });
885
+ try std.testing.expectEqual(@as(canvas.ObjectId, 3), harness.runtime.views[0].canvas_widget_focused_id);
886
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{ .window_id = 1, .label = "canvas", .kind = .key_down, .key = "tab" } });
887
+ try std.testing.expectEqual(@as(canvas.ObjectId, 5), harness.runtime.views[0].canvas_widget_focused_id);
888
+ }
889
+
890
+ test "nested radio groups keep independent ordered Tab stops" {
891
+ const TestApp = struct {
892
+ fn app(self: *@This()) App {
893
+ return .{ .context = self, .name = "gpu-widget-nested-radio-tab", .source = platform.WebViewSource.html("<h1>Hello</h1>") };
894
+ }
895
+ };
896
+
897
+ const harness = try TestHarness().create(std.testing.allocator, .{});
898
+ defer harness.destroy(std.testing.allocator);
899
+ harness.null_platform.gpu_surfaces = true;
900
+ var app_state: TestApp = .{};
901
+ const app = app_state.app();
902
+ try harness.start(app);
903
+
904
+ _ = try harness.runtime.createView(.{
905
+ .window_id = 1,
906
+ .label = "canvas",
907
+ .kind = .gpu_surface,
908
+ .frame = geometry.RectF.init(0, 0, 280, 80),
909
+ });
910
+
911
+ const inner_radios = [_]canvas.Widget{
912
+ .{ .id = 21, .kind = .radio, .frame = geometry.RectF.init(0, 0, 40, 32), .text = "Inner", .state = .{ .selected = true } },
913
+ };
914
+ const outer_children = [_]canvas.Widget{
915
+ .{ .id = 11, .kind = .radio, .frame = geometry.RectF.init(0, 0, 40, 32), .text = "Outer one", .state = .{ .selected = true } },
916
+ .{ .id = 20, .kind = .radio_group, .frame = geometry.RectF.init(0, 0, 40, 32), .semantics = .{ .label = "Inner choice" }, .children = &inner_radios },
917
+ .{ .id = 12, .kind = .radio, .frame = geometry.RectF.init(0, 0, 40, 32), .text = "Outer two" },
918
+ };
919
+ const children = [_]canvas.Widget{
920
+ .{ .id = 2, .kind = .button, .frame = geometry.RectF.init(0, 0, 40, 32), .text = "Before" },
921
+ .{ .id = 10, .kind = .radio_group, .frame = geometry.RectF.init(52, 0, 144, 32), .layout = .{ .gap = 4 }, .semantics = .{ .label = "Outer choice" }, .children = &outer_children },
922
+ .{ .id = 3, .kind = .button, .frame = geometry.RectF.init(208, 0, 40, 32), .text = "After" },
923
+ };
924
+ var nodes: [8]canvas.WidgetLayoutNode = undefined;
925
+ const layout = try canvas.layoutWidgetTree(.{ .id = 1, .kind = .stack, .children = &children }, geometry.RectF.init(0, 0, 280, 80), &nodes);
926
+ _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
927
+
928
+ // Each nearest scope owns one slot at its first radio. The trailing
929
+ // outer radio must not retarget backward to #11 after focus visits
930
+ // the nested group, which used to cycle #11 -> #21 -> #11 forever.
931
+ harness.runtime.views[0].canvas_widget_focused_id = 2;
932
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{ .window_id = 1, .label = "canvas", .kind = .key_down, .key = "tab" } });
933
+ try std.testing.expectEqual(@as(canvas.ObjectId, 11), harness.runtime.views[0].canvas_widget_focused_id);
934
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{ .window_id = 1, .label = "canvas", .kind = .key_down, .key = "tab" } });
935
+ try std.testing.expectEqual(@as(canvas.ObjectId, 21), harness.runtime.views[0].canvas_widget_focused_id);
936
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{ .window_id = 1, .label = "canvas", .kind = .key_down, .key = "tab" } });
937
+ try std.testing.expectEqual(@as(canvas.ObjectId, 3), harness.runtime.views[0].canvas_widget_focused_id);
938
+
939
+ // Reverse traversal visits the same logical slots in reverse order.
940
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{ .window_id = 1, .label = "canvas", .kind = .key_down, .key = "tab", .modifiers = .{ .shift = true } } });
941
+ try std.testing.expectEqual(@as(canvas.ObjectId, 21), harness.runtime.views[0].canvas_widget_focused_id);
942
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{ .window_id = 1, .label = "canvas", .kind = .key_down, .key = "tab", .modifiers = .{ .shift = true } } });
943
+ try std.testing.expectEqual(@as(canvas.ObjectId, 11), harness.runtime.views[0].canvas_widget_focused_id);
944
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{ .window_id = 1, .label = "canvas", .kind = .key_down, .key = "tab", .modifiers = .{ .shift = true } } });
945
+ try std.testing.expectEqual(@as(canvas.ObjectId, 2), harness.runtime.views[0].canvas_widget_focused_id);
946
+
947
+ // The group's selected entry may sit after the nested scope, but its
948
+ // logical Tab slot stays at #11: entry lands on #12, then traversal
949
+ // resumes from the slot and still reaches the inner group.
950
+ _ = try runtimeViewSetCanvasWidgetSelected(&harness.runtime.views[0], 11, false);
951
+ _ = try runtimeViewSetCanvasWidgetSelected(&harness.runtime.views[0], 12, true);
952
+ harness.runtime.views[0].canvas_widget_focused_id = 2;
953
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{ .window_id = 1, .label = "canvas", .kind = .key_down, .key = "tab" } });
954
+ try std.testing.expectEqual(@as(canvas.ObjectId, 12), harness.runtime.views[0].canvas_widget_focused_id);
955
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{ .window_id = 1, .label = "canvas", .kind = .key_down, .key = "tab" } });
956
+ try std.testing.expectEqual(@as(canvas.ObjectId, 21), harness.runtime.views[0].canvas_widget_focused_id);
957
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{ .window_id = 1, .label = "canvas", .kind = .key_down, .key = "tab" } });
958
+ try std.testing.expectEqual(@as(canvas.ObjectId, 3), harness.runtime.views[0].canvas_widget_focused_id);
959
+ }
960
+
961
+ test "radio navigation skips fixed-clipped candidates" {
962
+ const TestApp = struct {
963
+ fn app(self: *@This()) App {
964
+ return .{ .context = self, .name = "gpu-widget-radio-fixed-clip-navigation", .source = platform.WebViewSource.html("<h1>Hello</h1>") };
965
+ }
966
+ };
967
+
968
+ const harness = try TestHarness().create(std.testing.allocator, .{});
969
+ defer harness.destroy(std.testing.allocator);
970
+ harness.null_platform.gpu_surfaces = true;
971
+ var app_state: TestApp = .{};
972
+ const app = app_state.app();
973
+ try harness.start(app);
974
+
975
+ _ = try harness.runtime.createView(.{
976
+ .window_id = 1,
977
+ .label = "canvas",
978
+ .kind = .gpu_surface,
979
+ .frame = geometry.RectF.init(0, 0, 280, 80),
980
+ });
981
+
982
+ const radios = [_]canvas.Widget{
983
+ .{ .id = 3, .kind = .radio, .frame = geometry.RectF.init(0, 0, 28, 32), .text = "Hidden first" },
984
+ .{ .id = 4, .kind = .radio, .frame = geometry.RectF.init(0, 0, 28, 32), .text = "Visible one", .state = .{ .selected = true } },
985
+ .{ .id = 5, .kind = .radio, .frame = geometry.RectF.init(0, 0, 28, 32), .text = "Hidden middle" },
986
+ .{ .id = 6, .kind = .radio, .frame = geometry.RectF.init(0, 0, 28, 32), .text = "Visible two" },
987
+ .{ .id = 7, .kind = .radio, .frame = geometry.RectF.init(0, 0, 28, 32), .text = "Hidden last" },
988
+ };
989
+ const children = [_]canvas.Widget{
990
+ .{ .id = 10, .kind = .radio_group, .frame = geometry.RectF.init(20, 0, 160, 32), .layout = .{ .clip_content = true, .gap = 4 }, .semantics = .{ .label = "View" }, .children = &radios },
991
+ };
992
+ var nodes: [7]canvas.WidgetLayoutNode = undefined;
993
+ const layout = try canvas.layoutWidgetTree(.{ .id = 1, .kind = .stack, .children = &children }, geometry.RectF.init(0, 0, 280, 80), &nodes);
994
+ for (nodes[0..layout.nodes.len]) |*node| {
995
+ if (node.widget.id == 3 or node.widget.id == 5 or node.widget.id == 7) {
996
+ node.frame.x = 220;
997
+ }
998
+ }
999
+ _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
1000
+
1001
+ // Logical order remains 3,4,5,6,7 so scroll viewports can reveal
1002
+ // candidates. Fixed clipping cannot reveal 3/5/7; traversal must
1003
+ // continue until the next visible member accepts focus.
1004
+ harness.runtime.views[0].canvas_widget_focused_id = 4;
1005
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{ .window_id = 1, .label = "canvas", .kind = .key_down, .key = "arrowright" } });
1006
+ try std.testing.expectEqual(@as(canvas.ObjectId, 6), harness.runtime.views[0].canvas_widget_focused_id);
1007
+ const retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
1008
+ try std.testing.expect(!retained.findById(4).?.widget.state.selected);
1009
+ try std.testing.expect(retained.findById(6).?.widget.state.selected);
1010
+
1011
+ harness.runtime.views[0].canvas_widget_focused_id = 4;
1012
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{ .window_id = 1, .label = "canvas", .kind = .key_down, .key = "end" } });
1013
+ try std.testing.expectEqual(@as(canvas.ObjectId, 6), harness.runtime.views[0].canvas_widget_focused_id);
1014
+
1015
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{ .window_id = 1, .label = "canvas", .kind = .key_down, .key = "home" } });
1016
+ try std.testing.expectEqual(@as(canvas.ObjectId, 4), harness.runtime.views[0].canvas_widget_focused_id);
1017
+
1018
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{ .window_id = 1, .label = "canvas", .kind = .key_down, .key = "arrowleft" } });
1019
+ try std.testing.expectEqual(@as(canvas.ObjectId, 6), harness.runtime.views[0].canvas_widget_focused_id);
1020
+ }
1021
+
747
1022
  fn builtinShadcnGroupLayout() canvas.WidgetLayoutStyle {
748
1023
  return .{ .gap = 4, .cross_alignment = .center };
749
1024
  }
@@ -352,6 +352,60 @@ test "escape from an unrelated focused widget falls back to the topmost mounted
352
352
  try std.testing.expect(!fixture.app_state.model.switcher_open);
353
353
  }
354
354
 
355
+ test "outside click dismisses an anchored surface opened from a NON-focusable trigger" {
356
+ const fixture = try Fixture.create();
357
+ defer fixture.destroy();
358
+
359
+ const trigger_id = fixture.widgetIdByText(.text, "Files").?;
360
+ try fixture.clickWidget(trigger_id);
361
+ try std.testing.expect(fixture.app_state.model.switcher_open);
362
+ try std.testing.expectEqual(@as(canvas.ObjectId, 0), fixture.harness.runtime.views[0].canvas_widget_focused_id);
363
+
364
+ try fixture.click(geometry.PointF.init(360, 280));
365
+ try std.testing.expectEqual(@as(u32, 1), fixture.app_state.model.switcher_dismissals);
366
+ try std.testing.expect(!fixture.app_state.model.switcher_open);
367
+ try std.testing.expect(fixture.widgetIdByText(.menu_item, "Sibling") == null);
368
+ }
369
+
370
+ test "outside click falls back from unrelated focus to the mounted anchored surface" {
371
+ const fixture = try Fixture.create();
372
+ defer fixture.destroy();
373
+
374
+ const trigger_id = fixture.widgetIdByText(.text, "Files").?;
375
+ try fixture.clickWidget(trigger_id);
376
+ const select_id = fixture.widgetIdByText(.select, "Repo").?;
377
+ var command_buffer: [96]u8 = undefined;
378
+ const focus_command = try std.fmt.bufPrint(&command_buffer, "widget-action {s} {d} focus", .{ canvas_label, select_id });
379
+ try fixture.harness.runtime.dispatchAutomationCommand(fixture.app, focus_command);
380
+ try std.testing.expectEqual(select_id, fixture.harness.runtime.views[0].canvas_widget_focused_id);
381
+
382
+ try fixture.click(geometry.PointF.init(360, 280));
383
+ try std.testing.expectEqual(@as(u32, 1), fixture.app_state.model.switcher_dismissals);
384
+ try std.testing.expect(!fixture.app_state.model.switcher_open);
385
+ }
386
+
387
+ test "inside and trigger clicks do not outside-dismiss a non-focusable anchored surface" {
388
+ const fixture = try Fixture.create();
389
+ defer fixture.destroy();
390
+
391
+ const trigger_id = fixture.widgetIdByText(.text, "Files").?;
392
+ try fixture.clickWidget(trigger_id);
393
+ const item_id = fixture.widgetIdByText(.menu_item, "Sibling").?;
394
+
395
+ // The menu item is inside the surface. Its ordinary Msg fires, but
396
+ // outside dismissal does not race it or close the surface.
397
+ try fixture.clickWidget(item_id);
398
+ try std.testing.expectEqual(@as(u32, 1), fixture.app_state.model.crumb_presses);
399
+ try std.testing.expectEqual(@as(u32, 0), fixture.app_state.model.switcher_dismissals);
400
+ try std.testing.expect(fixture.app_state.model.switcher_open);
401
+
402
+ // The trigger stack owns its toggle gesture: it closes exactly once,
403
+ // with no preceding dismissal Msg.
404
+ try fixture.clickWidget(trigger_id);
405
+ try std.testing.expect(!fixture.app_state.model.switcher_open);
406
+ try std.testing.expectEqual(@as(u32, 0), fixture.app_state.model.switcher_dismissals);
407
+ }
408
+
355
409
  test "anchored picker: click outside dismisses as a Msg; clicking the trigger toggles exactly once" {
356
410
  const fixture = try Fixture.create();
357
411
  defer fixture.destroy();
@@ -649,6 +649,21 @@ test "runtime reconciles canvas control state across layout replacement" {
649
649
  .text = "Annual",
650
650
  },
651
651
  };
652
+ const nested_radio_a = [_]canvas.Widget{.{
653
+ .id = 18,
654
+ .kind = .radio,
655
+ .text = "Email",
656
+ .state = .{ .selected = true },
657
+ }};
658
+ const nested_radio_b = [_]canvas.Widget{.{
659
+ .id = 19,
660
+ .kind = .radio,
661
+ .text = "SMS",
662
+ }};
663
+ const nested_radio_rows = [_]canvas.Widget{
664
+ .{ .kind = .row, .children = &nested_radio_a },
665
+ .{ .kind = .column, .children = &nested_radio_b },
666
+ };
652
667
  const controls = [_]canvas.Widget{
653
668
  .{
654
669
  .id = 2,
@@ -696,8 +711,14 @@ test "runtime reconciles canvas control state across layout replacement" {
696
711
  .frame = geometry.RectF.init(150, 178, 160, 30),
697
712
  .children = &radio_items,
698
713
  },
714
+ .{
715
+ .id = 20,
716
+ .kind = .radio_group,
717
+ .frame = geometry.RectF.init(150, 140, 120, 30),
718
+ .children = &nested_radio_rows,
719
+ },
699
720
  };
700
- var nodes: [20]canvas.WidgetLayoutNode = undefined;
721
+ var nodes: [24]canvas.WidgetLayoutNode = undefined;
701
722
  const layout = try canvas.layoutWidgetTree(.{ .kind = .stack, .children = &controls }, geometry.RectF.init(0, 0, 280, 220), &nodes);
702
723
  _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
703
724
 
@@ -709,6 +730,7 @@ test "runtime reconciles canvas control state across layout replacement" {
709
730
  try dispatchAutomationWidgetAction(&harness.runtime, app, .{ .view_label = "canvas", .id = 12, .action = .select });
710
731
  try dispatchAutomationWidgetAction(&harness.runtime, app, .{ .view_label = "canvas", .id = 14, .action = .select });
711
732
  try dispatchAutomationWidgetAction(&harness.runtime, app, .{ .view_label = "canvas", .id = 17, .action = .select });
733
+ try dispatchAutomationWidgetAction(&harness.runtime, app, .{ .view_label = "canvas", .id = 19, .action = .select });
712
734
 
713
735
  var retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
714
736
  try std.testing.expect(retained.findById(2).?.widget.state.selected);
@@ -726,6 +748,8 @@ test "runtime reconciles canvas control state across layout replacement" {
726
748
  try std.testing.expect(retained.findById(14).?.widget.state.selected);
727
749
  try std.testing.expect(!retained.findById(16).?.widget.state.selected);
728
750
  try std.testing.expect(retained.findById(17).?.widget.state.selected);
751
+ try std.testing.expect(!retained.findById(18).?.widget.state.selected);
752
+ try std.testing.expect(retained.findById(19).?.widget.state.selected);
729
753
 
730
754
  harness.runtime.invalidated = false;
731
755
  harness.runtime.dirty_region_count = 0;
@@ -757,6 +781,12 @@ test "runtime reconciles canvas control state across layout replacement" {
757
781
  try std.testing.expectEqual(@as(f32, 0), retained.findById(16).?.widget.value);
758
782
  try std.testing.expect(retained.findById(17).?.widget.state.selected);
759
783
  try std.testing.expectEqual(@as(f32, 1), retained.findById(17).?.widget.value);
784
+ // The unchanged source still declares 18 selected. Reconcile keeps
785
+ // the runtime selection on nested 19 until the source actually moves.
786
+ try std.testing.expect(!retained.findById(18).?.widget.state.selected);
787
+ try std.testing.expectEqual(@as(f32, 0), retained.findById(18).?.widget.value);
788
+ try std.testing.expect(retained.findById(19).?.widget.state.selected);
789
+ try std.testing.expectEqual(@as(f32, 1), retained.findById(19).?.widget.value);
760
790
  try std.testing.expect(!harness.runtime.invalidated);
761
791
  try std.testing.expectEqual(@as(usize, 0), harness.runtime.pendingDirtyRegions().len);
762
792