@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
@@ -12,6 +12,7 @@ const std = @import("std");
12
12
  const effects_mod = @import("effects.zig");
13
13
  const runtime_clock = @import("clock.zig");
14
14
  const ts_core_host = @import("ts_core_host.zig");
15
+ const platform = @import("../platform/root.zig");
15
16
 
16
17
  // ------------------------------------------------------ the mini core
17
18
  //
@@ -338,6 +339,7 @@ const mini_core = struct {
338
339
  open_save_sink, // 102: write_file_stream "save" -> wrote/failed
339
340
  write_save_chunk, // 103: write_file_chunk "save" -> wrote/failed
340
341
  close_save_sink, // 104: write_file_close "save" -> wrote/failed
342
+ dock_on, // 105: dock_presence true
341
343
  };
342
344
 
343
345
  const stream_fill_keys = [_][]const u8{
@@ -686,6 +688,7 @@ const mini_core = struct {
686
688
  .open_win => return .{ .model = model, .cmd = cmdWindowShow("player") },
687
689
  .hide_win => return .{ .model = model, .cmd = cmdWindowHide("player") },
688
690
  .dock_off => return .{ .model = model, .cmd = cmdDockPresence(false) },
691
+ .dock_on => return .{ .model = model, .cmd = cmdDockPresence(true) },
689
692
  .quit_app => return .{ .model = model, .cmd = cmdQuitApp() },
690
693
  .open_chan => return .{ .model = model, .cmd = cmdChannelOpen(41, 47) },
691
694
  .close_chan => return .{ .model = model, .cmd = cmdChannelClose(41) },
@@ -2842,6 +2845,50 @@ test "window verbs bridge to the effects channel's label-addressed verbs" {
2842
2845
  try std.testing.expectEqual(boot_pending, fx.pendingHostCount());
2843
2846
  }
2844
2847
 
2848
+ test "an accessory launch composes with a TypeScript dock-presence promotion" {
2849
+ var null_platform = platform.NullPlatform.initWithOptions(.{}, .system, .{
2850
+ .app_name = "Menu Bar",
2851
+ .dock_visible = false,
2852
+ });
2853
+ try std.testing.expect(!null_platform.dock_visible);
2854
+
2855
+ const Actions = struct {
2856
+ fn window(_: *anyopaque, _: []const u8) bool {
2857
+ return true;
2858
+ }
2859
+
2860
+ fn dock(context: *anyopaque, visible: bool) bool {
2861
+ const host: *platform.NullPlatform = @ptrCast(@alignCast(context));
2862
+ host.platform().services.setDockPresence(visible) catch return false;
2863
+ return true;
2864
+ }
2865
+
2866
+ fn quit(_: *anyopaque) bool {
2867
+ return true;
2868
+ }
2869
+ };
2870
+
2871
+ const fx = freshChannel();
2872
+ defer fx.deinit();
2873
+ Host.init(fx);
2874
+ fx.bindWindowActions(.{
2875
+ .context = &null_platform,
2876
+ .close_fn = Actions.window,
2877
+ .minimize_fn = Actions.window,
2878
+ .hide_fn = Actions.window,
2879
+ .show_fn = Actions.window,
2880
+ .dock_presence_fn = Actions.dock,
2881
+ .quit_fn = Actions.quit,
2882
+ });
2883
+ fx.executor = .real;
2884
+
2885
+ Host.dispatch(fx, .dock_on);
2886
+ try std.testing.expect(fx.windowActionState().dock_visible);
2887
+ try std.testing.expectEqual(@as(u32, 1), fx.windowActionState().dock_presence_count);
2888
+ try std.testing.expect(null_platform.dock_visible);
2889
+ try std.testing.expectEqual(@as(u32, 1), null_platform.dock_presence_count);
2890
+ }
2891
+
2845
2892
  test "a channel opens, posts route the five-field arm by name, and close retires the key" {
2846
2893
  const fx = freshChannel();
2847
2894
  defer fx.deinit();
@@ -4983,7 +4983,7 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
4983
4983
  // `on_double_press` handler (falling back to the ordinary
4984
4984
  // press), while its first release already dispatched the
4985
4985
  // single press — select-then-act, the list convention.
4986
- if (tree.msgForPointerClick(target.id, pointer_event.pointer.phase, pointer_event.pointer.click_count)) |msg| {
4986
+ if (tree.msgForPointerEvent(target.id, pointer_event.pointer)) |msg| {
4987
4987
  try self.dispatch(runtime, pointer_event.window_id, msg);
4988
4988
  }
4989
4989
  }
@@ -5829,6 +5829,12 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
5829
5829
  }
5830
5830
  return;
5831
5831
  }
5832
+ // A radio group owns Arrow/Home/End even when the
5833
+ // requested target is already focused and selected.
5834
+ // That in-place case deliberately has no selection
5835
+ // intent (and therefore no duplicate on-change), but
5836
+ // it must still stop before the app-level key map.
5837
+ if (keyboard_event.keyboard.radio_group_navigation) return;
5832
5838
  }
5833
5839
  }
5834
5840
  }
@@ -6022,8 +6028,8 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
6022
6028
  const tree = self.treeForViewLabel(drag_event.view_label);
6023
6029
  const live_template = if (tree) |value| value.msgFor(source.id, .drag) else null;
6024
6030
  const layout: ?canvas.WidgetLayoutTree = runtime.canvasWidgetLayout(drag_event.window_id, drag_event.view_label) catch null;
6025
- const live_view_size: ?geometry.SizeF = if (layout) |value| if (value.nodes.len > 0) blk: {
6026
- const root = value.nodes[0].frame.normalized();
6031
+ const live_view_size: ?geometry.SizeF = if (layout) |value| if (canvas.widgetLayoutRootBounds(value)) |root_value| blk: {
6032
+ const root = root_value.normalized();
6027
6033
  break :blk geometry.SizeF.init(root.width, root.height);
6028
6034
  } else null else null;
6029
6035
 
@@ -70,6 +70,43 @@ fn counterOptions() CounterApp.Options {
70
70
  };
71
71
  }
72
72
 
73
+ const RadioModel = struct {
74
+ choice: u8 = 0,
75
+ change_count: u32 = 0,
76
+ };
77
+
78
+ const RadioMsg = union(enum) {
79
+ choose_first,
80
+ choose_second,
81
+ };
82
+
83
+ const RadioApp = ui_app_model.UiApp(RadioModel, RadioMsg);
84
+
85
+ fn radioUpdate(model: *RadioModel, msg: RadioMsg) void {
86
+ model.choice = switch (msg) {
87
+ .choose_first => 0,
88
+ .choose_second => 1,
89
+ };
90
+ model.change_count += 1;
91
+ }
92
+
93
+ fn radioView(ui: *RadioApp.Ui, model: *const RadioModel) RadioApp.Ui.Node {
94
+ return ui.el(.radio_group, .{ .semantics = .{ .label = "Plan" } }, .{
95
+ ui.el(.radio, .{ .text = "Free", .checked = model.choice == 0, .on_change = .choose_first }, .{}),
96
+ ui.el(.radio, .{ .text = "Pro", .checked = model.choice == 1, .on_change = .choose_second }, .{}),
97
+ });
98
+ }
99
+
100
+ fn radioOptions() RadioApp.Options {
101
+ return .{
102
+ .name = "ui-app-radio",
103
+ .scene = counter_scene,
104
+ .canvas_label = canvas_label,
105
+ .update = radioUpdate,
106
+ .view = radioView,
107
+ };
108
+ }
109
+
73
110
  const software_counter_views = [_]app_manifest.ShellView{
74
111
  .{ .label = canvas_label, .kind = .gpu_surface, .fill = true, .gpu_backend = .software },
75
112
  };
@@ -772,13 +809,19 @@ test "a declared context menu presents as the anchored fallback surface on prese
772
809
  try std.testing.expect(app_state.tree.?.context_menu_fallback == null);
773
810
  try std.testing.expect(!try retainedWidgetKindExists(&harness.runtime, .dropdown_menu));
774
811
 
775
- // Reopen and dismiss (Escape/outside-click/automation all land on
776
- // the same dismissal machinery): the surface closes, no Msg fires.
812
+ // Reopen and click outside. The fallback was opened from a typically
813
+ // non-focusable secondary-click target, so no focused ancestry is
814
+ // available to find it; the whole-view anchored fallback must still
815
+ // dismiss it. Its internal open state closes and no app Msg fires.
777
816
  try harness.runtime.dispatchAutomationCommand(app, context_press);
778
- const reopened = app_state.tree.?.context_menu_fallback orelse return error.TestUnexpectedResult;
779
- var dismiss_buffer: [96]u8 = undefined;
780
- const dismiss = try std.fmt.bufPrint(&dismiss_buffer, "widget-action {s} {d} dismiss", .{ canvas_label, reopened.surface_id });
781
- try harness.runtime.dispatchAutomationCommand(app, dismiss);
817
+ _ = app_state.tree.?.context_menu_fallback orelse return error.TestUnexpectedResult;
818
+ harness.runtime.views[0].canvas_widget_focused_id = 0;
819
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
820
+ .label = canvas_label,
821
+ .kind = .pointer_down,
822
+ .x = 360,
823
+ .y = 280,
824
+ } });
782
825
  try std.testing.expect(app_state.tree.?.context_menu_fallback == null);
783
826
  try std.testing.expect(!try retainedWidgetKindExists(&harness.runtime, .dropdown_menu));
784
827
  try std.testing.expectEqual(@as(u32, 1), app_state.model.deleted);
@@ -2370,6 +2413,41 @@ fn installCounterApp(harness: anytype, app: core.App) !void {
2370
2413
  } });
2371
2414
  }
2372
2415
 
2416
+ test "radio accessibility selection dispatches change once per retained transition" {
2417
+ const harness = try core.TestHarness().create(std.testing.allocator, .{ .size = geometry.SizeF.init(400, 300) });
2418
+ defer harness.destroy(std.testing.allocator);
2419
+ harness.null_platform.gpu_surfaces = true;
2420
+
2421
+ const app_state = try std.testing.allocator.create(RadioApp);
2422
+ defer std.testing.allocator.destroy(app_state);
2423
+ app_state.* = RadioApp.init(std.heap.page_allocator, .{}, radioOptions());
2424
+ defer app_state.deinit();
2425
+ const app = app_state.app();
2426
+ try installCounterApp(harness, app);
2427
+
2428
+ const pro_id = findWidgetIdByText(app_state.tree.?, .radio, "Pro").?;
2429
+ _ = try harness.runtime.dispatchCanvasWidgetAccessibilityAction(app, 1, canvas_label, .{
2430
+ .id = pro_id,
2431
+ .action = .select,
2432
+ });
2433
+ try std.testing.expectEqual(@as(u8, 1), app_state.model.choice);
2434
+ try std.testing.expectEqual(@as(u32, 1), app_state.model.change_count);
2435
+ try std.testing.expect((try harness.runtime.canvasWidgetLayout(1, canvas_label)).findById(pro_id).?.widget.state.selected);
2436
+
2437
+ // AX selection, pointer activation, and Space all still activate the
2438
+ // radio, but an already-selected control has no new `on_change` edge.
2439
+ _ = try harness.runtime.dispatchCanvasWidgetAccessibilityAction(app, 1, canvas_label, .{
2440
+ .id = pro_id,
2441
+ .action = .select,
2442
+ });
2443
+ var command_buffer: [96]u8 = undefined;
2444
+ const click = try std.fmt.bufPrint(&command_buffer, "widget-click {s} {d}", .{ canvas_label, pro_id });
2445
+ try harness.runtime.dispatchAutomationCommand(app, click);
2446
+ try harness.runtime.dispatchAutomationCommand(app, "widget-key counter-canvas space");
2447
+ try std.testing.expectEqual(@as(u8, 1), app_state.model.choice);
2448
+ try std.testing.expectEqual(@as(u32, 1), app_state.model.change_count);
2449
+ }
2450
+
2373
2451
  test "the fragment watch reloads a compiled fragment embedded in a Zig view" {
2374
2452
  const io = std.testing.io;
2375
2453
  const cwd = std.Io.Dir.cwd();
@@ -3310,17 +3388,23 @@ fn autofocusUpdate(model: *AutofocusModel, msg: AutofocusMsg) void {
3310
3388
  /// must receive the keyboard without a click.
3311
3389
  fn autofocusView(ui: *AutofocusApp.Ui, model: *const AutofocusModel) AutofocusApp.Ui.Node {
3312
3390
  if (!model.editing) {
3313
- return ui.column(.{ .gap = 8, .padding = 12 }, .{
3314
- ui.button(.{ .on_press = AutofocusMsg.begin_edit }, "New note"),
3391
+ return ui.column(.{ .padding = 12 }, .{
3392
+ ui.scroll(.{ .height = 96 }, ui.column(.{ .gap = 8 }, .{
3393
+ ui.button(.{ .on_press = AutofocusMsg.begin_edit }, "New note"),
3394
+ ui.text(.{ .height = 120 }, "Recent notes"),
3395
+ })),
3315
3396
  });
3316
3397
  }
3317
- return ui.column(.{ .gap = 8, .padding = 12 }, .{
3318
- ui.button(.{ .on_press = AutofocusMsg.begin_edit }, "New note"),
3319
- ui.textField(.{
3320
- .autofocus = true,
3321
- .text = model.draft.text(),
3322
- .on_input = AutofocusApp.Ui.inputMsg(.draft_edit),
3323
- }),
3398
+ return ui.column(.{ .padding = 12 }, .{
3399
+ ui.scroll(.{ .height = 96 }, ui.column(.{ .gap = 8 }, .{
3400
+ ui.button(.{ .on_press = AutofocusMsg.begin_edit }, "New note"),
3401
+ ui.text(.{ .height = 120 }, "Recent notes"),
3402
+ ui.textField(.{
3403
+ .autofocus = true,
3404
+ .text = model.draft.text(),
3405
+ .on_input = AutofocusApp.Ui.inputMsg(.draft_edit),
3406
+ }),
3407
+ })),
3324
3408
  });
3325
3409
  }
3326
3410
 
@@ -3375,12 +3459,20 @@ test "ui app autofocus moves the keyboard to a freshly mounted editor through th
3375
3459
  }
3376
3460
  try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[view_index].canvas_widget_focused_id);
3377
3461
 
3378
- // The Cmd-N-shaped command mounts the editor; the rebuild's
3379
- // autofocus edge moves keyboard focus to it — no click.
3462
+ // The Cmd-N-shaped command mounts the editor BELOW the scroll
3463
+ // viewport; the rebuild's autofocus edge reveals it and moves
3464
+ // keyboard focus to it — no click.
3380
3465
  try harness.runtime.dispatchPlatformEvent(app, .{ .menu_command = .{ .name = "note.new", .window_id = 1 } });
3381
3466
  try std.testing.expect(app_state.model.editing);
3382
3467
  const field_id = findWidgetIdByKind(app_state.tree.?.root, .text_field).?;
3468
+ const scroll_id = findWidgetIdByKind(app_state.tree.?.root, .scroll_view).?;
3383
3469
  try std.testing.expectEqual(field_id, harness.runtime.views[view_index].canvas_widget_focused_id);
3470
+ var retained = try harness.runtime.canvasWidgetLayout(1, autofocus_canvas_label);
3471
+ const scroll = retained.findById(scroll_id).?;
3472
+ const field = retained.findById(field_id).?;
3473
+ try std.testing.expect(scroll.widget.value > 0);
3474
+ try std.testing.expect(field.frame.y >= scroll.frame.y);
3475
+ try std.testing.expect(field.frame.maxY() <= scroll.frame.maxY());
3384
3476
 
3385
3477
  // Typing lands in the model through the ordinary input path.
3386
3478
  try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
@@ -3392,10 +3484,18 @@ test "ui app autofocus moves the keyboard to a freshly mounted editor through th
3392
3484
  try std.testing.expectEqualStrings("Groceries", app_state.model.draft.text());
3393
3485
  try std.testing.expect(app_state.model.edit_count > 0);
3394
3486
 
3395
- // A later rebuild with the flag still true never re-steals focus:
3396
- // click the button (its press dispatches begin_edit and rebuilds).
3487
+ // A later rebuild with the flag still true never re-steals focus.
3488
+ // Programmatically focusing the now-offscreen button first also proves
3489
+ // the shared automation focus verb reveals logical targets; its real
3490
+ // click then dispatches begin_edit and rebuilds.
3397
3491
  const button_id = findWidgetIdByKind(app_state.tree.?.root, .button).?;
3398
3492
  var command_buffer: [96]u8 = undefined;
3493
+ const focus_command = try std.fmt.bufPrint(&command_buffer, "widget-action {s} {d} focus", .{ autofocus_canvas_label, button_id });
3494
+ try harness.runtime.dispatchAutomationCommand(app, focus_command);
3495
+ try std.testing.expectEqual(button_id, harness.runtime.views[view_index].canvas_widget_focused_id);
3496
+ retained = try harness.runtime.canvasWidgetLayout(1, autofocus_canvas_label);
3497
+ try std.testing.expectEqual(@as(f32, 0), retained.findById(scroll_id).?.widget.value);
3498
+
3399
3499
  const click_command = try std.fmt.bufPrint(&command_buffer, "widget-click {s} {d}", .{ autofocus_canvas_label, button_id });
3400
3500
  try harness.runtime.dispatchAutomationCommand(app, click_command);
3401
3501
  try std.testing.expectEqual(button_id, harness.runtime.views[view_index].canvas_widget_focused_id);
@@ -20,6 +20,7 @@ const settings_window_label = "settings";
20
20
 
21
21
  const PanelModel = struct {
22
22
  settings_open: bool = false,
23
+ position_settings: bool = true,
23
24
  transparent_settings: bool = false,
24
25
  bumps: u32 = 0,
25
26
  user_closes: u32 = 0,
@@ -60,6 +61,8 @@ fn panelWindows(model: *const PanelModel, scratch: *PanelApp.WindowsScratch) []c
60
61
  .title = "Settings",
61
62
  .width = 320,
62
63
  .height = 240,
64
+ .x = if (model.position_settings) 84 else null,
65
+ .y = if (model.position_settings) 126 else null,
63
66
  .min_width = 280,
64
67
  .min_height = 200,
65
68
  .titlebar = if (model.transparent_settings) .chromeless else .standard,
@@ -191,6 +194,9 @@ test "a Msg declares the settings window, its canvas installs, and automation dr
191
194
  if (window.id != info.id) continue;
192
195
  try std.testing.expectEqual(@as(f32, 280), null_platform.window_min_width[index]);
193
196
  try std.testing.expectEqual(@as(f32, 200), null_platform.window_min_height[index]);
197
+ try std.testing.expectEqual(support.platform.WindowInitialPlacement.explicit, null_platform.window_placement[index]);
198
+ try std.testing.expectEqual(@as(f32, 84), window.frame.x);
199
+ try std.testing.expectEqual(@as(f32, 126), window.frame.y);
194
200
  found = true;
195
201
  }
196
202
  try std.testing.expect(found);
@@ -226,11 +232,17 @@ test "a Msg declares the settings window, its canvas installs, and automation dr
226
232
  const closed = fixture.settingsWindowInfo();
227
233
  try std.testing.expect(closed == null or !closed.?.open);
228
234
 
229
- // Reopen under the SAME label: the closed slot released it.
235
+ // Reopen under the SAME label without an authored origin: the closed slot
236
+ // released it, and a descriptor with no x/y takes default host placement.
237
+ fixture.app_state.model.position_settings = false;
230
238
  try fixture.clickSettingsButton();
231
239
  try std.testing.expect(fixture.app_state.model.settings_open);
232
240
  const reopened = fixture.settingsWindowInfo() orelse return error.TestUnexpectedResult;
233
241
  try std.testing.expect(reopened.open);
242
+ for (fixture.harness.null_platform.windows[0..fixture.harness.null_platform.window_count], 0..) |window, index| {
243
+ if (window.id != reopened.id) continue;
244
+ try std.testing.expectEqual(support.platform.WindowInitialPlacement.default, fixture.harness.null_platform.window_placement[index]);
245
+ }
234
246
  }
235
247
 
236
248
  test "a transparent descriptor selects premultiplied canvas alpha and an alpha-zero clear" {
@@ -445,6 +445,7 @@ pub const RuntimeView = struct {
445
445
  canvas_frame_profile_dirty_ratio: f32 = 0,
446
446
  widget_layout_nodes: [max_canvas_widget_nodes_per_view]canvas.WidgetLayoutNode = undefined,
447
447
  widget_layout_node_count: usize = 0,
448
+ widget_layout_root_bounds: ?geometry.RectF = null,
448
449
  widget_semantics_nodes: [max_canvas_widget_semantics_per_view]canvas.WidgetSemanticsNode = undefined,
449
450
  widget_semantics_node_count: usize = 0,
450
451
  /// Fingerprint of the last accessibility tree actually handed to the
@@ -863,6 +864,7 @@ pub const RuntimeView = struct {
863
864
  pub const applyCanvasWidgetTextareaScroll = CanvasWidgetScrollMethods.applyCanvasWidgetTextareaScroll;
864
865
  pub const applyCanvasWidgetScrollDriverOffset = CanvasWidgetScrollMethods.applyCanvasWidgetScrollDriverOffset;
865
866
  pub const applyCanvasWidgetScrollKeyboardTarget = CanvasWidgetScrollMethods.applyCanvasWidgetScrollKeyboardTarget;
867
+ pub const canScrollCanvasWidgetIntoView = CanvasWidgetScrollMethods.canScrollCanvasWidgetIntoView;
866
868
  pub const scrollCanvasWidgetIntoView = CanvasWidgetScrollMethods.scrollCanvasWidgetIntoView;
867
869
  pub const stepCanvasWidgetKineticScroll = CanvasWidgetScrollMethods.stepCanvasWidgetKineticScroll;
868
870
  pub const canvasWidgetScrollContentExtent = CanvasWidgetScrollMethods.canvasWidgetScrollContentExtent;
@@ -981,6 +983,7 @@ pub const RuntimeView = struct {
981
983
  pub const canvasWidgetTopmostAnchoredDismissibleIndex = CanvasWidgetTreeMethods.canvasWidgetTopmostAnchoredDismissibleIndex;
982
984
  pub const canvasWidgetRouteDescendsFromIndex = CanvasWidgetTreeMethods.canvasWidgetRouteDescendsFromIndex;
983
985
  pub const canvasWidgetScopedFocusTarget = CanvasWidgetTreeMethods.canvasWidgetScopedFocusTarget;
986
+ pub const canvasWidgetRovingTabTarget = CanvasWidgetTreeMethods.canvasWidgetRovingTabTarget;
984
987
  pub const canvasWidgetFocusTargetInScope = CanvasWidgetTreeMethods.canvasWidgetFocusTargetInScope;
985
988
  pub const canvasWidgetForwardFocusTargetInScope = CanvasWidgetTreeMethods.canvasWidgetForwardFocusTargetInScope;
986
989
  pub const canvasWidgetBackwardFocusTargetInScope = CanvasWidgetTreeMethods.canvasWidgetBackwardFocusTargetInScope;
@@ -379,6 +379,24 @@ pub fn RuntimeViewCanvasWidgetControl(comptime RuntimeView: type) type {
379
379
  dirty = unionRects(dirty, self.canvasWidgetDirtyBounds(row_index, node.frame));
380
380
  changed = true;
381
381
  }
382
+ } else if (selected and widget.kind == .radio) {
383
+ // A radio group is one logical selection scope even when
384
+ // layout containers wrap its radios. Nearest-ancestor
385
+ // resolution also isolates nested radio groups. A bare
386
+ // radio deliberately falls back to its direct parent.
387
+ const scope = canvas_widget_runtime.canvasWidgetRadioGroupScopeIndex(self.widgetLayoutTree(), index);
388
+ const parent_index = self.widget_layout_nodes[index].parent_index;
389
+ for (self.widget_layout_nodes[0..self.widget_layout_node_count], 0..) |*node, radio_index| {
390
+ if (radio_index == index or node.widget.kind != .radio) continue;
391
+ if (scope) |radio_group_index| {
392
+ if (canvas_widget_runtime.canvasWidgetRadioGroupScopeIndex(self.widgetLayoutTree(), radio_index) != radio_group_index) continue;
393
+ } else if (node.parent_index != parent_index or canvas_widget_runtime.canvasWidgetRadioGroupScopeIndex(self.widgetLayoutTree(), radio_index) != null) continue;
394
+ if (!canvasWidgetSelectableSelected(node.widget)) continue;
395
+ node.widget.state.selected = false;
396
+ node.widget.value = 0;
397
+ dirty = unionRects(dirty, self.canvasWidgetDirtyBounds(radio_index, node.frame));
398
+ changed = true;
399
+ }
382
400
  } else if (selected and canvasWidgetSelectionClearsSiblings(widget.kind)) {
383
401
  const parent_index = self.widget_layout_nodes[index].parent_index;
384
402
  for (self.widget_layout_nodes[0..self.widget_layout_node_count], 0..) |*node, sibling_index| {
@@ -6,6 +6,7 @@ const canvas_widget_runtime = @import("canvas_widget_runtime.zig");
6
6
 
7
7
  const unionRects = canvas_frame_helpers.unionRects;
8
8
  const CanvasWidgetScrollKeyboardTarget = canvas_widget_runtime.CanvasWidgetScrollKeyboardTarget;
9
+ const canvasWidgetClipsContent = canvas_widget_runtime.canvasWidgetClipsContent;
9
10
  const canvasWidgetScrollableKind = canvas_widget_runtime.canvasWidgetScrollableKind;
10
11
  const canvasWidgetSingleLineTextKind = canvas_widget_runtime.canvasWidgetSingleLineTextKind;
11
12
 
@@ -29,6 +30,23 @@ fn unionOptionalRects(a: ?geometry.RectF, b: ?geometry.RectF) ?geometry.RectF {
29
30
  return unionRects(first, second);
30
31
  }
31
32
 
33
+ fn canvasWidgetRevealAxisRequestedDelta(comptime axis: canvas.ScrollAxis, target: geometry.RectF, viewport: geometry.RectF) f32 {
34
+ return switch (axis) {
35
+ .vertical => if (target.y < viewport.y)
36
+ target.y - viewport.y
37
+ else if (target.maxY() > viewport.maxY())
38
+ target.maxY() - viewport.maxY()
39
+ else
40
+ 0,
41
+ .horizontal => if (target.x < viewport.x)
42
+ target.x - viewport.x
43
+ else if (target.maxX() > viewport.maxX())
44
+ target.maxX() - viewport.maxX()
45
+ else
46
+ 0,
47
+ };
48
+ }
49
+
32
50
  pub fn RuntimeViewCanvasWidgetScroll(comptime RuntimeView: type) type {
33
51
  return struct {
34
52
  pub fn canvasWidgetKineticScrollActive(self: *const RuntimeView) bool {
@@ -387,39 +405,39 @@ pub fn RuntimeViewCanvasWidgetScroll(comptime RuntimeView: type) type {
387
405
  /// normal routable focus target in the same key event.
388
406
  pub fn scrollCanvasWidgetIntoView(self: *RuntimeView, id: canvas.ObjectId) anyerror!?geometry.RectF {
389
407
  const target_index = self.canvasWidgetNodeIndexById(id) orelse return null;
408
+ // Prove the whole reveal before mutating the first retained
409
+ // offset. A fixed clip outside a runtime scroll can never be
410
+ // repaired by scrolling an outer ancestor; partially applying
411
+ // that attempt used to jump the viewport (and could clear the
412
+ // old focus) before the caller rejected the still-hidden target.
413
+ if (!canvasWidgetCanScrollIntoView(self, target_index)) return null;
414
+ // The target itself is a hoisted window-level surface. Its
415
+ // authored scroll ancestors neither clip nor translate it, so
416
+ // revealing it must not move the content underneath it.
417
+ if (canvas.widgetEscapesAncestorClips(self.widget_layout_nodes[target_index].widget)) return null;
390
418
  var dirty: ?geometry.RectF = null;
391
419
  var current = self.widget_layout_nodes[target_index].parent_index;
392
420
  while (current) |ancestor_index| {
393
421
  if (ancestor_index >= self.widget_layout_node_count) break;
394
422
  const ancestor = self.widget_layout_nodes[ancestor_index];
395
423
 
396
- // Anchored surfaces escape ancestor clips rather than
424
+ // Window-level surfaces escape ancestor clips rather than
397
425
  // scrolling with their source branch.
398
- if (canvas.widgetIsAnchored(ancestor.widget)) break;
426
+ if (canvas.widgetEscapesAncestorClips(ancestor.widget)) break;
399
427
 
400
428
  if (canvasWidgetScrollableKind(ancestor.widget.kind) and ancestor.widget.kind != .textarea) {
401
429
  const viewport = ancestor.frame.inset(ancestor.widget.layout.padding).normalized();
402
430
  if (!viewport.isEmpty()) {
403
431
  if (canvas.widgetScrollsAxis(ancestor.widget, .vertical)) {
404
432
  const target = self.widget_layout_nodes[target_index].frame.normalized();
405
- const delta_y: f32 = if (target.y < viewport.y)
406
- target.y - viewport.y
407
- else if (target.maxY() > viewport.maxY())
408
- target.maxY() - viewport.maxY()
409
- else
410
- 0;
433
+ const delta_y = canvasWidgetRevealAxisRequestedDelta(.vertical, target, viewport);
411
434
  if (delta_y != 0) {
412
435
  dirty = unionOptionalRects(dirty, try self.applyCanvasWidgetScrollAxis(ancestor_index, .vertical, delta_y, .discrete, false));
413
436
  }
414
437
  }
415
438
  if (canvas.widgetScrollsAxis(ancestor.widget, .horizontal)) {
416
439
  const target = self.widget_layout_nodes[target_index].frame.normalized();
417
- const delta_x: f32 = if (target.x < viewport.x)
418
- target.x - viewport.x
419
- else if (target.maxX() > viewport.maxX())
420
- target.maxX() - viewport.maxX()
421
- else
422
- 0;
440
+ const delta_x = canvasWidgetRevealAxisRequestedDelta(.horizontal, target, viewport);
423
441
  if (delta_x != 0) {
424
442
  dirty = unionOptionalRects(dirty, try self.applyCanvasWidgetScrollAxis(ancestor_index, .horizontal, delta_x, .discrete, false));
425
443
  }
@@ -431,6 +449,79 @@ pub fn RuntimeViewCanvasWidgetScroll(comptime RuntimeView: type) type {
431
449
  return dirty;
432
450
  }
433
451
 
452
+ /// Pure preflight for the fallible focus/reveal sequence. Callers
453
+ /// can validate the entire scroll path before changing platform
454
+ /// focus or retained scroll offsets.
455
+ pub fn canScrollCanvasWidgetIntoView(self: *const RuntimeView, id: canvas.ObjectId) bool {
456
+ const target_index = self.canvasWidgetNodeIndexById(id) orelse return false;
457
+ return canvasWidgetCanScrollIntoView(self, target_index);
458
+ }
459
+
460
+ /// Dry-run `scrollCanvasWidgetIntoView` against one target frame.
461
+ /// Inner scrolls translate the target before each outer clip is
462
+ /// tested, exactly like the live walk, but no retained scroll state,
463
+ /// descendant frame, semantics revision, or pending scroll event is
464
+ /// touched until every clip has proved revealable.
465
+ fn canvasWidgetCanScrollIntoView(self: *const RuntimeView, target_index: usize) bool {
466
+ if (target_index >= self.widget_layout_node_count) return false;
467
+ var target = self.widget_layout_nodes[target_index].frame.normalized();
468
+ if (target.isEmpty()) return false;
469
+
470
+ // A window-level target escapes every ancestor clip at its own
471
+ // tree position. There is therefore nothing to reveal through
472
+ // the authored ancestor chain.
473
+ if (canvas.widgetEscapesAncestorClips(self.widget_layout_nodes[target_index].widget)) return true;
474
+
475
+ var current = self.widget_layout_nodes[target_index].parent_index;
476
+ while (current) |ancestor_index| {
477
+ if (ancestor_index >= self.widget_layout_node_count) break;
478
+ const ancestor = self.widget_layout_nodes[ancestor_index];
479
+
480
+ // Window-level surfaces still clip their own descendants;
481
+ // they only escape clips ABOVE their surface root.
482
+ if (canvas.widgetEscapesAncestorClips(ancestor.widget)) {
483
+ if (canvasWidgetClipsContent(ancestor.widget) and geometry.RectF.intersection(target, ancestor.frame.normalized()).isEmpty()) return false;
484
+ break;
485
+ }
486
+
487
+ if (canvasWidgetScrollableKind(ancestor.widget.kind) and ancestor.widget.kind != .textarea) {
488
+ const viewport = ancestor.frame.inset(ancestor.widget.layout.padding).normalized();
489
+ if (!viewport.isEmpty()) {
490
+ const delta_y = canvasWidgetRevealAxisOffsetDelta(self, ancestor_index, .vertical, target, viewport);
491
+ const delta_x = canvasWidgetRevealAxisOffsetDelta(self, ancestor_index, .horizontal, target, viewport);
492
+ target = target.translate(.{ .dx = -delta_x, .dy = -delta_y });
493
+ }
494
+ }
495
+
496
+ if (canvasWidgetClipsContent(ancestor.widget) and geometry.RectF.intersection(target, ancestor.frame.normalized()).isEmpty()) return false;
497
+ current = ancestor.parent_index;
498
+ }
499
+ return true;
500
+ }
501
+
502
+ fn canvasWidgetRevealAxisOffsetDelta(
503
+ self: *const RuntimeView,
504
+ scroll_index: usize,
505
+ comptime axis: canvas.ScrollAxis,
506
+ target: geometry.RectF,
507
+ viewport: geometry.RectF,
508
+ ) f32 {
509
+ if (scroll_index >= self.widget_layout_node_count) return 0;
510
+ const scroll_node = self.widget_layout_nodes[scroll_index];
511
+ if (canvasWidgetModelDrivenVirtual(scroll_node.widget)) return 0;
512
+ if (!canvas.widgetScrollsAxis(scroll_node.widget, axis)) return 0;
513
+
514
+ const requested = canvasWidgetRevealAxisRequestedDelta(axis, target, viewport);
515
+ if (requested == 0) return 0;
516
+
517
+ const current_axis = self.canvasWidgetScrollState(scroll_index, scroll_node, viewport).axis(axis);
518
+ var next_axis = current_axis;
519
+ next_axis.offset += requested;
520
+ next_axis.velocity = 0;
521
+ next_axis = next_axis.clamped();
522
+ return next_axis.offset - current_axis.offset;
523
+ }
524
+
434
525
  pub fn stepCanvasWidgetKineticScroll(self: *RuntimeView, dt_ms: f32) anyerror!?geometry.RectF {
435
526
  var dirty: ?geometry.RectF = null;
436
527
  var changed = false;
@@ -540,15 +631,18 @@ pub fn RuntimeViewCanvasWidgetScroll(comptime RuntimeView: type) type {
540
631
 
541
632
  /// Scrolled content carries its descendants — INCLUDING floating
542
633
  /// surfaces anchored to widgets inside it (their anchor bases
543
- /// moved) — but a surface anchored to the SCROLL REGION ITSELF
544
- /// stays put: its anchor base is the region's own frame, which
545
- /// never moves when the content under it does.
634
+ /// moved) — but root-relative modal surfaces never ride content,
635
+ /// and a surface anchored to the SCROLL REGION ITSELF stays put:
636
+ /// its anchor base is the region's own frame, which never moves
637
+ /// when the content under it does.
546
638
  pub fn translateCanvasWidgetScrollDescendants(self: *RuntimeView, scroll_index: usize, offset: geometry.OffsetF) void {
547
639
  const scroll_depth = self.widget_layout_nodes[scroll_index].depth;
548
640
  var index = scroll_index + 1;
549
641
  while (index < self.widget_layout_node_count and self.widget_layout_nodes[index].depth > scroll_depth) {
550
642
  const node = self.widget_layout_nodes[index];
551
- if (node.widget.layout.anchor != null and node.parent_index == scroll_index) {
643
+ if (canvas.widgetIsRootRelativeModal(node.widget) or
644
+ node.widget.layout.anchor != null and node.parent_index == scroll_index)
645
+ {
552
646
  const subtree_depth = node.depth;
553
647
  index += 1;
554
648
  while (index < self.widget_layout_node_count and self.widget_layout_nodes[index].depth > subtree_depth) : (index += 1) {}