@native-sdk/cli 0.0.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +176 -0
- package/README.md +50 -1
- package/app.zon +30 -0
- package/assets/icon.icns +0 -0
- package/assets/icon.ico +0 -0
- package/assets/icon.png +0 -0
- package/assets/icon.svg +15 -0
- package/assets/native-sdk.entitlements +10 -0
- package/assets/native-sdk.manifest +12 -0
- package/bin/native.js +156 -0
- package/build/app.zig +716 -0
- package/build.zig +2593 -0
- package/build.zig.zon +24 -0
- package/native-sdk.d.ts +615 -0
- package/package.json +45 -8
- package/skill-data/automation/SKILL.md +248 -0
- package/skill-data/core/SKILL.md +249 -0
- package/skill-data/core/references/app-model-runtime.md +141 -0
- package/skill-data/core/references/bridge-security-native-capabilities.md +230 -0
- package/skill-data/core/references/frontend-assets.md +124 -0
- package/skill-data/core/references/project-anatomy.md +108 -0
- package/skill-data/core/references/web-engines-packaging-debugging.md +199 -0
- package/skill-data/native-ui/SKILL.md +1080 -0
- package/skills/native-sdk/SKILL.md +33 -0
- package/src/app_runner/root.zig +740 -0
- package/src/assets/root.zig +20 -0
- package/src/automation/protocol.zig +285 -0
- package/src/automation/root.zig +13 -0
- package/src/automation/server.zig +506 -0
- package/src/automation/snapshot.zig +1202 -0
- package/src/automation/watcher.zig +165 -0
- package/src/bridge/root.zig +507 -0
- package/src/debug/root.zig +246 -0
- package/src/embed/app_exports.zig +11 -0
- package/src/embed/c_api.zig +793 -0
- package/src/embed/c_exports.zig +10 -0
- package/src/embed/chrome.zig +168 -0
- package/src/embed/conversions.zig +359 -0
- package/src/embed/host.zig +960 -0
- package/src/embed/root.zig +81 -0
- package/src/embed/tests.zig +2552 -0
- package/src/embed/types.zig +382 -0
- package/src/embed/ui_host.zig +289 -0
- package/src/extensions/root.zig +197 -0
- package/src/frontend/root.zig +48 -0
- package/src/js/root.zig +65 -0
- package/src/platform/android/NativeSdkActivity.java +1370 -0
- package/src/platform/android/android_host.c +696 -0
- package/src/platform/android/files.zig +9 -0
- package/src/platform/android/native_sdk_app.h +237 -0
- package/src/platform/ios/files.zig +8 -0
- package/src/platform/ios/native_sdk_app.h +289 -0
- package/src/platform/ios/uikit_host.m +2739 -0
- package/src/platform/linux/cef_host.cpp +599 -0
- package/src/platform/linux/gtk_host.c +5362 -0
- package/src/platform/linux/gtk_host.h +265 -0
- package/src/platform/linux/root.zig +1519 -0
- package/src/platform/macos/appkit_host.h +604 -0
- package/src/platform/macos/appkit_host.m +10392 -0
- package/src/platform/macos/automation_host.h +14 -0
- package/src/platform/macos/automation_host.m +12 -0
- package/src/platform/macos/cef_host.mm +3028 -0
- package/src/platform/macos/root.zig +2260 -0
- package/src/platform/null_platform.zig +2232 -0
- package/src/platform/null_platform_tests.zig +670 -0
- package/src/platform/policy_values.zig +14 -0
- package/src/platform/root.zig +181 -0
- package/src/platform/types.zig +2681 -0
- package/src/platform/windows/cef_host.cpp +3 -0
- package/src/platform/windows/root.zig +1521 -0
- package/src/platform/windows/webview2_host.cpp +6230 -0
- package/src/primitives/app_dirs/root.zig +440 -0
- package/src/primitives/app_manifest/root.zig +109 -0
- package/src/primitives/app_manifest/tests.zig +758 -0
- package/src/primitives/app_manifest/types.zig +587 -0
- package/src/primitives/app_manifest/validation.zig +828 -0
- package/src/primitives/assets/root.zig +520 -0
- package/src/primitives/canvas/a11y_audit.zig +390 -0
- package/src/primitives/canvas/a11y_audit_tests.zig +225 -0
- package/src/primitives/canvas/app_icon.zig +1590 -0
- package/src/primitives/canvas/chart.zig +392 -0
- package/src/primitives/canvas/chart_tests.zig +751 -0
- package/src/primitives/canvas/commands.zig +446 -0
- package/src/primitives/canvas/drawing.zig +309 -0
- package/src/primitives/canvas/equality.zig +316 -0
- package/src/primitives/canvas/events.zig +696 -0
- package/src/primitives/canvas/font_coverage.zig +118 -0
- package/src/primitives/canvas/font_ttf.zig +510 -0
- package/src/primitives/canvas/font_ttf_tests.zig +280 -0
- package/src/primitives/canvas/fonts/Geist-Regular.ttf +0 -0
- package/src/primitives/canvas/fonts/GeistMono-Regular.ttf +0 -0
- package/src/primitives/canvas/frame.zig +679 -0
- package/src/primitives/canvas/frame_metrics.zig +462 -0
- package/src/primitives/canvas/gpu.zig +639 -0
- package/src/primitives/canvas/hash.zig +112 -0
- package/src/primitives/canvas/icons/alert.svg +1 -0
- package/src/primitives/canvas/icons/archive.svg +1 -0
- package/src/primitives/canvas/icons/arrow-down.svg +1 -0
- package/src/primitives/canvas/icons/arrow-right.svg +1 -0
- package/src/primitives/canvas/icons/arrow-up.svg +1 -0
- package/src/primitives/canvas/icons/check-circle.svg +1 -0
- package/src/primitives/canvas/icons/check.svg +1 -0
- package/src/primitives/canvas/icons/chevron-down.svg +1 -0
- package/src/primitives/canvas/icons/chevron-left.svg +1 -0
- package/src/primitives/canvas/icons/chevron-right.svg +1 -0
- package/src/primitives/canvas/icons/chevron-up.svg +1 -0
- package/src/primitives/canvas/icons/circle-dot.svg +1 -0
- package/src/primitives/canvas/icons/clock.svg +1 -0
- package/src/primitives/canvas/icons/copy.svg +1 -0
- package/src/primitives/canvas/icons/download.svg +1 -0
- package/src/primitives/canvas/icons/edit.svg +1 -0
- package/src/primitives/canvas/icons/ellipsis.svg +1 -0
- package/src/primitives/canvas/icons/external-link.svg +1 -0
- package/src/primitives/canvas/icons/eye.svg +1 -0
- package/src/primitives/canvas/icons/file-text.svg +1 -0
- package/src/primitives/canvas/icons/folder-open.svg +1 -0
- package/src/primitives/canvas/icons/folder.svg +1 -0
- package/src/primitives/canvas/icons/git-branch.svg +1 -0
- package/src/primitives/canvas/icons/git-merge.svg +1 -0
- package/src/primitives/canvas/icons/git-pull-request.svg +1 -0
- package/src/primitives/canvas/icons/info.svg +1 -0
- package/src/primitives/canvas/icons/menu.svg +1 -0
- package/src/primitives/canvas/icons/missing.svg +1 -0
- package/src/primitives/canvas/icons/moon.svg +1 -0
- package/src/primitives/canvas/icons/music.svg +1 -0
- package/src/primitives/canvas/icons/panel-left.svg +1 -0
- package/src/primitives/canvas/icons/panel-right.svg +1 -0
- package/src/primitives/canvas/icons/pause.svg +1 -0
- package/src/primitives/canvas/icons/play.svg +1 -0
- package/src/primitives/canvas/icons/plus.svg +1 -0
- package/src/primitives/canvas/icons/refresh-cw.svg +1 -0
- package/src/primitives/canvas/icons/repeat.svg +1 -0
- package/src/primitives/canvas/icons/save.svg +1 -0
- package/src/primitives/canvas/icons/search.svg +1 -0
- package/src/primitives/canvas/icons/send.svg +1 -0
- package/src/primitives/canvas/icons/settings.svg +1 -0
- package/src/primitives/canvas/icons/shuffle.svg +1 -0
- package/src/primitives/canvas/icons/skip-back.svg +1 -0
- package/src/primitives/canvas/icons/skip-forward.svg +1 -0
- package/src/primitives/canvas/icons/sun.svg +1 -0
- package/src/primitives/canvas/icons/terminal.svg +1 -0
- package/src/primitives/canvas/icons/trash.svg +1 -0
- package/src/primitives/canvas/icons/volume.svg +1 -0
- package/src/primitives/canvas/icons/wrench.svg +1 -0
- package/src/primitives/canvas/icons/x-circle.svg +1 -0
- package/src/primitives/canvas/icons/x.svg +1 -0
- package/src/primitives/canvas/icons.zig +249 -0
- package/src/primitives/canvas/layout_audit.zig +744 -0
- package/src/primitives/canvas/layout_audit_tests.zig +426 -0
- package/src/primitives/canvas/markdown.zig +1031 -0
- package/src/primitives/canvas/markdown_hostile_tests.zig +471 -0
- package/src/primitives/canvas/markdown_tests.zig +538 -0
- package/src/primitives/canvas/plan_key_index.zig +120 -0
- package/src/primitives/canvas/png.zig +355 -0
- package/src/primitives/canvas/reference.zig +1457 -0
- package/src/primitives/canvas/reference_blur.zig +104 -0
- package/src/primitives/canvas/reference_memo.zig +322 -0
- package/src/primitives/canvas/reference_paths.zig +184 -0
- package/src/primitives/canvas/reference_tests.zig +1650 -0
- package/src/primitives/canvas/render.zig +747 -0
- package/src/primitives/canvas/render_effects.zig +255 -0
- package/src/primitives/canvas/render_fingerprints.zig +256 -0
- package/src/primitives/canvas/render_generic_resources.zig +376 -0
- package/src/primitives/canvas/render_images.zig +247 -0
- package/src/primitives/canvas/render_layers.zig +260 -0
- package/src/primitives/canvas/render_paths.zig +347 -0
- package/src/primitives/canvas/render_resources.zig +51 -0
- package/src/primitives/canvas/render_tests.zig +3186 -0
- package/src/primitives/canvas/root.zig +744 -0
- package/src/primitives/canvas/serialization.zig +1528 -0
- package/src/primitives/canvas/svg_icon.zig +636 -0
- package/src/primitives/canvas/svg_icon_tests.zig +312 -0
- package/src/primitives/canvas/test_support.zig +422 -0
- package/src/primitives/canvas/testdata/markdown_document.md +83 -0
- package/src/primitives/canvas/tests.zig +30 -0
- package/src/primitives/canvas/text.zig +82 -0
- package/src/primitives/canvas/text_atlas.zig +408 -0
- package/src/primitives/canvas/text_batch_tests.zig +431 -0
- package/src/primitives/canvas/text_interaction.zig +615 -0
- package/src/primitives/canvas/text_layout.zig +1069 -0
- package/src/primitives/canvas/text_layout_cache.zig +281 -0
- package/src/primitives/canvas/text_layout_hash.zig +113 -0
- package/src/primitives/canvas/text_layout_types.zig +128 -0
- package/src/primitives/canvas/text_measure_cache.zig +279 -0
- package/src/primitives/canvas/text_metrics.zig +309 -0
- package/src/primitives/canvas/text_metrics_tests.zig +262 -0
- package/src/primitives/canvas/text_span_tests.zig +608 -0
- package/src/primitives/canvas/text_spans.zig +1010 -0
- package/src/primitives/canvas/text_tests.zig +1949 -0
- package/src/primitives/canvas/themes/geist.zig +470 -0
- package/src/primitives/canvas/tokens.zig +1522 -0
- package/src/primitives/canvas/ui.zig +2686 -0
- package/src/primitives/canvas/ui_markup.zig +3791 -0
- package/src/primitives/canvas/ui_markup_binary.zig +522 -0
- package/src/primitives/canvas/ui_markup_binary_tests.zig +591 -0
- package/src/primitives/canvas/ui_markup_compiled.zig +2565 -0
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +1669 -0
- package/src/primitives/canvas/ui_markup_contract.zig +1620 -0
- package/src/primitives/canvas/ui_markup_contract_tests.zig +953 -0
- package/src/primitives/canvas/ui_markup_edit.zig +416 -0
- package/src/primitives/canvas/ui_markup_edit_tests.zig +341 -0
- package/src/primitives/canvas/ui_markup_expr.zig +1152 -0
- package/src/primitives/canvas/ui_markup_expr_tests.zig +779 -0
- package/src/primitives/canvas/ui_markup_huge_model_tests.zig +505 -0
- package/src/primitives/canvas/ui_markup_reflect.zig +127 -0
- package/src/primitives/canvas/ui_markup_tests.zig +1545 -0
- package/src/primitives/canvas/ui_markup_view.zig +2352 -0
- package/src/primitives/canvas/ui_markup_view_tests.zig +3709 -0
- package/src/primitives/canvas/ui_provenance.zig +96 -0
- package/src/primitives/canvas/ui_provenance_tests.zig +186 -0
- package/src/primitives/canvas/ui_schema.zig +825 -0
- package/src/primitives/canvas/ui_schema_tests.zig +128 -0
- package/src/primitives/canvas/ui_tests.zig +1432 -0
- package/src/primitives/canvas/vector.zig +919 -0
- package/src/primitives/canvas/vector_tests.zig +547 -0
- package/src/primitives/canvas/virtual_extent_tests.zig +317 -0
- package/src/primitives/canvas/virtual_extents.zig +540 -0
- package/src/primitives/canvas/widget_access.zig +208 -0
- package/src/primitives/canvas/widget_anchored_tests.zig +264 -0
- package/src/primitives/canvas/widget_builtin_tests.zig +3160 -0
- package/src/primitives/canvas/widget_invalidation.zig +748 -0
- package/src/primitives/canvas/widget_layout.zig +2055 -0
- package/src/primitives/canvas/widget_layout_tests.zig +2691 -0
- package/src/primitives/canvas/widget_metrics.zig +228 -0
- package/src/primitives/canvas/widget_render.zig +2534 -0
- package/src/primitives/canvas/widget_render_controls.zig +1563 -0
- package/src/primitives/canvas/widget_render_scroll.zig +136 -0
- package/src/primitives/canvas/widget_render_style.zig +626 -0
- package/src/primitives/canvas/widget_render_surfaces.zig +794 -0
- package/src/primitives/canvas/widget_routing.zig +475 -0
- package/src/primitives/canvas/widget_runtime.zig +307 -0
- package/src/primitives/canvas/widget_runtime_tests.zig +3015 -0
- package/src/primitives/canvas/widget_semantics.zig +480 -0
- package/src/primitives/canvas/widget_semantics_tests.zig +2129 -0
- package/src/primitives/canvas/widget_tests.zig +8 -0
- package/src/primitives/canvas/widget_text_input.zig +351 -0
- package/src/primitives/canvas/widget_text_select.zig +147 -0
- package/src/primitives/canvas/widget_tree.zig +232 -0
- package/src/primitives/canvas/widgets.zig +1319 -0
- package/src/primitives/diagnostics/root.zig +445 -0
- package/src/primitives/geometry/root.zig +889 -0
- package/src/primitives/json/root.zig +272 -0
- package/src/primitives/platform_info/root.zig +450 -0
- package/src/primitives/trace/root.zig +569 -0
- package/src/root.zig +165 -0
- package/src/runtime/api.zig +431 -0
- package/src/runtime/async_bridge.zig +49 -0
- package/src/runtime/automation_commands.zig +686 -0
- package/src/runtime/automation_liveness_tests.zig +140 -0
- package/src/runtime/automation_snapshot.zig +246 -0
- package/src/runtime/automation_widget_dispatch.zig +617 -0
- package/src/runtime/bridge_dispatch_tests.zig +202 -0
- package/src/runtime/bridge_payload.zig +194 -0
- package/src/runtime/bridge_permission_tests.zig +551 -0
- package/src/runtime/bridge_responses.zig +414 -0
- package/src/runtime/builtin_bridge.zig +554 -0
- package/src/runtime/canvas_budget_edge_tests.zig +415 -0
- package/src/runtime/canvas_font_tests.zig +410 -0
- package/src/runtime/canvas_fonts.zig +229 -0
- package/src/runtime/canvas_frame.zig +1734 -0
- package/src/runtime/canvas_frame_animation_tests.zig +609 -0
- package/src/runtime/canvas_frame_cache_tests.zig +333 -0
- package/src/runtime/canvas_frame_helpers.zig +414 -0
- package/src/runtime/canvas_frame_invalidation_tests.zig +544 -0
- package/src/runtime/canvas_frame_packet_tests.zig +1353 -0
- package/src/runtime/canvas_frame_patch_tests.zig +1051 -0
- package/src/runtime/canvas_frame_retained_tests.zig +753 -0
- package/src/runtime/canvas_frame_tests.zig +9 -0
- package/src/runtime/canvas_frame_text_layout_budget_tests.zig +149 -0
- package/src/runtime/canvas_image_tests.zig +362 -0
- package/src/runtime/canvas_images.zig +224 -0
- package/src/runtime/canvas_limits.zig +317 -0
- package/src/runtime/canvas_screenshot_tests.zig +289 -0
- package/src/runtime/canvas_widget_accessibility_tests.zig +1494 -0
- package/src/runtime/canvas_widget_anchored_tests.zig +678 -0
- package/src/runtime/canvas_widget_chart_tests.zig +249 -0
- package/src/runtime/canvas_widget_clipboard_tests.zig +399 -0
- package/src/runtime/canvas_widget_context_menu.zig +318 -0
- package/src/runtime/canvas_widget_context_menu_tests.zig +462 -0
- package/src/runtime/canvas_widget_control_tests.zig +2164 -0
- package/src/runtime/canvas_widget_disclosure_tests.zig +440 -0
- package/src/runtime/canvas_widget_display.zig +677 -0
- package/src/runtime/canvas_widget_event_tests.zig +1779 -0
- package/src/runtime/canvas_widget_events.zig +1098 -0
- package/src/runtime/canvas_widget_floating_tests.zig +695 -0
- package/src/runtime/canvas_widget_layout_tests.zig +26 -0
- package/src/runtime/canvas_widget_runtime.zig +1335 -0
- package/src/runtime/canvas_widget_scroll_driver_tests.zig +582 -0
- package/src/runtime/canvas_widget_scroll_drivers.zig +202 -0
- package/src/runtime/canvas_widget_scroll_tests.zig +1549 -0
- package/src/runtime/canvas_widget_semantics_tests.zig +810 -0
- package/src/runtime/canvas_widget_split_tree_tests.zig +1031 -0
- package/src/runtime/canvas_widget_state.zig +798 -0
- package/src/runtime/canvas_widget_text_tests.zig +2104 -0
- package/src/runtime/canvas_widget_window_drag_tests.zig +284 -0
- package/src/runtime/clock.zig +231 -0
- package/src/runtime/core.zig +927 -0
- package/src/runtime/effects.zig +4197 -0
- package/src/runtime/effects_audio_tests.zig +690 -0
- package/src/runtime/effects_clipboard_tests.zig +317 -0
- package/src/runtime/effects_fetch_tests.zig +1031 -0
- package/src/runtime/effects_file_tests.zig +407 -0
- package/src/runtime/effects_tests.zig +1251 -0
- package/src/runtime/flow.zig +1175 -0
- package/src/runtime/frame_profile.zig +221 -0
- package/src/runtime/gpu_surface_events.zig +639 -0
- package/src/runtime/launch_timing.zig +59 -0
- package/src/runtime/markdown_app_tests.zig +224 -0
- package/src/runtime/native_command_event_tests.zig +431 -0
- package/src/runtime/platform_bridge_tests.zig +8 -0
- package/src/runtime/platform_config_tests.zig +392 -0
- package/src/runtime/root.zig +150 -0
- package/src/runtime/runtime_event_tests.zig +1079 -0
- package/src/runtime/session_journal.zig +1522 -0
- package/src/runtime/session_record.zig +332 -0
- package/src/runtime/session_replay.zig +274 -0
- package/src/runtime/session_state.zig +30 -0
- package/src/runtime/session_tests.zig +399 -0
- package/src/runtime/shell_layout.zig +472 -0
- package/src/runtime/shell_layout_tests.zig +1246 -0
- package/src/runtime/shell_view_tests.zig +604 -0
- package/src/runtime/state.zig +110 -0
- package/src/runtime/system_services.zig +392 -0
- package/src/runtime/test_support.zig +79 -0
- package/src/runtime/tests.zig +30 -0
- package/src/runtime/ui_app.zig +3290 -0
- package/src/runtime/ui_app_huge_model_tests.zig +351 -0
- package/src/runtime/ui_app_provenance.zig +370 -0
- package/src/runtime/ui_app_tests.zig +3254 -0
- package/src/runtime/ui_app_virtual_variable_tests.zig +485 -0
- package/src/runtime/ui_app_window_tests.zig +442 -0
- package/src/runtime/validation.zig +206 -0
- package/src/runtime/view.zig +908 -0
- package/src/runtime/view_canvas.zig +850 -0
- package/src/runtime/view_widget_control.zig +433 -0
- package/src/runtime/view_widget_scroll.zig +360 -0
- package/src/runtime/view_widget_text.zig +275 -0
- package/src/runtime/view_widget_tree.zig +843 -0
- package/src/runtime/webview_view_bridge_tests.zig +664 -0
- package/src/runtime/widget_bridge.zig +231 -0
- package/src/runtime/window_command_bridge_tests.zig +403 -0
- package/src/runtime/window_storage.zig +255 -0
- package/src/runtime/window_view_runtime.zig +727 -0
- package/src/runtime/window_views.zig +334 -0
- package/src/security/root.zig +118 -0
- package/src/tooling/android.zig +1172 -0
- package/src/tooling/assets.zig +128 -0
- package/src/tooling/buildgraph.zig +379 -0
- package/src/tooling/cef.zig +671 -0
- package/src/tooling/codesign.zig +172 -0
- package/src/tooling/components/identity_tests.zig +185 -0
- package/src/tooling/components/stepper.zig +113 -0
- package/src/tooling/components/timeline.native +27 -0
- package/src/tooling/components/timeline_item.zig +131 -0
- package/src/tooling/default_icon.icns +0 -0
- package/src/tooling/default_icon.png +0 -0
- package/src/tooling/dev.zig +172 -0
- package/src/tooling/doctor.zig +349 -0
- package/src/tooling/eject_components.zig +170 -0
- package/src/tooling/embedlib.zig +290 -0
- package/src/tooling/ios.zig +528 -0
- package/src/tooling/manifest.zig +1939 -0
- package/src/tooling/package.zig +2388 -0
- package/src/tooling/process_tree.zig +114 -0
- package/src/tooling/raw_manifest.zig +193 -0
- package/src/tooling/root.zig +22 -0
- package/src/tooling/templates.zig +3191 -0
- package/src/tooling/toolchain.zig +371 -0
- package/src/tooling/verbs.zig +204 -0
- package/src/tooling/web_engine.zig +135 -0
- package/src/tooling/xcodeproj.zig +462 -0
- package/src/window_state/root.zig +507 -0
- package/index.js +0 -2
|
@@ -0,0 +1,1549 @@
|
|
|
1
|
+
const support = @import("test_support.zig");
|
|
2
|
+
const std = support.std;
|
|
3
|
+
const geometry = support.geometry;
|
|
4
|
+
const trace = support.trace;
|
|
5
|
+
const json = support.json;
|
|
6
|
+
const canvas = support.canvas;
|
|
7
|
+
const automation = support.automation;
|
|
8
|
+
const bridge = support.bridge;
|
|
9
|
+
const app_manifest = support.app_manifest;
|
|
10
|
+
const platform = support.platform;
|
|
11
|
+
const security = support.security;
|
|
12
|
+
const extensions = support.extensions;
|
|
13
|
+
const window_state = support.window_state;
|
|
14
|
+
const runtime_module = support.runtime_module;
|
|
15
|
+
const bridge_payload = support.bridge_payload;
|
|
16
|
+
const canvas_frame = support.canvas_frame;
|
|
17
|
+
const App = support.App;
|
|
18
|
+
const Runtime = support.Runtime;
|
|
19
|
+
const Options = support.Options;
|
|
20
|
+
const Event = support.Event;
|
|
21
|
+
const LifecycleEvent = support.LifecycleEvent;
|
|
22
|
+
const CommandEvent = support.CommandEvent;
|
|
23
|
+
const Command = support.Command;
|
|
24
|
+
const CommandSource = support.CommandSource;
|
|
25
|
+
const FrameDiagnostics = support.FrameDiagnostics;
|
|
26
|
+
const ShortcutEvent = support.ShortcutEvent;
|
|
27
|
+
const Appearance = support.Appearance;
|
|
28
|
+
const GpuFrame = support.GpuFrame;
|
|
29
|
+
const GpuSurfaceFrameEvent = support.GpuSurfaceFrameEvent;
|
|
30
|
+
const GpuSurfaceResizeEvent = support.GpuSurfaceResizeEvent;
|
|
31
|
+
const GpuSurfaceInputEvent = support.GpuSurfaceInputEvent;
|
|
32
|
+
const CanvasWidgetPointerEvent = support.CanvasWidgetPointerEvent;
|
|
33
|
+
const CanvasWidgetKeyboardEvent = support.CanvasWidgetKeyboardEvent;
|
|
34
|
+
const CanvasWidgetDisplayListChrome = support.CanvasWidgetDisplayListChrome;
|
|
35
|
+
const CanvasPresentationMode = support.CanvasPresentationMode;
|
|
36
|
+
const CanvasPresentationResult = support.CanvasPresentationResult;
|
|
37
|
+
const CanvasWidgetAccessibilityActionKind = support.CanvasWidgetAccessibilityActionKind;
|
|
38
|
+
const CanvasWidgetAccessibilityAction = support.CanvasWidgetAccessibilityAction;
|
|
39
|
+
const CanvasWidgetFileDropEvent = support.CanvasWidgetFileDropEvent;
|
|
40
|
+
const CanvasWidgetDragEvent = support.CanvasWidgetDragEvent;
|
|
41
|
+
const InvalidationReason = support.InvalidationReason;
|
|
42
|
+
const TestHarness = support.TestHarness;
|
|
43
|
+
const max_canvas_commands_per_view = support.max_canvas_commands_per_view;
|
|
44
|
+
const max_canvas_widget_nodes_per_view = support.max_canvas_widget_nodes_per_view;
|
|
45
|
+
const jsonStringField = support.jsonStringField;
|
|
46
|
+
const jsonNumberField = support.jsonNumberField;
|
|
47
|
+
const jsonBoolField = support.jsonBoolField;
|
|
48
|
+
const canvasRenderAnimationFinalOverrideNoop = support.canvasRenderAnimationFinalOverrideNoop;
|
|
49
|
+
const copyInto = support.copyInto;
|
|
50
|
+
const writeViewJson = support.writeViewJson;
|
|
51
|
+
const canvasFrameScratchStorage = support.canvasFrameScratchStorage;
|
|
52
|
+
const runtimeViewInfo = support.runtimeViewInfo;
|
|
53
|
+
const runtimeViewCanvasFrameRenderOverrides = support.runtimeViewCanvasFrameRenderOverrides;
|
|
54
|
+
const runtimeViewCanvasRenderAnimationDirtyBoundsForOverrides = support.runtimeViewCanvasRenderAnimationDirtyBoundsForOverrides;
|
|
55
|
+
const runtimeViewWidgetSemantics = support.runtimeViewWidgetSemantics;
|
|
56
|
+
const runtimeViewSetCanvasWidgetSelected = support.runtimeViewSetCanvasWidgetSelected;
|
|
57
|
+
const runtimeViewCanvasWidgetDirtyBounds = support.runtimeViewCanvasWidgetDirtyBounds;
|
|
58
|
+
const dispatchAutomationWidgetAction = support.dispatchAutomationWidgetAction;
|
|
59
|
+
const shellBoundsForWindow = support.shellBoundsForWindow;
|
|
60
|
+
const reloadWindows = support.reloadWindows;
|
|
61
|
+
const canvasWidgetSemanticsById = support.canvasWidgetSemanticsById;
|
|
62
|
+
const platformWidgetAccessibilityNodeById = support.platformWidgetAccessibilityNodeById;
|
|
63
|
+
const builtinBridgeErrorCode = support.builtinBridgeErrorCode;
|
|
64
|
+
const builtinBridgeErrorMessage = support.builtinBridgeErrorMessage;
|
|
65
|
+
const testViewByLabel = support.testViewByLabel;
|
|
66
|
+
const testCanvasWidgetPartId = support.testCanvasWidgetPartId;
|
|
67
|
+
|
|
68
|
+
test "runtime retains canvas widget design tokens" {
|
|
69
|
+
const TestApp = struct {
|
|
70
|
+
fn app(self: *@This()) App {
|
|
71
|
+
return .{ .context = self, .name = "gpu-widget-design-tokens", .source = platform.WebViewSource.html("<h1>Hello</h1>") };
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
76
|
+
defer harness.destroy(std.testing.allocator);
|
|
77
|
+
harness.null_platform.gpu_surfaces = true;
|
|
78
|
+
var app_state: TestApp = .{};
|
|
79
|
+
try harness.start(app_state.app());
|
|
80
|
+
|
|
81
|
+
_ = try harness.runtime.createView(.{
|
|
82
|
+
.window_id = 1,
|
|
83
|
+
.label = "canvas",
|
|
84
|
+
.kind = .gpu_surface,
|
|
85
|
+
.frame = geometry.RectF.init(0, 0, 240, 120),
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
const button = canvas.Widget{
|
|
89
|
+
.id = 2,
|
|
90
|
+
.kind = .button,
|
|
91
|
+
.frame = geometry.RectF.init(10, 12, 96, 32),
|
|
92
|
+
.text = "Run",
|
|
93
|
+
.state = .{ .selected = true },
|
|
94
|
+
};
|
|
95
|
+
var nodes: [2]canvas.WidgetLayoutNode = undefined;
|
|
96
|
+
const layout = try canvas.layoutWidgetTree(.{ .kind = .stack, .children = &.{button} }, geometry.RectF.init(0, 0, 240, 120), &nodes);
|
|
97
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
98
|
+
|
|
99
|
+
const tokens = canvas.DesignTokens{
|
|
100
|
+
.colors = .{
|
|
101
|
+
.accent = canvas.Color.rgb8(100, 20, 200),
|
|
102
|
+
.accent_text = canvas.Color.rgb8(255, 250, 240),
|
|
103
|
+
},
|
|
104
|
+
.radius = .{ .md = 7 },
|
|
105
|
+
};
|
|
106
|
+
harness.runtime.invalidated = false;
|
|
107
|
+
harness.runtime.dirty_region_count = 0;
|
|
108
|
+
const themed = try harness.runtime.setCanvasWidgetDesignTokens(1, "canvas", tokens);
|
|
109
|
+
try std.testing.expectEqual(@as(u64, 2), themed.widget_revision);
|
|
110
|
+
try std.testing.expectEqualDeep(tokens, try harness.runtime.canvasWidgetDesignTokens(1, "canvas"));
|
|
111
|
+
try std.testing.expect(!harness.runtime.invalidated);
|
|
112
|
+
try std.testing.expectEqual(@as(usize, 0), harness.runtime.pendingDirtyRegions().len);
|
|
113
|
+
|
|
114
|
+
harness.runtime.invalidated = false;
|
|
115
|
+
harness.runtime.dirty_region_count = 0;
|
|
116
|
+
const unchanged = try harness.runtime.setCanvasWidgetDesignTokens(1, "canvas", tokens);
|
|
117
|
+
try std.testing.expectEqual(@as(u64, 2), unchanged.widget_revision);
|
|
118
|
+
try std.testing.expect(!harness.runtime.invalidated);
|
|
119
|
+
try std.testing.expectEqual(@as(usize, 0), harness.runtime.pendingDirtyRegions().len);
|
|
120
|
+
|
|
121
|
+
_ = try harness.runtime.emitCanvasWidgetDisplayListWithStoredTokens(1, "canvas");
|
|
122
|
+
const display_list = try harness.runtime.canvasDisplayList(1, "canvas");
|
|
123
|
+
var saw_accent_fill = false;
|
|
124
|
+
var saw_accent_text = false;
|
|
125
|
+
for (display_list.commands) |command| {
|
|
126
|
+
switch (command) {
|
|
127
|
+
.fill_rounded_rect => |fill| {
|
|
128
|
+
if (fill.id == testCanvasWidgetPartId(2, 1)) {
|
|
129
|
+
switch (fill.fill) {
|
|
130
|
+
.color => |color| try std.testing.expectEqualDeep(tokens.colors.accent, color),
|
|
131
|
+
else => return error.TestUnexpectedResult,
|
|
132
|
+
}
|
|
133
|
+
saw_accent_fill = true;
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
.draw_text => |text| {
|
|
137
|
+
if (text.id == testCanvasWidgetPartId(2, 4)) {
|
|
138
|
+
try std.testing.expectEqualDeep(tokens.colors.accent_text, text.color);
|
|
139
|
+
saw_accent_text = true;
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
else => {},
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
try std.testing.expect(saw_accent_fill);
|
|
146
|
+
try std.testing.expect(saw_accent_text);
|
|
147
|
+
|
|
148
|
+
const next_tokens = canvas.DesignTokens{
|
|
149
|
+
.colors = .{
|
|
150
|
+
.accent = canvas.Color.rgb8(20, 120, 80),
|
|
151
|
+
.accent_text = canvas.Color.rgb8(240, 255, 250),
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
harness.runtime.invalidated = false;
|
|
155
|
+
harness.runtime.dirty_region_count = 0;
|
|
156
|
+
const changed = try harness.runtime.setCanvasWidgetDesignTokens(1, "canvas", next_tokens);
|
|
157
|
+
try std.testing.expectEqual(@as(u64, 3), changed.widget_revision);
|
|
158
|
+
try std.testing.expect(harness.runtime.invalidated);
|
|
159
|
+
try std.testing.expect(harness.runtime.pendingDirtyRegions().len >= 1);
|
|
160
|
+
_ = try harness.runtime.emitCanvasWidgetDisplayListWithStoredTokens(1, "canvas");
|
|
161
|
+
const changed_display_list = try harness.runtime.canvasDisplayList(1, "canvas");
|
|
162
|
+
for (changed_display_list.commands) |command| {
|
|
163
|
+
switch (command) {
|
|
164
|
+
.fill_rounded_rect => |fill| {
|
|
165
|
+
if (fill.id == testCanvasWidgetPartId(2, 1)) {
|
|
166
|
+
switch (fill.fill) {
|
|
167
|
+
.color => |color| try std.testing.expectEqualDeep(next_tokens.colors.accent, color),
|
|
168
|
+
else => return error.TestUnexpectedResult,
|
|
169
|
+
}
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
else => {},
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return error.TestUnexpectedResult;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
test "runtime dispatches canvas widget scroll events for wheel and kinetic scrolls" {
|
|
180
|
+
const TestApp = struct {
|
|
181
|
+
scroll_event_count: u32 = 0,
|
|
182
|
+
last_id: canvas.ObjectId = 0,
|
|
183
|
+
last_scroll: canvas.ScrollState = .{},
|
|
184
|
+
|
|
185
|
+
fn app(self: *@This()) App {
|
|
186
|
+
return .{ .context = self, .name = "gpu-widget-scroll-events", .source = platform.WebViewSource.html("<h1>Hello</h1>"), .event_fn = event };
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
fn event(context: *anyopaque, runtime: *Runtime, event_value: Event) anyerror!void {
|
|
190
|
+
_ = runtime;
|
|
191
|
+
const self: *@This() = @ptrCast(@alignCast(context));
|
|
192
|
+
switch (event_value) {
|
|
193
|
+
.canvas_widget_scroll => |scroll_event| {
|
|
194
|
+
self.scroll_event_count += 1;
|
|
195
|
+
self.last_id = scroll_event.id;
|
|
196
|
+
self.last_scroll = scroll_event.scroll;
|
|
197
|
+
},
|
|
198
|
+
else => {},
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
204
|
+
defer harness.destroy(std.testing.allocator);
|
|
205
|
+
harness.null_platform.gpu_surfaces = true;
|
|
206
|
+
var app_state: TestApp = .{};
|
|
207
|
+
const app = app_state.app();
|
|
208
|
+
try harness.start(app);
|
|
209
|
+
|
|
210
|
+
_ = try harness.runtime.createView(.{
|
|
211
|
+
.window_id = 1,
|
|
212
|
+
.label = "canvas",
|
|
213
|
+
.kind = .gpu_surface,
|
|
214
|
+
.frame = geometry.RectF.init(10, 20, 180, 72),
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
const children = [_]canvas.Widget{
|
|
218
|
+
.{ .id = 2, .kind = .button, .frame = geometry.RectF.init(0, 0, 0, 32), .text = "One" },
|
|
219
|
+
.{ .id = 3, .kind = .button, .frame = geometry.RectF.init(0, 44, 0, 32), .text = "Two" },
|
|
220
|
+
.{ .id = 4, .kind = .button, .frame = geometry.RectF.init(0, 88, 0, 32), .text = "Three" },
|
|
221
|
+
};
|
|
222
|
+
const scroll = canvas.Widget{
|
|
223
|
+
.id = 1,
|
|
224
|
+
.kind = .scroll_view,
|
|
225
|
+
.children = &children,
|
|
226
|
+
};
|
|
227
|
+
var nodes: [5]canvas.WidgetLayoutNode = undefined;
|
|
228
|
+
const layout = try canvas.layoutWidgetTree(scroll, geometry.RectF.init(0, 0, 180, 72), &nodes);
|
|
229
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
230
|
+
|
|
231
|
+
// A wheel gesture delivers one canvas_widget_scroll event carrying
|
|
232
|
+
// the post-scroll state: the applied offset plus the viewport and
|
|
233
|
+
// content extents an app needs to page or lazy-load.
|
|
234
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
235
|
+
.window_id = 1,
|
|
236
|
+
.label = "canvas",
|
|
237
|
+
.timestamp_ns = 1_000_000_000,
|
|
238
|
+
.kind = .scroll,
|
|
239
|
+
.x = 20,
|
|
240
|
+
.y = 20,
|
|
241
|
+
.delta_y = 24,
|
|
242
|
+
} });
|
|
243
|
+
|
|
244
|
+
try std.testing.expectEqual(@as(u32, 1), app_state.scroll_event_count);
|
|
245
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 1), app_state.last_id);
|
|
246
|
+
try std.testing.expectEqual(@as(f32, 24), app_state.last_scroll.offset);
|
|
247
|
+
try std.testing.expectEqual(@as(f32, 72), app_state.last_scroll.viewport_extent);
|
|
248
|
+
try std.testing.expectEqual(@as(f32, 120), app_state.last_scroll.content_extent);
|
|
249
|
+
try std.testing.expectEqual(@as(f32, 48), app_state.last_scroll.maxOffset());
|
|
250
|
+
|
|
251
|
+
// The wheel left momentum; the first frame after input skips the
|
|
252
|
+
// kinetic step (pending-input frame), the second one steps it and
|
|
253
|
+
// delivers a fresh event with the advanced offset.
|
|
254
|
+
try std.testing.expect(harness.runtime.views[0].widget_scroll_states[0].velocity > 0);
|
|
255
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_frame = .{
|
|
256
|
+
.window_id = 1,
|
|
257
|
+
.label = "canvas",
|
|
258
|
+
.size = geometry.SizeF.init(180, 72),
|
|
259
|
+
.scale_factor = 1,
|
|
260
|
+
.frame_index = 1,
|
|
261
|
+
.timestamp_ns = 1_016_000_000,
|
|
262
|
+
.frame_interval_ns = 16_000_000,
|
|
263
|
+
} });
|
|
264
|
+
try std.testing.expectEqual(@as(u32, 1), app_state.scroll_event_count);
|
|
265
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_frame = .{
|
|
266
|
+
.window_id = 1,
|
|
267
|
+
.label = "canvas",
|
|
268
|
+
.size = geometry.SizeF.init(180, 72),
|
|
269
|
+
.scale_factor = 1,
|
|
270
|
+
.frame_index = 2,
|
|
271
|
+
.timestamp_ns = 1_032_000_000,
|
|
272
|
+
.frame_interval_ns = 16_000_000,
|
|
273
|
+
} });
|
|
274
|
+
try std.testing.expectEqual(@as(u32, 2), app_state.scroll_event_count);
|
|
275
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 1), app_state.last_id);
|
|
276
|
+
try std.testing.expect(app_state.last_scroll.offset > 24);
|
|
277
|
+
try std.testing.expectEqual(
|
|
278
|
+
harness.runtime.views[0].widget_layout_nodes[0].widget.value,
|
|
279
|
+
app_state.last_scroll.offset,
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
test "runtime wheel input scrolls retained canvas scroll views" {
|
|
284
|
+
const TestApp = struct {
|
|
285
|
+
widget_pointer_count: u32 = 0,
|
|
286
|
+
raw_input_count: u32 = 0,
|
|
287
|
+
last_phase: canvas.WidgetPointerPhase = .hover,
|
|
288
|
+
last_target_id: canvas.ObjectId = 0,
|
|
289
|
+
|
|
290
|
+
fn app(self: *@This()) App {
|
|
291
|
+
return .{ .context = self, .name = "gpu-widget-scroll", .source = platform.WebViewSource.html("<h1>Hello</h1>"), .event_fn = event };
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
fn event(context: *anyopaque, runtime: *Runtime, event_value: Event) anyerror!void {
|
|
295
|
+
_ = runtime;
|
|
296
|
+
const self: *@This() = @ptrCast(@alignCast(context));
|
|
297
|
+
switch (event_value) {
|
|
298
|
+
.canvas_widget_pointer => |pointer_event| {
|
|
299
|
+
self.widget_pointer_count += 1;
|
|
300
|
+
self.last_phase = pointer_event.pointer.phase;
|
|
301
|
+
self.last_target_id = if (pointer_event.target) |target| target.id else 0;
|
|
302
|
+
},
|
|
303
|
+
.gpu_surface_input => self.raw_input_count += 1,
|
|
304
|
+
else => {},
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
310
|
+
defer harness.destroy(std.testing.allocator);
|
|
311
|
+
harness.null_platform.gpu_surfaces = true;
|
|
312
|
+
var app_state: TestApp = .{};
|
|
313
|
+
const app = app_state.app();
|
|
314
|
+
try harness.start(app);
|
|
315
|
+
|
|
316
|
+
_ = try harness.runtime.createView(.{
|
|
317
|
+
.window_id = 1,
|
|
318
|
+
.label = "canvas",
|
|
319
|
+
.kind = .gpu_surface,
|
|
320
|
+
.frame = geometry.RectF.init(10, 20, 180, 72),
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
const children = [_]canvas.Widget{
|
|
324
|
+
.{ .id = 2, .kind = .button, .frame = geometry.RectF.init(0, 0, 0, 32), .text = "One" },
|
|
325
|
+
.{ .id = 3, .kind = .button, .frame = geometry.RectF.init(0, 44, 0, 32), .text = "Two" },
|
|
326
|
+
.{ .id = 4, .kind = .button, .frame = geometry.RectF.init(0, 88, 0, 32), .text = "Three" },
|
|
327
|
+
};
|
|
328
|
+
const scroll = canvas.Widget{
|
|
329
|
+
.id = 1,
|
|
330
|
+
.kind = .scroll_view,
|
|
331
|
+
.children = &children,
|
|
332
|
+
};
|
|
333
|
+
var nodes: [5]canvas.WidgetLayoutNode = undefined;
|
|
334
|
+
const layout = try canvas.layoutWidgetTree(scroll, geometry.RectF.init(0, 0, 180, 72), &nodes);
|
|
335
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
336
|
+
|
|
337
|
+
harness.runtime.invalidated = false;
|
|
338
|
+
harness.runtime.dirty_region_count = 0;
|
|
339
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
340
|
+
.window_id = 1,
|
|
341
|
+
.label = "canvas",
|
|
342
|
+
.timestamp_ns = 1_000_000_000,
|
|
343
|
+
.kind = .scroll,
|
|
344
|
+
.x = 20,
|
|
345
|
+
.y = 20,
|
|
346
|
+
.delta_y = 24,
|
|
347
|
+
} });
|
|
348
|
+
|
|
349
|
+
try std.testing.expectEqual(@as(u32, 1), app_state.widget_pointer_count);
|
|
350
|
+
try std.testing.expectEqual(@as(u32, 1), app_state.raw_input_count);
|
|
351
|
+
try std.testing.expectEqual(canvas.WidgetPointerPhase.wheel, app_state.last_phase);
|
|
352
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), app_state.last_target_id);
|
|
353
|
+
try std.testing.expect(harness.runtime.invalidated);
|
|
354
|
+
try std.testing.expectEqual(@as(usize, 1), harness.runtime.pendingDirtyRegions().len);
|
|
355
|
+
try std.testing.expectEqualDeep(geometry.RectF.init(10, 20, 180, 72), harness.runtime.pendingDirtyRegions()[0]);
|
|
356
|
+
|
|
357
|
+
const retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
358
|
+
try std.testing.expectEqual(@as(f32, 24), retained.nodes[0].widget.value);
|
|
359
|
+
try std.testing.expectEqualDeep(geometry.RectF.init(0, -24, 180, 32), retained.nodes[1].frame);
|
|
360
|
+
try std.testing.expectEqualDeep(geometry.RectF.init(0, 20, 180, 32), retained.nodes[2].frame);
|
|
361
|
+
try std.testing.expectEqualDeep(geometry.RectF.init(0, 64, 180, 32), retained.nodes[3].frame);
|
|
362
|
+
try std.testing.expectEqual(@as(u64, 2), harness.runtime.views[0].widget_revision);
|
|
363
|
+
|
|
364
|
+
const snapshot = harness.runtime.automationSnapshot("Widgets");
|
|
365
|
+
try std.testing.expectEqual(@as(usize, 4), snapshot.widgets.len);
|
|
366
|
+
try std.testing.expectEqual(@as(?f32, 0.5), snapshot.widgets[0].value);
|
|
367
|
+
try std.testing.expect(snapshot.widgets[0].scroll.present);
|
|
368
|
+
try std.testing.expectEqual(@as(f32, 24.0), snapshot.widgets[0].scroll.offset);
|
|
369
|
+
try std.testing.expectEqual(@as(f32, 72.0), snapshot.widgets[0].scroll.viewport_extent);
|
|
370
|
+
try std.testing.expectEqual(@as(f32, 120.0), snapshot.widgets[0].scroll.content_extent);
|
|
371
|
+
try std.testing.expect(snapshot.widgets[0].actions.focus);
|
|
372
|
+
try std.testing.expect(snapshot.widgets[0].actions.increment);
|
|
373
|
+
try std.testing.expect(snapshot.widgets[0].actions.decrement);
|
|
374
|
+
try std.testing.expectEqualDeep(geometry.RectF.init(10, -4, 180, 32), snapshot.widgets[1].bounds);
|
|
375
|
+
try std.testing.expectEqualDeep(geometry.RectF.init(10, 40, 180, 32), snapshot.widgets[2].bounds);
|
|
376
|
+
|
|
377
|
+
var a11y_buffer: [2048]u8 = undefined;
|
|
378
|
+
var a11y_writer = std.Io.Writer.fixed(&a11y_buffer);
|
|
379
|
+
try automation.snapshot.writeA11yText(snapshot, &a11y_writer);
|
|
380
|
+
try std.testing.expect(std.mem.indexOf(u8, a11y_writer.buffered(), "@w1/canvas#1 role=group") != null);
|
|
381
|
+
try std.testing.expect(std.mem.indexOf(u8, a11y_writer.buffered(), "value=0.5") != null);
|
|
382
|
+
try std.testing.expect(std.mem.indexOf(u8, a11y_writer.buffered(), "scroll=[offset=24,viewport=72,content=120]") != null);
|
|
383
|
+
try std.testing.expect(std.mem.indexOf(u8, a11y_writer.buffered(), "actions=[focus,increment,decrement]") != null);
|
|
384
|
+
|
|
385
|
+
_ = try harness.runtime.emitCanvasWidgetDisplayList(1, "canvas", .{});
|
|
386
|
+
const display_list = try harness.runtime.canvasDisplayList(1, "canvas");
|
|
387
|
+
var saw_scrolled_button = false;
|
|
388
|
+
for (display_list.commands) |command| {
|
|
389
|
+
switch (command) {
|
|
390
|
+
.fill_rounded_rect => |fill| {
|
|
391
|
+
if (fill.id == testCanvasWidgetPartId(3, 1)) {
|
|
392
|
+
try std.testing.expectEqualDeep(geometry.RectF.init(0, 20, 180, 32), fill.rect);
|
|
393
|
+
saw_scrolled_button = true;
|
|
394
|
+
}
|
|
395
|
+
},
|
|
396
|
+
else => {},
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
try std.testing.expect(saw_scrolled_button);
|
|
400
|
+
|
|
401
|
+
try std.testing.expect(harness.runtime.views[0].widget_scroll_states[0].velocity > 0);
|
|
402
|
+
harness.runtime.invalidated = false;
|
|
403
|
+
harness.runtime.dirty_region_count = 0;
|
|
404
|
+
harness.null_platform.gpu_surface_frame_request_count = 0;
|
|
405
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_frame = .{
|
|
406
|
+
.label = "canvas",
|
|
407
|
+
.size = geometry.SizeF.init(180, 72),
|
|
408
|
+
.scale_factor = 2,
|
|
409
|
+
.frame_index = 1,
|
|
410
|
+
.timestamp_ns = 1_016_000_000,
|
|
411
|
+
.frame_interval_ns = 16_000_000,
|
|
412
|
+
.nonblank = true,
|
|
413
|
+
} });
|
|
414
|
+
var kinetic_layout = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
415
|
+
try std.testing.expectEqual(@as(f32, 24), kinetic_layout.nodes[0].widget.value);
|
|
416
|
+
try std.testing.expectEqual(@as(usize, 1), harness.null_platform.gpu_surface_frame_request_count);
|
|
417
|
+
|
|
418
|
+
harness.runtime.invalidated = false;
|
|
419
|
+
harness.runtime.dirty_region_count = 0;
|
|
420
|
+
harness.null_platform.gpu_surface_frame_request_count = 0;
|
|
421
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_frame = .{
|
|
422
|
+
.label = "canvas",
|
|
423
|
+
.size = geometry.SizeF.init(180, 72),
|
|
424
|
+
.scale_factor = 2,
|
|
425
|
+
.frame_index = 2,
|
|
426
|
+
.timestamp_ns = 1_032_000_000,
|
|
427
|
+
.frame_interval_ns = 16_000_000,
|
|
428
|
+
.nonblank = true,
|
|
429
|
+
} });
|
|
430
|
+
const kinetic = try harness.runtime.gpuSurfaceFrame(1, "canvas");
|
|
431
|
+
try std.testing.expectEqual(@as(u64, 3), kinetic.widget_revision);
|
|
432
|
+
try std.testing.expect(harness.runtime.invalidated);
|
|
433
|
+
try std.testing.expect(harness.runtime.pendingDirtyRegions().len >= 1);
|
|
434
|
+
try std.testing.expectEqualDeep(geometry.RectF.init(10, 20, 180, 72), harness.runtime.pendingDirtyRegions()[0]);
|
|
435
|
+
try std.testing.expectEqual(@as(usize, 1), harness.null_platform.gpu_surface_frame_request_count);
|
|
436
|
+
|
|
437
|
+
kinetic_layout = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
438
|
+
try std.testing.expectApproxEqAbs(@as(f32, 47.04), kinetic_layout.nodes[0].widget.value, 0.01);
|
|
439
|
+
try std.testing.expectApproxEqAbs(@as(f32, -47.04), kinetic_layout.nodes[1].frame.y, 0.01);
|
|
440
|
+
try std.testing.expectApproxEqAbs(@as(f32, -3.04), kinetic_layout.nodes[2].frame.y, 0.01);
|
|
441
|
+
try std.testing.expectApproxEqAbs(@as(f32, 40.96), kinetic_layout.nodes[3].frame.y, 0.01);
|
|
442
|
+
try std.testing.expect(harness.runtime.views[0].widget_scroll_states[0].velocity > 0);
|
|
443
|
+
|
|
444
|
+
const kinetic_display_list = try harness.runtime.canvasDisplayList(1, "canvas");
|
|
445
|
+
var saw_kinetic_scrolled_button = false;
|
|
446
|
+
for (kinetic_display_list.commands) |command| {
|
|
447
|
+
switch (command) {
|
|
448
|
+
.fill_rounded_rect => |fill| {
|
|
449
|
+
if (fill.id == testCanvasWidgetPartId(3, 1)) {
|
|
450
|
+
try std.testing.expectApproxEqAbs(@as(f32, -3.04), fill.rect.y, 0.01);
|
|
451
|
+
saw_kinetic_scrolled_button = true;
|
|
452
|
+
}
|
|
453
|
+
},
|
|
454
|
+
else => {},
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
try std.testing.expect(saw_kinetic_scrolled_button);
|
|
458
|
+
|
|
459
|
+
harness.runtime.invalidated = false;
|
|
460
|
+
harness.runtime.dirty_region_count = 0;
|
|
461
|
+
const clamped = try harness.runtime.stepCanvasWidgetKineticScroll(1, "canvas", 16);
|
|
462
|
+
try std.testing.expectEqual(@as(u64, 4), clamped.widget_revision);
|
|
463
|
+
try std.testing.expect(harness.runtime.invalidated);
|
|
464
|
+
try std.testing.expect(harness.runtime.pendingDirtyRegions().len >= 1);
|
|
465
|
+
try std.testing.expectEqualDeep(geometry.RectF.init(10, 20, 180, 72), harness.runtime.pendingDirtyRegions()[0]);
|
|
466
|
+
|
|
467
|
+
kinetic_layout = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
468
|
+
try std.testing.expectApproxEqAbs(@as(f32, 48), kinetic_layout.nodes[0].widget.value, 0.01);
|
|
469
|
+
try std.testing.expectApproxEqAbs(@as(f32, -48), kinetic_layout.nodes[1].frame.y, 0.01);
|
|
470
|
+
try std.testing.expectApproxEqAbs(@as(f32, -4), kinetic_layout.nodes[2].frame.y, 0.01);
|
|
471
|
+
try std.testing.expectApproxEqAbs(@as(f32, 40), kinetic_layout.nodes[3].frame.y, 0.01);
|
|
472
|
+
try std.testing.expectEqual(@as(f32, 0), harness.runtime.views[0].widget_scroll_states[0].velocity);
|
|
473
|
+
|
|
474
|
+
var settle_frame: usize = 0;
|
|
475
|
+
while (settle_frame < 48) : (settle_frame += 1) {
|
|
476
|
+
harness.runtime.invalidated = false;
|
|
477
|
+
harness.runtime.dirty_region_count = 0;
|
|
478
|
+
_ = try harness.runtime.stepCanvasWidgetKineticScroll(1, "canvas", 16);
|
|
479
|
+
kinetic_layout = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
480
|
+
if (@abs(kinetic_layout.nodes[0].widget.value - 48) <= 0.01 and harness.runtime.views[0].widget_scroll_states[0].velocity == 0) break;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
try std.testing.expect(settle_frame < 48);
|
|
484
|
+
try std.testing.expectApproxEqAbs(@as(f32, 48), kinetic_layout.nodes[0].widget.value, 0.01);
|
|
485
|
+
try std.testing.expectApproxEqAbs(@as(f32, -48), kinetic_layout.nodes[1].frame.y, 0.01);
|
|
486
|
+
try std.testing.expectApproxEqAbs(@as(f32, -4), kinetic_layout.nodes[2].frame.y, 0.01);
|
|
487
|
+
try std.testing.expectApproxEqAbs(@as(f32, 40), kinetic_layout.nodes[3].frame.y, 0.01);
|
|
488
|
+
try std.testing.expectEqual(@as(f32, 0), harness.runtime.views[0].widget_scroll_states[0].velocity);
|
|
489
|
+
|
|
490
|
+
const settled_revision = harness.runtime.views[0].widget_revision;
|
|
491
|
+
harness.runtime.invalidated = false;
|
|
492
|
+
harness.runtime.dirty_region_count = 0;
|
|
493
|
+
const idle = try harness.runtime.stepCanvasWidgetKineticScroll(1, "canvas", 16);
|
|
494
|
+
try std.testing.expectEqual(settled_revision, idle.widget_revision);
|
|
495
|
+
try std.testing.expect(!harness.runtime.invalidated);
|
|
496
|
+
try std.testing.expectEqual(@as(usize, 0), harness.runtime.pendingDirtyRegions().len);
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
test "runtime wheel over virtualized scroll does not bubble to parent scroll view" {
|
|
500
|
+
const TestApp = struct {
|
|
501
|
+
widget_pointer_count: u32 = 0,
|
|
502
|
+
|
|
503
|
+
fn app(self: *@This()) App {
|
|
504
|
+
return .{ .context = self, .name = "gpu-widget-virtual-scroll-bubble", .source = platform.WebViewSource.html("<h1>Hello</h1>"), .event_fn = event };
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
fn event(context: *anyopaque, runtime: *Runtime, event_value: Event) anyerror!void {
|
|
508
|
+
_ = runtime;
|
|
509
|
+
const self: *@This() = @ptrCast(@alignCast(context));
|
|
510
|
+
switch (event_value) {
|
|
511
|
+
.canvas_widget_pointer => |pointer_event| if (pointer_event.pointer.phase == .wheel) {
|
|
512
|
+
self.widget_pointer_count += 1;
|
|
513
|
+
},
|
|
514
|
+
else => {},
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
};
|
|
518
|
+
|
|
519
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
520
|
+
defer harness.destroy(std.testing.allocator);
|
|
521
|
+
harness.null_platform.gpu_surfaces = true;
|
|
522
|
+
var app_state: TestApp = .{};
|
|
523
|
+
const app = app_state.app();
|
|
524
|
+
try harness.start(app);
|
|
525
|
+
|
|
526
|
+
_ = try harness.runtime.createView(.{
|
|
527
|
+
.window_id = 1,
|
|
528
|
+
.label = "canvas",
|
|
529
|
+
.kind = .gpu_surface,
|
|
530
|
+
.frame = geometry.RectF.init(0, 0, 180, 72),
|
|
531
|
+
});
|
|
532
|
+
|
|
533
|
+
const virtual_children = [_]canvas.Widget{
|
|
534
|
+
.{ .id = 3, .kind = .list_item, .text = "One" },
|
|
535
|
+
.{ .id = 4, .kind = .list_item, .text = "Two" },
|
|
536
|
+
.{ .id = 5, .kind = .list_item, .text = "Three" },
|
|
537
|
+
.{ .id = 6, .kind = .list_item, .text = "Four" },
|
|
538
|
+
};
|
|
539
|
+
const parent_children = [_]canvas.Widget{
|
|
540
|
+
.{
|
|
541
|
+
.id = 2,
|
|
542
|
+
.kind = .scroll_view,
|
|
543
|
+
.frame = geometry.RectF.init(0, 0, 180, 40),
|
|
544
|
+
.layout = .{ .virtualized = true, .virtual_item_extent = 20 },
|
|
545
|
+
.children = &virtual_children,
|
|
546
|
+
},
|
|
547
|
+
.{ .id = 20, .kind = .button, .frame = geometry.RectF.init(0, 120, 0, 32), .text = "Below" },
|
|
548
|
+
};
|
|
549
|
+
const parent_scroll = canvas.Widget{
|
|
550
|
+
.id = 1,
|
|
551
|
+
.kind = .scroll_view,
|
|
552
|
+
.children = &parent_children,
|
|
553
|
+
};
|
|
554
|
+
var nodes: [8]canvas.WidgetLayoutNode = undefined;
|
|
555
|
+
const layout = try canvas.layoutWidgetTree(parent_scroll, geometry.RectF.init(0, 0, 180, 72), &nodes);
|
|
556
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
557
|
+
|
|
558
|
+
const initial_revision = harness.runtime.views[0].widget_revision;
|
|
559
|
+
harness.runtime.invalidated = false;
|
|
560
|
+
harness.runtime.dirty_region_count = 0;
|
|
561
|
+
|
|
562
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
563
|
+
.window_id = 1,
|
|
564
|
+
.label = "canvas",
|
|
565
|
+
.timestamp_ns = 1_000_000_000,
|
|
566
|
+
.kind = .scroll,
|
|
567
|
+
.x = 20,
|
|
568
|
+
.y = 20,
|
|
569
|
+
.delta_y = 24,
|
|
570
|
+
} });
|
|
571
|
+
|
|
572
|
+
try std.testing.expectEqual(@as(u32, 1), app_state.widget_pointer_count);
|
|
573
|
+
const retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
574
|
+
try std.testing.expectEqual(@as(f32, 0), retained.findById(1).?.widget.value);
|
|
575
|
+
try std.testing.expectEqual(@as(f32, 0), retained.findById(2).?.widget.value);
|
|
576
|
+
try std.testing.expectEqual(initial_revision, harness.runtime.views[0].widget_revision);
|
|
577
|
+
try std.testing.expect(!harness.runtime.invalidated);
|
|
578
|
+
try std.testing.expectEqual(@as(usize, 0), harness.runtime.pendingDirtyRegions().len);
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
test "runtime automation widget wheel timestamps retained canvas scroll input" {
|
|
582
|
+
const TestApp = struct {
|
|
583
|
+
fn app(self: *@This()) App {
|
|
584
|
+
return .{ .context = self, .name = "gpu-widget-wheel-automation", .source = platform.WebViewSource.html("<h1>Hello</h1>") };
|
|
585
|
+
}
|
|
586
|
+
};
|
|
587
|
+
|
|
588
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
589
|
+
defer harness.destroy(std.testing.allocator);
|
|
590
|
+
harness.null_platform.gpu_surfaces = true;
|
|
591
|
+
var app_state: TestApp = .{};
|
|
592
|
+
const app = app_state.app();
|
|
593
|
+
try harness.start(app);
|
|
594
|
+
|
|
595
|
+
_ = try harness.runtime.createView(.{
|
|
596
|
+
.window_id = 1,
|
|
597
|
+
.label = "canvas",
|
|
598
|
+
.kind = .gpu_surface,
|
|
599
|
+
.frame = geometry.RectF.init(0, 0, 180, 64),
|
|
600
|
+
});
|
|
601
|
+
|
|
602
|
+
const children = [_]canvas.Widget{
|
|
603
|
+
.{ .id = 2, .kind = .button, .frame = geometry.RectF.init(0, 0, 0, 32), .text = "One" },
|
|
604
|
+
.{ .id = 3, .kind = .button, .frame = geometry.RectF.init(0, 40, 0, 32), .text = "Two" },
|
|
605
|
+
.{ .id = 4, .kind = .button, .frame = geometry.RectF.init(0, 80, 0, 32), .text = "Three" },
|
|
606
|
+
};
|
|
607
|
+
var nodes: [4]canvas.WidgetLayoutNode = undefined;
|
|
608
|
+
const layout = try canvas.layoutWidgetTree(.{ .id = 1, .kind = .scroll_view, .children = &children }, geometry.RectF.init(0, 0, 180, 64), &nodes);
|
|
609
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
610
|
+
|
|
611
|
+
try harness.runtime.dispatchAutomationCommand(app, "widget-wheel canvas 1 18");
|
|
612
|
+
try std.testing.expect(harness.runtime.views[0].gpu_input_timestamp_ns > 0);
|
|
613
|
+
try std.testing.expectEqual(harness.runtime.views[0].gpu_input_timestamp_ns, harness.runtime.views[0].gpu_pending_input_timestamp_ns);
|
|
614
|
+
try std.testing.expect(harness.runtime.invalidated);
|
|
615
|
+
|
|
616
|
+
const retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
617
|
+
try std.testing.expectEqual(@as(f32, 18), retained.findById(1).?.widget.value);
|
|
618
|
+
try std.testing.expectEqual(@as(u64, 2), harness.runtime.views[0].widget_revision);
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
test "runtime automation widget key inputs route to focused canvas widgets" {
|
|
622
|
+
const TestApp = struct {
|
|
623
|
+
command_count: u32 = 0,
|
|
624
|
+
last_command: []const u8 = "",
|
|
625
|
+
last_source: CommandSource = .runtime,
|
|
626
|
+
last_view_label: []const u8 = "",
|
|
627
|
+
|
|
628
|
+
fn app(self: *@This()) App {
|
|
629
|
+
return .{ .context = self, .name = "gpu-widget-key-automation", .source = platform.WebViewSource.html("<h1>Hello</h1>"), .event_fn = event };
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
fn event(context: *anyopaque, runtime: *Runtime, event_value: Event) anyerror!void {
|
|
633
|
+
_ = runtime;
|
|
634
|
+
const self: *@This() = @ptrCast(@alignCast(context));
|
|
635
|
+
switch (event_value) {
|
|
636
|
+
.command => |command| {
|
|
637
|
+
self.command_count += 1;
|
|
638
|
+
self.last_command = command.name;
|
|
639
|
+
self.last_source = command.source;
|
|
640
|
+
self.last_view_label = command.view_label;
|
|
641
|
+
},
|
|
642
|
+
else => {},
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
};
|
|
646
|
+
|
|
647
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
648
|
+
defer harness.destroy(std.testing.allocator);
|
|
649
|
+
harness.null_platform.gpu_surfaces = true;
|
|
650
|
+
var app_state: TestApp = .{};
|
|
651
|
+
const app = app_state.app();
|
|
652
|
+
try harness.start(app);
|
|
653
|
+
|
|
654
|
+
_ = try harness.runtime.createView(.{
|
|
655
|
+
.window_id = 1,
|
|
656
|
+
.label = "canvas",
|
|
657
|
+
.kind = .gpu_surface,
|
|
658
|
+
.frame = geometry.RectF.init(0, 0, 240, 120),
|
|
659
|
+
});
|
|
660
|
+
|
|
661
|
+
const children = [_]canvas.Widget{
|
|
662
|
+
.{ .id = 2, .kind = .text_field, .frame = geometry.RectF.init(12, 16, 160, 36), .text = "Draft" },
|
|
663
|
+
.{ .id = 3, .kind = .button, .frame = geometry.RectF.init(12, 64, 96, 32), .text = "Run", .command = "app.run" },
|
|
664
|
+
};
|
|
665
|
+
var nodes: [3]canvas.WidgetLayoutNode = undefined;
|
|
666
|
+
const layout = try canvas.layoutWidgetTree(.{ .kind = .stack, .children = &children }, geometry.RectF.init(0, 0, 240, 120), &nodes);
|
|
667
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
668
|
+
|
|
669
|
+
try harness.runtime.dispatchAutomationCommand(app, "widget-action canvas 2 focus");
|
|
670
|
+
try harness.runtime.dispatchAutomationCommand(app, "widget-key canvas a a");
|
|
671
|
+
|
|
672
|
+
const retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
673
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), harness.runtime.views[0].canvas_widget_focused_id);
|
|
674
|
+
try std.testing.expectEqualStrings("Drafta", retained.findById(2).?.widget.text);
|
|
675
|
+
try std.testing.expectEqualDeep(canvas.TextSelection.collapsed(6), retained.findById(2).?.widget.text_selection.?);
|
|
676
|
+
|
|
677
|
+
try harness.runtime.dispatchAutomationCommand(app, "widget-key canvas tab");
|
|
678
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 3), harness.runtime.views[0].canvas_widget_focused_id);
|
|
679
|
+
const snapshot = harness.runtime.automationSnapshot("Widgets");
|
|
680
|
+
try std.testing.expect(!snapshot.widgets[0].focused);
|
|
681
|
+
try std.testing.expect(snapshot.widgets[1].focused);
|
|
682
|
+
|
|
683
|
+
try harness.runtime.dispatchAutomationCommand(app, "widget-key canvas enter");
|
|
684
|
+
try std.testing.expectEqual(@as(u32, 1), app_state.command_count);
|
|
685
|
+
try std.testing.expectEqualStrings("app.run", app_state.last_command);
|
|
686
|
+
try std.testing.expectEqual(CommandSource.native_view, app_state.last_source);
|
|
687
|
+
try std.testing.expectEqualStrings("canvas", app_state.last_view_label);
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
test "runtime applies stored design token scroll physics" {
|
|
691
|
+
const TestApp = struct {
|
|
692
|
+
fn app(self: *@This()) App {
|
|
693
|
+
return .{ .context = self, .name = "gpu-widget-token-scroll", .source = platform.WebViewSource.html("<h1>Hello</h1>") };
|
|
694
|
+
}
|
|
695
|
+
};
|
|
696
|
+
|
|
697
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
698
|
+
defer harness.destroy(std.testing.allocator);
|
|
699
|
+
harness.null_platform.gpu_surfaces = true;
|
|
700
|
+
var app_state: TestApp = .{};
|
|
701
|
+
const app = app_state.app();
|
|
702
|
+
try harness.start(app);
|
|
703
|
+
|
|
704
|
+
_ = try harness.runtime.createView(.{
|
|
705
|
+
.window_id = 1,
|
|
706
|
+
.label = "canvas",
|
|
707
|
+
.kind = .gpu_surface,
|
|
708
|
+
.frame = geometry.RectF.init(10, 20, 180, 72),
|
|
709
|
+
});
|
|
710
|
+
|
|
711
|
+
const children = [_]canvas.Widget{
|
|
712
|
+
.{ .id = 2, .kind = .button, .frame = geometry.RectF.init(0, 0, 0, 32), .text = "One" },
|
|
713
|
+
.{ .id = 3, .kind = .button, .frame = geometry.RectF.init(0, 44, 0, 32), .text = "Two" },
|
|
714
|
+
.{ .id = 4, .kind = .button, .frame = geometry.RectF.init(0, 88, 0, 32), .text = "Three" },
|
|
715
|
+
};
|
|
716
|
+
const scroll = canvas.Widget{
|
|
717
|
+
.id = 1,
|
|
718
|
+
.kind = .scroll_view,
|
|
719
|
+
.children = &children,
|
|
720
|
+
};
|
|
721
|
+
var nodes: [5]canvas.WidgetLayoutNode = undefined;
|
|
722
|
+
const layout = try canvas.layoutWidgetTree(scroll, geometry.RectF.init(0, 0, 180, 72), &nodes);
|
|
723
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
724
|
+
|
|
725
|
+
const tokens = canvas.DesignTokens{
|
|
726
|
+
.scroll = .{
|
|
727
|
+
.wheel_multiplier = 0.5,
|
|
728
|
+
.wheel_velocity_scale = 4,
|
|
729
|
+
.deceleration_per_second = 1,
|
|
730
|
+
.stop_velocity = 0,
|
|
731
|
+
},
|
|
732
|
+
};
|
|
733
|
+
_ = try harness.runtime.setCanvasWidgetDesignTokens(1, "canvas", tokens);
|
|
734
|
+
try std.testing.expectEqualDeep(tokens, try harness.runtime.canvasWidgetDesignTokens(1, "canvas"));
|
|
735
|
+
|
|
736
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
737
|
+
.window_id = 1,
|
|
738
|
+
.label = "canvas",
|
|
739
|
+
.kind = .scroll,
|
|
740
|
+
.x = 20,
|
|
741
|
+
.y = 20,
|
|
742
|
+
.delta_y = 40,
|
|
743
|
+
} });
|
|
744
|
+
|
|
745
|
+
var retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
746
|
+
try std.testing.expectEqual(@as(f32, 20), retained.nodes[0].widget.value);
|
|
747
|
+
try std.testing.expectEqual(@as(f32, -20), retained.nodes[1].frame.y);
|
|
748
|
+
try std.testing.expectEqual(@as(f32, 80), harness.runtime.views[0].widget_scroll_states[0].velocity);
|
|
749
|
+
|
|
750
|
+
_ = try harness.runtime.stepCanvasWidgetKineticScroll(1, "canvas", 16);
|
|
751
|
+
retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
752
|
+
try std.testing.expectApproxEqAbs(@as(f32, 21.28), retained.nodes[0].widget.value, 0.001);
|
|
753
|
+
try std.testing.expectApproxEqAbs(@as(f32, -21.28), retained.nodes[1].frame.y, 0.001);
|
|
754
|
+
try std.testing.expectEqual(@as(f32, 80), harness.runtime.views[0].widget_scroll_states[0].velocity);
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
test "runtime refreshes hovered canvas widget after scroll clipping" {
|
|
758
|
+
const TestApp = struct {
|
|
759
|
+
fn app(self: *@This()) App {
|
|
760
|
+
return .{ .context = self, .name = "gpu-widget-scroll-hover", .source = platform.WebViewSource.html("<h1>Hello</h1>") };
|
|
761
|
+
}
|
|
762
|
+
};
|
|
763
|
+
|
|
764
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
765
|
+
defer harness.destroy(std.testing.allocator);
|
|
766
|
+
harness.null_platform.gpu_surfaces = true;
|
|
767
|
+
var app_state: TestApp = .{};
|
|
768
|
+
const app = app_state.app();
|
|
769
|
+
try harness.start(app);
|
|
770
|
+
|
|
771
|
+
_ = try harness.runtime.createView(.{
|
|
772
|
+
.window_id = 1,
|
|
773
|
+
.label = "canvas",
|
|
774
|
+
.kind = .gpu_surface,
|
|
775
|
+
.frame = geometry.RectF.init(10, 20, 160, 40),
|
|
776
|
+
});
|
|
777
|
+
|
|
778
|
+
const children = [_]canvas.Widget{
|
|
779
|
+
.{ .id = 2, .kind = .button, .frame = geometry.RectF.init(0, 0, 0, 32), .text = "One" },
|
|
780
|
+
.{ .id = 3, .kind = .button, .frame = geometry.RectF.init(0, 48, 0, 32), .text = "Two" },
|
|
781
|
+
};
|
|
782
|
+
var nodes: [3]canvas.WidgetLayoutNode = undefined;
|
|
783
|
+
const layout = try canvas.layoutWidgetTree(
|
|
784
|
+
.{ .id = 1, .kind = .scroll_view, .children = &children },
|
|
785
|
+
geometry.RectF.init(0, 0, 160, 40),
|
|
786
|
+
&nodes,
|
|
787
|
+
);
|
|
788
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
789
|
+
|
|
790
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
791
|
+
.window_id = 1,
|
|
792
|
+
.label = "canvas",
|
|
793
|
+
.kind = .pointer_move,
|
|
794
|
+
.x = 12,
|
|
795
|
+
.y = 12,
|
|
796
|
+
} });
|
|
797
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), harness.runtime.views[0].canvas_widget_hovered_id);
|
|
798
|
+
// Buttons show the native arrow; the hover id above is the state
|
|
799
|
+
// this test actually pins across the scroll.
|
|
800
|
+
try std.testing.expectEqual(platform.Cursor.arrow, harness.runtime.views[0].canvas_widget_cursor);
|
|
801
|
+
|
|
802
|
+
var snapshot = harness.runtime.automationSnapshot("Widgets");
|
|
803
|
+
try std.testing.expect(snapshot.widgets[1].hovered);
|
|
804
|
+
try std.testing.expect(!snapshot.widgets[2].hovered);
|
|
805
|
+
|
|
806
|
+
harness.runtime.invalidated = false;
|
|
807
|
+
harness.runtime.dirty_region_count = 0;
|
|
808
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
809
|
+
.window_id = 1,
|
|
810
|
+
.label = "canvas",
|
|
811
|
+
.kind = .scroll,
|
|
812
|
+
.x = 12,
|
|
813
|
+
.y = 12,
|
|
814
|
+
.delta_y = 40,
|
|
815
|
+
} });
|
|
816
|
+
|
|
817
|
+
const retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
818
|
+
try std.testing.expectEqualDeep(geometry.RectF.init(0, -40, 160, 32), retained.findById(2).?.frame);
|
|
819
|
+
try std.testing.expectEqualDeep(geometry.RectF.init(0, 8, 160, 32), retained.findById(3).?.frame);
|
|
820
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 3), harness.runtime.views[0].canvas_widget_hovered_id);
|
|
821
|
+
try std.testing.expectEqual(platform.Cursor.arrow, harness.runtime.views[0].canvas_widget_cursor);
|
|
822
|
+
try std.testing.expect(harness.runtime.invalidated);
|
|
823
|
+
try std.testing.expectEqual(@as(usize, 1), harness.runtime.pendingDirtyRegions().len);
|
|
824
|
+
try std.testing.expectEqualDeep(geometry.RectF.init(10, 20, 160, 40), harness.runtime.pendingDirtyRegions()[0]);
|
|
825
|
+
|
|
826
|
+
snapshot = harness.runtime.automationSnapshot("Widgets");
|
|
827
|
+
try std.testing.expect(!snapshot.widgets[1].hovered);
|
|
828
|
+
try std.testing.expect(snapshot.widgets[2].hovered);
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
test "runtime clears focused canvas widget after scroll clipping" {
|
|
832
|
+
const TestApp = struct {
|
|
833
|
+
fn app(self: *@This()) App {
|
|
834
|
+
return .{ .context = self, .name = "gpu-widget-scroll-focus", .source = platform.WebViewSource.html("<h1>Hello</h1>") };
|
|
835
|
+
}
|
|
836
|
+
};
|
|
837
|
+
|
|
838
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
839
|
+
defer harness.destroy(std.testing.allocator);
|
|
840
|
+
harness.null_platform.gpu_surfaces = true;
|
|
841
|
+
var app_state: TestApp = .{};
|
|
842
|
+
const app = app_state.app();
|
|
843
|
+
try harness.start(app);
|
|
844
|
+
|
|
845
|
+
_ = try harness.runtime.createView(.{
|
|
846
|
+
.window_id = 1,
|
|
847
|
+
.label = "canvas",
|
|
848
|
+
.kind = .gpu_surface,
|
|
849
|
+
.frame = geometry.RectF.init(10, 20, 160, 40),
|
|
850
|
+
});
|
|
851
|
+
|
|
852
|
+
const children = [_]canvas.Widget{
|
|
853
|
+
.{ .id = 2, .kind = .button, .frame = geometry.RectF.init(0, 0, 0, 32), .text = "One" },
|
|
854
|
+
.{ .id = 3, .kind = .button, .frame = geometry.RectF.init(0, 48, 0, 32), .text = "Two" },
|
|
855
|
+
};
|
|
856
|
+
var nodes: [3]canvas.WidgetLayoutNode = undefined;
|
|
857
|
+
const layout = try canvas.layoutWidgetTree(
|
|
858
|
+
.{ .id = 1, .kind = .scroll_view, .children = &children },
|
|
859
|
+
geometry.RectF.init(0, 0, 160, 40),
|
|
860
|
+
&nodes,
|
|
861
|
+
);
|
|
862
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
863
|
+
try harness.runtime.focusView(1, "canvas");
|
|
864
|
+
harness.runtime.views[0].canvas_widget_focused_id = 2;
|
|
865
|
+
harness.runtime.views[0].canvas_widget_focus_visible_id = 2;
|
|
866
|
+
_ = try harness.runtime.emitCanvasWidgetDisplayList(1, "canvas", .{});
|
|
867
|
+
|
|
868
|
+
var route_buffer: [4]canvas.WidgetEventRouteEntry = undefined;
|
|
869
|
+
const initial_route = try harness.runtime.routeCanvasWidgetKeyboardInput(.{
|
|
870
|
+
.window_id = 1,
|
|
871
|
+
.label = "canvas",
|
|
872
|
+
.kind = .key_down,
|
|
873
|
+
.key = "enter",
|
|
874
|
+
}, &route_buffer);
|
|
875
|
+
try std.testing.expect(initial_route != null);
|
|
876
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), initial_route.?.target.?.id);
|
|
877
|
+
|
|
878
|
+
var display_list = try harness.runtime.canvasDisplayList(1, "canvas");
|
|
879
|
+
var saw_focus_ring = false;
|
|
880
|
+
for (display_list.commands) |command| {
|
|
881
|
+
if (command.objectId()) |id| {
|
|
882
|
+
if (id == testCanvasWidgetPartId(2, 3)) saw_focus_ring = true;
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
try std.testing.expect(saw_focus_ring);
|
|
886
|
+
|
|
887
|
+
var snapshot = harness.runtime.automationSnapshot("Widgets");
|
|
888
|
+
try std.testing.expect(snapshot.widgets[1].focused);
|
|
889
|
+
|
|
890
|
+
harness.runtime.invalidated = false;
|
|
891
|
+
harness.runtime.dirty_region_count = 0;
|
|
892
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
893
|
+
.window_id = 1,
|
|
894
|
+
.label = "canvas",
|
|
895
|
+
.kind = .scroll,
|
|
896
|
+
.x = 12,
|
|
897
|
+
.y = 12,
|
|
898
|
+
.delta_y = 40,
|
|
899
|
+
} });
|
|
900
|
+
|
|
901
|
+
const retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
902
|
+
try std.testing.expectEqualDeep(geometry.RectF.init(0, -40, 160, 32), retained.findById(2).?.frame);
|
|
903
|
+
try std.testing.expectEqualDeep(geometry.RectF.init(0, 8, 160, 32), retained.findById(3).?.frame);
|
|
904
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_widget_focused_id);
|
|
905
|
+
try std.testing.expect(try harness.runtime.routeCanvasWidgetKeyboardInput(.{
|
|
906
|
+
.window_id = 1,
|
|
907
|
+
.label = "canvas",
|
|
908
|
+
.kind = .key_down,
|
|
909
|
+
.key = "enter",
|
|
910
|
+
}, &route_buffer) == null);
|
|
911
|
+
|
|
912
|
+
display_list = try harness.runtime.canvasDisplayList(1, "canvas");
|
|
913
|
+
saw_focus_ring = false;
|
|
914
|
+
for (display_list.commands) |command| {
|
|
915
|
+
if (command.objectId()) |id| {
|
|
916
|
+
if (id == testCanvasWidgetPartId(2, 3)) saw_focus_ring = true;
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
try std.testing.expect(!saw_focus_ring);
|
|
920
|
+
|
|
921
|
+
snapshot = harness.runtime.automationSnapshot("Widgets");
|
|
922
|
+
try std.testing.expect(!snapshot.widgets[1].focused);
|
|
923
|
+
try std.testing.expect(!snapshot.widgets[2].focused);
|
|
924
|
+
try std.testing.expect(harness.runtime.invalidated);
|
|
925
|
+
try std.testing.expect(harness.runtime.pendingDirtyRegions().len >= 1);
|
|
926
|
+
try std.testing.expectEqualDeep(geometry.RectF.init(10, 20, 160, 40), harness.runtime.pendingDirtyRegions()[0]);
|
|
927
|
+
}
|
|
928
|
+
|
|
929
|
+
test "runtime clears focused canvas widget after kinetic scroll clipping" {
|
|
930
|
+
const TestApp = struct {
|
|
931
|
+
fn app(self: *@This()) App {
|
|
932
|
+
return .{ .context = self, .name = "gpu-widget-kinetic-focus", .source = platform.WebViewSource.html("<h1>Hello</h1>") };
|
|
933
|
+
}
|
|
934
|
+
};
|
|
935
|
+
|
|
936
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
937
|
+
defer harness.destroy(std.testing.allocator);
|
|
938
|
+
harness.null_platform.gpu_surfaces = true;
|
|
939
|
+
var app_state: TestApp = .{};
|
|
940
|
+
try harness.start(app_state.app());
|
|
941
|
+
|
|
942
|
+
_ = try harness.runtime.createView(.{
|
|
943
|
+
.window_id = 1,
|
|
944
|
+
.label = "canvas",
|
|
945
|
+
.kind = .gpu_surface,
|
|
946
|
+
.frame = geometry.RectF.init(10, 20, 160, 40),
|
|
947
|
+
});
|
|
948
|
+
|
|
949
|
+
const children = [_]canvas.Widget{
|
|
950
|
+
.{ .id = 2, .kind = .button, .frame = geometry.RectF.init(0, 0, 0, 32), .text = "One" },
|
|
951
|
+
.{ .id = 3, .kind = .button, .frame = geometry.RectF.init(0, 48, 0, 32), .text = "Two" },
|
|
952
|
+
};
|
|
953
|
+
var nodes: [3]canvas.WidgetLayoutNode = undefined;
|
|
954
|
+
const layout = try canvas.layoutWidgetTree(
|
|
955
|
+
.{ .id = 1, .kind = .scroll_view, .children = &children },
|
|
956
|
+
geometry.RectF.init(0, 0, 160, 40),
|
|
957
|
+
&nodes,
|
|
958
|
+
);
|
|
959
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
960
|
+
try harness.runtime.focusView(1, "canvas");
|
|
961
|
+
harness.runtime.views[0].canvas_widget_focused_id = 2;
|
|
962
|
+
harness.runtime.views[0].widget_scroll_states[0].velocity = 2500;
|
|
963
|
+
_ = try harness.runtime.emitCanvasWidgetDisplayList(1, "canvas", .{});
|
|
964
|
+
|
|
965
|
+
harness.runtime.invalidated = false;
|
|
966
|
+
harness.runtime.dirty_region_count = 0;
|
|
967
|
+
const frame = try harness.runtime.stepCanvasWidgetKineticScroll(1, "canvas", 16);
|
|
968
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_widget_focused_id);
|
|
969
|
+
try std.testing.expectEqual(@as(u64, 2), frame.widget_revision);
|
|
970
|
+
try std.testing.expect(harness.runtime.invalidated);
|
|
971
|
+
try std.testing.expect(harness.runtime.pendingDirtyRegions().len >= 1);
|
|
972
|
+
try std.testing.expectEqualDeep(geometry.RectF.init(10, 20, 160, 40), harness.runtime.pendingDirtyRegions()[0]);
|
|
973
|
+
|
|
974
|
+
const retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
975
|
+
try std.testing.expectEqual(@as(f32, 40), retained.findById(1).?.widget.value);
|
|
976
|
+
try std.testing.expectEqualDeep(geometry.RectF.init(0, -40, 160, 32), retained.findById(2).?.frame);
|
|
977
|
+
try std.testing.expectEqualDeep(geometry.RectF.init(0, 8, 160, 32), retained.findById(3).?.frame);
|
|
978
|
+
|
|
979
|
+
const snapshot = harness.runtime.automationSnapshot("Widgets");
|
|
980
|
+
try std.testing.expect(!snapshot.widgets[1].focused);
|
|
981
|
+
try std.testing.expect(!snapshot.widgets[2].focused);
|
|
982
|
+
|
|
983
|
+
const display_list = try harness.runtime.canvasDisplayList(1, "canvas");
|
|
984
|
+
for (display_list.commands) |command| {
|
|
985
|
+
if (command.objectId()) |id| {
|
|
986
|
+
try std.testing.expect(id != testCanvasWidgetPartId(2, 3));
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
test "runtime reconciles canvas widget render state after keyboard scroll clipping" {
|
|
992
|
+
const TestApp = struct {
|
|
993
|
+
fn app(self: *@This()) App {
|
|
994
|
+
return .{ .context = self, .name = "gpu-widget-keyboard-scroll-state", .source = platform.WebViewSource.html("<h1>Hello</h1>") };
|
|
995
|
+
}
|
|
996
|
+
};
|
|
997
|
+
|
|
998
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
999
|
+
defer harness.destroy(std.testing.allocator);
|
|
1000
|
+
harness.null_platform.gpu_surfaces = true;
|
|
1001
|
+
var app_state: TestApp = .{};
|
|
1002
|
+
const app = app_state.app();
|
|
1003
|
+
try harness.start(app);
|
|
1004
|
+
|
|
1005
|
+
_ = try harness.runtime.createView(.{
|
|
1006
|
+
.window_id = 1,
|
|
1007
|
+
.label = "canvas",
|
|
1008
|
+
.kind = .gpu_surface,
|
|
1009
|
+
.frame = geometry.RectF.init(10, 20, 160, 40),
|
|
1010
|
+
});
|
|
1011
|
+
|
|
1012
|
+
const children = [_]canvas.Widget{
|
|
1013
|
+
.{ .id = 2, .kind = .button, .frame = geometry.RectF.init(0, 0, 0, 32), .text = "One" },
|
|
1014
|
+
.{ .id = 3, .kind = .button, .frame = geometry.RectF.init(0, 48, 0, 32), .text = "Two" },
|
|
1015
|
+
};
|
|
1016
|
+
var nodes: [3]canvas.WidgetLayoutNode = undefined;
|
|
1017
|
+
const layout = try canvas.layoutWidgetTree(
|
|
1018
|
+
.{ .id = 1, .kind = .scroll_view, .children = &children },
|
|
1019
|
+
geometry.RectF.init(0, 0, 160, 40),
|
|
1020
|
+
&nodes,
|
|
1021
|
+
);
|
|
1022
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
1023
|
+
try harness.runtime.focusView(1, "canvas");
|
|
1024
|
+
harness.runtime.views[0].canvas_widget_focused_id = 1;
|
|
1025
|
+
harness.runtime.views[0].canvas_widget_hovered_id = 2;
|
|
1026
|
+
// Seed a non-arrow cursor (only a link hover produces this in the
|
|
1027
|
+
// wild) so the reset back to arrow below is observable.
|
|
1028
|
+
harness.runtime.views[0].canvas_widget_cursor = .pointing_hand;
|
|
1029
|
+
_ = try harness.runtime.emitCanvasWidgetDisplayList(1, "canvas", .{});
|
|
1030
|
+
|
|
1031
|
+
harness.runtime.invalidated = false;
|
|
1032
|
+
harness.runtime.dirty_region_count = 0;
|
|
1033
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
1034
|
+
.window_id = 1,
|
|
1035
|
+
.label = "canvas",
|
|
1036
|
+
.kind = .key_down,
|
|
1037
|
+
.key = "pagedown",
|
|
1038
|
+
} });
|
|
1039
|
+
|
|
1040
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 1), harness.runtime.views[0].canvas_widget_focused_id);
|
|
1041
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_widget_hovered_id);
|
|
1042
|
+
try std.testing.expectEqual(platform.Cursor.arrow, harness.runtime.views[0].canvas_widget_cursor);
|
|
1043
|
+
try std.testing.expect(harness.runtime.invalidated);
|
|
1044
|
+
try std.testing.expect(harness.runtime.pendingDirtyRegions().len >= 1);
|
|
1045
|
+
try std.testing.expectEqualDeep(geometry.RectF.init(10, 20, 160, 40), harness.runtime.pendingDirtyRegions()[0]);
|
|
1046
|
+
|
|
1047
|
+
const retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
1048
|
+
try std.testing.expectEqual(@as(f32, 34), retained.findById(1).?.widget.value);
|
|
1049
|
+
try std.testing.expectEqualDeep(geometry.RectF.init(0, -34, 160, 32), retained.findById(2).?.frame);
|
|
1050
|
+
try std.testing.expectEqualDeep(geometry.RectF.init(0, 14, 160, 32), retained.findById(3).?.frame);
|
|
1051
|
+
|
|
1052
|
+
const snapshot = harness.runtime.automationSnapshot("Widgets");
|
|
1053
|
+
try std.testing.expect(snapshot.widgets[0].focused);
|
|
1054
|
+
try std.testing.expect(!snapshot.widgets[1].hovered);
|
|
1055
|
+
try std.testing.expect(!snapshot.widgets[2].hovered);
|
|
1056
|
+
|
|
1057
|
+
harness.runtime.invalidated = false;
|
|
1058
|
+
harness.runtime.dirty_region_count = 0;
|
|
1059
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
1060
|
+
.window_id = 1,
|
|
1061
|
+
.label = "canvas",
|
|
1062
|
+
.kind = .key_down,
|
|
1063
|
+
.key = "end",
|
|
1064
|
+
} });
|
|
1065
|
+
var keyboard_scrolled = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
1066
|
+
try std.testing.expectEqual(@as(f32, 40), keyboard_scrolled.findById(1).?.widget.value);
|
|
1067
|
+
try std.testing.expectEqualDeep(geometry.RectF.init(0, -40, 160, 32), keyboard_scrolled.findById(2).?.frame);
|
|
1068
|
+
try std.testing.expectEqualDeep(geometry.RectF.init(0, 8, 160, 32), keyboard_scrolled.findById(3).?.frame);
|
|
1069
|
+
try std.testing.expect(harness.runtime.invalidated);
|
|
1070
|
+
try std.testing.expect(harness.runtime.pendingDirtyRegions().len >= 1);
|
|
1071
|
+
|
|
1072
|
+
harness.runtime.invalidated = false;
|
|
1073
|
+
harness.runtime.dirty_region_count = 0;
|
|
1074
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
1075
|
+
.window_id = 1,
|
|
1076
|
+
.label = "canvas",
|
|
1077
|
+
.kind = .key_down,
|
|
1078
|
+
.key = "home",
|
|
1079
|
+
} });
|
|
1080
|
+
keyboard_scrolled = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
1081
|
+
try std.testing.expectEqual(@as(f32, 0), keyboard_scrolled.findById(1).?.widget.value);
|
|
1082
|
+
try std.testing.expectEqualDeep(geometry.RectF.init(0, 0, 160, 32), keyboard_scrolled.findById(2).?.frame);
|
|
1083
|
+
try std.testing.expectEqualDeep(geometry.RectF.init(0, 48, 160, 32), keyboard_scrolled.findById(3).?.frame);
|
|
1084
|
+
try std.testing.expect(harness.runtime.invalidated);
|
|
1085
|
+
try std.testing.expect(harness.runtime.pendingDirtyRegions().len >= 1);
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
test "runtime reconciles canvas widget scroll momentum across layout replacement" {
|
|
1089
|
+
const TestApp = struct {
|
|
1090
|
+
fn app(self: *@This()) App {
|
|
1091
|
+
return .{ .context = self, .name = "gpu-widget-scroll-reconcile", .source = platform.WebViewSource.html("<h1>Hello</h1>") };
|
|
1092
|
+
}
|
|
1093
|
+
};
|
|
1094
|
+
|
|
1095
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
1096
|
+
defer harness.destroy(std.testing.allocator);
|
|
1097
|
+
harness.null_platform.gpu_surfaces = true;
|
|
1098
|
+
var app_state: TestApp = .{};
|
|
1099
|
+
const app = app_state.app();
|
|
1100
|
+
try harness.start(app);
|
|
1101
|
+
|
|
1102
|
+
_ = try harness.runtime.createView(.{
|
|
1103
|
+
.window_id = 1,
|
|
1104
|
+
.label = "canvas",
|
|
1105
|
+
.kind = .gpu_surface,
|
|
1106
|
+
.frame = geometry.RectF.init(10, 20, 220, 96),
|
|
1107
|
+
});
|
|
1108
|
+
|
|
1109
|
+
const children = [_]canvas.Widget{
|
|
1110
|
+
.{ .id = 2, .kind = .button, .frame = geometry.RectF.init(0, 0, 0, 32), .text = "One" },
|
|
1111
|
+
.{ .id = 3, .kind = .button, .frame = geometry.RectF.init(0, 44, 0, 32), .text = "Two" },
|
|
1112
|
+
.{ .id = 4, .kind = .button, .frame = geometry.RectF.init(0, 88, 0, 32), .text = "Three" },
|
|
1113
|
+
};
|
|
1114
|
+
const scroll = canvas.Widget{
|
|
1115
|
+
.id = 1,
|
|
1116
|
+
.kind = .scroll_view,
|
|
1117
|
+
.frame = geometry.RectF.init(0, 0, 180, 72),
|
|
1118
|
+
.children = &children,
|
|
1119
|
+
};
|
|
1120
|
+
var nodes: [4]canvas.WidgetLayoutNode = undefined;
|
|
1121
|
+
const layout = try canvas.layoutWidgetTree(scroll, geometry.RectF.init(0, 0, 180, 72), &nodes);
|
|
1122
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
1123
|
+
|
|
1124
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
1125
|
+
.window_id = 1,
|
|
1126
|
+
.label = "canvas",
|
|
1127
|
+
.kind = .scroll,
|
|
1128
|
+
.x = 20,
|
|
1129
|
+
.y = 20,
|
|
1130
|
+
.delta_y = 24,
|
|
1131
|
+
} });
|
|
1132
|
+
try std.testing.expect(harness.runtime.views[0].widget_scroll_states[0].velocity > 0);
|
|
1133
|
+
|
|
1134
|
+
const scrolled = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
1135
|
+
const current_offset = scrolled.findById(1).?.widget.value;
|
|
1136
|
+
try std.testing.expectEqual(@as(f32, 24), current_offset);
|
|
1137
|
+
|
|
1138
|
+
const refreshed_scroll = canvas.Widget{
|
|
1139
|
+
.id = 1,
|
|
1140
|
+
.kind = .scroll_view,
|
|
1141
|
+
.frame = geometry.RectF.init(24, 12, 180, 72),
|
|
1142
|
+
.value = current_offset,
|
|
1143
|
+
.children = &children,
|
|
1144
|
+
};
|
|
1145
|
+
const refreshed_widgets = [_]canvas.Widget{
|
|
1146
|
+
.{ .id = 10, .kind = .text, .frame = geometry.RectF.init(8, 0, 120, 12), .text = "Activity" },
|
|
1147
|
+
refreshed_scroll,
|
|
1148
|
+
};
|
|
1149
|
+
var refreshed_nodes: [6]canvas.WidgetLayoutNode = undefined;
|
|
1150
|
+
const refreshed_layout = try canvas.layoutWidgetTree(.{ .kind = .stack, .children = &refreshed_widgets }, geometry.RectF.init(0, 0, 220, 96), &refreshed_nodes);
|
|
1151
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", refreshed_layout);
|
|
1152
|
+
|
|
1153
|
+
const refreshed = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
1154
|
+
try std.testing.expectEqual(@as(f32, 24), refreshed.findById(1).?.widget.value);
|
|
1155
|
+
try std.testing.expect(harness.runtime.views[0].widget_scroll_states[2].velocity > 0);
|
|
1156
|
+
|
|
1157
|
+
harness.runtime.invalidated = false;
|
|
1158
|
+
harness.runtime.dirty_region_count = 0;
|
|
1159
|
+
const kinetic = try harness.runtime.stepCanvasWidgetKineticScroll(1, "canvas", 16);
|
|
1160
|
+
try std.testing.expectEqual(@as(u64, 4), kinetic.widget_revision);
|
|
1161
|
+
try std.testing.expect(harness.runtime.invalidated);
|
|
1162
|
+
try std.testing.expect(harness.runtime.pendingDirtyRegions().len >= 1);
|
|
1163
|
+
try std.testing.expectEqualDeep(geometry.RectF.init(34, 32, 180, 72), harness.runtime.pendingDirtyRegions()[0]);
|
|
1164
|
+
|
|
1165
|
+
const kinetic_layout = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
1166
|
+
try std.testing.expectApproxEqAbs(@as(f32, 47.04), kinetic_layout.findById(1).?.widget.value, 0.01);
|
|
1167
|
+
try std.testing.expectApproxEqAbs(@as(f32, -35.04), kinetic_layout.findById(2).?.frame.y, 0.01);
|
|
1168
|
+
try std.testing.expectApproxEqAbs(@as(f32, 8.96), kinetic_layout.findById(3).?.frame.y, 0.01);
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1171
|
+
test "runtime clamps canvas scroll offset after layout replacement shrinks content" {
|
|
1172
|
+
const TestApp = struct {
|
|
1173
|
+
fn app(self: *@This()) App {
|
|
1174
|
+
return .{ .context = self, .name = "gpu-widget-scroll-clamp-replacement", .source = platform.WebViewSource.html("<h1>Hello</h1>") };
|
|
1175
|
+
}
|
|
1176
|
+
};
|
|
1177
|
+
|
|
1178
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
1179
|
+
defer harness.destroy(std.testing.allocator);
|
|
1180
|
+
harness.null_platform.gpu_surfaces = true;
|
|
1181
|
+
var app_state: TestApp = .{};
|
|
1182
|
+
try harness.start(app_state.app());
|
|
1183
|
+
|
|
1184
|
+
_ = try harness.runtime.createView(.{
|
|
1185
|
+
.window_id = 1,
|
|
1186
|
+
.label = "canvas",
|
|
1187
|
+
.kind = .gpu_surface,
|
|
1188
|
+
.frame = geometry.RectF.init(10, 20, 220, 96),
|
|
1189
|
+
});
|
|
1190
|
+
|
|
1191
|
+
const full_children = [_]canvas.Widget{
|
|
1192
|
+
.{ .id = 2, .kind = .button, .frame = geometry.RectF.init(0, 0, 0, 32), .text = "One" },
|
|
1193
|
+
.{ .id = 3, .kind = .button, .frame = geometry.RectF.init(0, 44, 0, 32), .text = "Two" },
|
|
1194
|
+
.{ .id = 4, .kind = .button, .frame = geometry.RectF.init(0, 88, 0, 32), .text = "Three" },
|
|
1195
|
+
};
|
|
1196
|
+
const full_scroll = canvas.Widget{
|
|
1197
|
+
.id = 1,
|
|
1198
|
+
.kind = .scroll_view,
|
|
1199
|
+
.frame = geometry.RectF.init(0, 0, 180, 72),
|
|
1200
|
+
.value = 48,
|
|
1201
|
+
.children = &full_children,
|
|
1202
|
+
};
|
|
1203
|
+
var full_nodes: [4]canvas.WidgetLayoutNode = undefined;
|
|
1204
|
+
const full_layout = try canvas.layoutWidgetTree(full_scroll, geometry.RectF.init(0, 0, 180, 72), &full_nodes);
|
|
1205
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", full_layout);
|
|
1206
|
+
|
|
1207
|
+
var retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
1208
|
+
try std.testing.expectEqual(@as(f32, 48), retained.findById(1).?.widget.value);
|
|
1209
|
+
try std.testing.expectEqual(@as(f32, -48), retained.findById(2).?.frame.y);
|
|
1210
|
+
|
|
1211
|
+
const short_children = [_]canvas.Widget{
|
|
1212
|
+
.{ .id = 2, .kind = .button, .frame = geometry.RectF.init(0, 0, 0, 32), .text = "One" },
|
|
1213
|
+
};
|
|
1214
|
+
const short_scroll = canvas.Widget{
|
|
1215
|
+
.id = 1,
|
|
1216
|
+
.kind = .scroll_view,
|
|
1217
|
+
.frame = geometry.RectF.init(0, 0, 180, 72),
|
|
1218
|
+
.value = 48,
|
|
1219
|
+
.children = &short_children,
|
|
1220
|
+
};
|
|
1221
|
+
var short_nodes: [2]canvas.WidgetLayoutNode = undefined;
|
|
1222
|
+
const short_layout = try canvas.layoutWidgetTree(short_scroll, geometry.RectF.init(0, 0, 180, 72), &short_nodes);
|
|
1223
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", short_layout);
|
|
1224
|
+
|
|
1225
|
+
retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
1226
|
+
try std.testing.expectEqual(@as(f32, 0), retained.findById(1).?.widget.value);
|
|
1227
|
+
try std.testing.expectEqual(@as(f32, 0), retained.findById(2).?.frame.y);
|
|
1228
|
+
try std.testing.expectEqual(@as(f32, 0), harness.runtime.views[0].widget_scroll_states[0].offset);
|
|
1229
|
+
try std.testing.expectEqual(@as(f32, 0), harness.runtime.views[0].widget_scroll_states[0].velocity);
|
|
1230
|
+
|
|
1231
|
+
const snapshot = harness.runtime.automationSnapshot("Widgets");
|
|
1232
|
+
try std.testing.expectEqual(@as(usize, 2), snapshot.widgets.len);
|
|
1233
|
+
try std.testing.expect(snapshot.widgets[0].scroll.present);
|
|
1234
|
+
try std.testing.expectEqual(@as(f32, 0), snapshot.widgets[0].scroll.offset);
|
|
1235
|
+
try std.testing.expectEqual(@as(f32, 72), snapshot.widgets[0].scroll.viewport_extent);
|
|
1236
|
+
try std.testing.expectEqual(@as(f32, 72), snapshot.widgets[0].scroll.content_extent);
|
|
1237
|
+
try std.testing.expectEqualDeep(geometry.RectF.init(10, 20, 180, 32), snapshot.widgets[1].bounds);
|
|
1238
|
+
}
|
|
1239
|
+
|
|
1240
|
+
test "runtime chains wheel input from saturated nested canvas scroll views" {
|
|
1241
|
+
const TestApp = struct {
|
|
1242
|
+
widget_pointer_count: u32 = 0,
|
|
1243
|
+
last_phase: canvas.WidgetPointerPhase = .hover,
|
|
1244
|
+
last_target_id: canvas.ObjectId = 0,
|
|
1245
|
+
|
|
1246
|
+
fn app(self: *@This()) App {
|
|
1247
|
+
return .{ .context = self, .name = "gpu-widget-scroll-chain", .source = platform.WebViewSource.html("<h1>Hello</h1>"), .event_fn = event };
|
|
1248
|
+
}
|
|
1249
|
+
|
|
1250
|
+
fn event(context: *anyopaque, runtime: *Runtime, event_value: Event) anyerror!void {
|
|
1251
|
+
_ = runtime;
|
|
1252
|
+
const self: *@This() = @ptrCast(@alignCast(context));
|
|
1253
|
+
switch (event_value) {
|
|
1254
|
+
.canvas_widget_pointer => |pointer_event| {
|
|
1255
|
+
self.widget_pointer_count += 1;
|
|
1256
|
+
self.last_phase = pointer_event.pointer.phase;
|
|
1257
|
+
self.last_target_id = if (pointer_event.target) |target| target.id else 0;
|
|
1258
|
+
},
|
|
1259
|
+
else => {},
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
};
|
|
1263
|
+
|
|
1264
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
1265
|
+
defer harness.destroy(std.testing.allocator);
|
|
1266
|
+
harness.null_platform.gpu_surfaces = true;
|
|
1267
|
+
var app_state: TestApp = .{};
|
|
1268
|
+
const app = app_state.app();
|
|
1269
|
+
try harness.start(app);
|
|
1270
|
+
|
|
1271
|
+
_ = try harness.runtime.createView(.{
|
|
1272
|
+
.window_id = 1,
|
|
1273
|
+
.label = "canvas",
|
|
1274
|
+
.kind = .gpu_surface,
|
|
1275
|
+
.frame = geometry.RectF.init(10, 20, 180, 80),
|
|
1276
|
+
});
|
|
1277
|
+
|
|
1278
|
+
const inner_children = [_]canvas.Widget{
|
|
1279
|
+
.{ .id = 3, .kind = .button, .frame = geometry.RectF.init(0, 0, 0, 32), .text = "Inner one" },
|
|
1280
|
+
.{ .id = 4, .kind = .button, .frame = geometry.RectF.init(0, 44, 0, 32), .text = "Inner two" },
|
|
1281
|
+
};
|
|
1282
|
+
const outer_children = [_]canvas.Widget{
|
|
1283
|
+
.{
|
|
1284
|
+
.id = 2,
|
|
1285
|
+
.kind = .scroll_view,
|
|
1286
|
+
.frame = geometry.RectF.init(0, 0, 0, 40),
|
|
1287
|
+
.value = 36,
|
|
1288
|
+
.children = &inner_children,
|
|
1289
|
+
},
|
|
1290
|
+
.{ .id = 5, .kind = .button, .frame = geometry.RectF.init(0, 120, 0, 32), .text = "Outer footer" },
|
|
1291
|
+
};
|
|
1292
|
+
const outer = canvas.Widget{
|
|
1293
|
+
.id = 1,
|
|
1294
|
+
.kind = .scroll_view,
|
|
1295
|
+
.children = &outer_children,
|
|
1296
|
+
};
|
|
1297
|
+
|
|
1298
|
+
var nodes: [6]canvas.WidgetLayoutNode = undefined;
|
|
1299
|
+
const layout = try canvas.layoutWidgetTree(outer, geometry.RectF.init(0, 0, 180, 80), &nodes);
|
|
1300
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
1301
|
+
|
|
1302
|
+
harness.runtime.invalidated = false;
|
|
1303
|
+
harness.runtime.dirty_region_count = 0;
|
|
1304
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
1305
|
+
.window_id = 1,
|
|
1306
|
+
.label = "canvas",
|
|
1307
|
+
.kind = .scroll,
|
|
1308
|
+
.x = 20,
|
|
1309
|
+
.y = 20,
|
|
1310
|
+
.delta_y = 24,
|
|
1311
|
+
} });
|
|
1312
|
+
|
|
1313
|
+
try std.testing.expectEqual(@as(u32, 1), app_state.widget_pointer_count);
|
|
1314
|
+
try std.testing.expectEqual(canvas.WidgetPointerPhase.wheel, app_state.last_phase);
|
|
1315
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 4), app_state.last_target_id);
|
|
1316
|
+
try std.testing.expect(harness.runtime.invalidated);
|
|
1317
|
+
try std.testing.expectEqual(@as(usize, 1), harness.runtime.pendingDirtyRegions().len);
|
|
1318
|
+
try std.testing.expectEqualDeep(geometry.RectF.init(10, 20, 180, 80), harness.runtime.pendingDirtyRegions()[0]);
|
|
1319
|
+
|
|
1320
|
+
const retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
1321
|
+
try std.testing.expectEqual(@as(f32, 24), retained.nodes[0].widget.value);
|
|
1322
|
+
try std.testing.expectEqual(@as(f32, 36), retained.nodes[1].widget.value);
|
|
1323
|
+
try std.testing.expectEqualDeep(geometry.RectF.init(0, -24, 180, 40), retained.nodes[1].frame);
|
|
1324
|
+
try std.testing.expectEqualDeep(geometry.RectF.init(0, -60, 180, 32), retained.nodes[2].frame);
|
|
1325
|
+
try std.testing.expectEqualDeep(geometry.RectF.init(0, -16, 180, 32), retained.nodes[3].frame);
|
|
1326
|
+
try std.testing.expectEqualDeep(geometry.RectF.init(0, 96, 180, 32), retained.nodes[4].frame);
|
|
1327
|
+
try std.testing.expect(harness.runtime.views[0].widget_scroll_states[0].velocity > 0);
|
|
1328
|
+
try std.testing.expectEqual(@as(f32, 0), harness.runtime.views[0].widget_scroll_states[1].velocity);
|
|
1329
|
+
}
|
|
1330
|
+
|
|
1331
|
+
test "runtime leaves virtualized canvas scroll views app driven" {
|
|
1332
|
+
const TestApp = struct {
|
|
1333
|
+
widget_pointer_count: u32 = 0,
|
|
1334
|
+
|
|
1335
|
+
fn app(self: *@This()) App {
|
|
1336
|
+
return .{ .context = self, .name = "gpu-widget-virtual-scroll", .source = platform.WebViewSource.html("<h1>Hello</h1>"), .event_fn = event };
|
|
1337
|
+
}
|
|
1338
|
+
|
|
1339
|
+
fn event(context: *anyopaque, runtime: *Runtime, event_value: Event) anyerror!void {
|
|
1340
|
+
_ = runtime;
|
|
1341
|
+
const self: *@This() = @ptrCast(@alignCast(context));
|
|
1342
|
+
switch (event_value) {
|
|
1343
|
+
.canvas_widget_pointer => self.widget_pointer_count += 1,
|
|
1344
|
+
else => {},
|
|
1345
|
+
}
|
|
1346
|
+
}
|
|
1347
|
+
};
|
|
1348
|
+
|
|
1349
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
1350
|
+
defer harness.destroy(std.testing.allocator);
|
|
1351
|
+
harness.null_platform.gpu_surfaces = true;
|
|
1352
|
+
var app_state: TestApp = .{};
|
|
1353
|
+
const app = app_state.app();
|
|
1354
|
+
try harness.start(app);
|
|
1355
|
+
|
|
1356
|
+
_ = try harness.runtime.createView(.{
|
|
1357
|
+
.window_id = 1,
|
|
1358
|
+
.label = "canvas",
|
|
1359
|
+
.kind = .gpu_surface,
|
|
1360
|
+
.frame = geometry.RectF.init(0, 0, 160, 48),
|
|
1361
|
+
});
|
|
1362
|
+
|
|
1363
|
+
const children = [_]canvas.Widget{
|
|
1364
|
+
.{ .id = 2, .kind = .button, .frame = geometry.RectF.init(0, 0, 0, 20), .text = "Zero" },
|
|
1365
|
+
.{ .id = 3, .kind = .button, .frame = geometry.RectF.init(0, 0, 0, 20), .text = "One" },
|
|
1366
|
+
.{ .id = 4, .kind = .button, .frame = geometry.RectF.init(0, 0, 0, 20), .text = "Two" },
|
|
1367
|
+
.{ .id = 5, .kind = .button, .frame = geometry.RectF.init(0, 0, 0, 20), .text = "Three" },
|
|
1368
|
+
};
|
|
1369
|
+
const scroll = canvas.Widget{
|
|
1370
|
+
.id = 1,
|
|
1371
|
+
.kind = .scroll_view,
|
|
1372
|
+
.layout = .{
|
|
1373
|
+
.virtualized = true,
|
|
1374
|
+
.virtual_item_extent = 20,
|
|
1375
|
+
.virtual_overscan = 1,
|
|
1376
|
+
},
|
|
1377
|
+
.children = &children,
|
|
1378
|
+
};
|
|
1379
|
+
var nodes: [5]canvas.WidgetLayoutNode = undefined;
|
|
1380
|
+
const layout = try canvas.layoutWidgetTree(scroll, geometry.RectF.init(0, 0, 160, 48), &nodes);
|
|
1381
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
1382
|
+
const retained_layout = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
1383
|
+
try std.testing.expectEqual(@as(usize, 0), retained_layout.nodes[0].widget.children.len);
|
|
1384
|
+
try std.testing.expectEqual(@as(?u32, 4), retained_layout.nodes[0].widget.semantics.list_item_count);
|
|
1385
|
+
try std.testing.expectEqual(@as(f32, 20), retained_layout.nodes[0].widget.layout.virtual_item_extent);
|
|
1386
|
+
|
|
1387
|
+
harness.runtime.invalidated = false;
|
|
1388
|
+
harness.runtime.dirty_region_count = 0;
|
|
1389
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
1390
|
+
.window_id = 1,
|
|
1391
|
+
.label = "canvas",
|
|
1392
|
+
.kind = .scroll,
|
|
1393
|
+
.x = 12,
|
|
1394
|
+
.y = 12,
|
|
1395
|
+
.delta_y = 20,
|
|
1396
|
+
} });
|
|
1397
|
+
|
|
1398
|
+
try std.testing.expectEqual(@as(u32, 1), app_state.widget_pointer_count);
|
|
1399
|
+
try std.testing.expect(!harness.runtime.invalidated);
|
|
1400
|
+
try std.testing.expectEqual(@as(usize, 0), harness.runtime.pendingDirtyRegions().len);
|
|
1401
|
+
|
|
1402
|
+
const retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
1403
|
+
try std.testing.expectEqual(@as(f32, 0), retained.nodes[0].widget.value);
|
|
1404
|
+
try std.testing.expectEqualDeep(layout.nodes[1].frame, retained.nodes[1].frame);
|
|
1405
|
+
try std.testing.expectEqual(@as(u64, 1), harness.runtime.views[0].widget_revision);
|
|
1406
|
+
|
|
1407
|
+
const snapshot = harness.runtime.automationSnapshot("Widgets");
|
|
1408
|
+
try std.testing.expectEqual(@as(usize, 5), snapshot.widgets.len);
|
|
1409
|
+
try std.testing.expect(snapshot.widgets[0].scroll.present);
|
|
1410
|
+
try std.testing.expectEqual(@as(f32, 0), snapshot.widgets[0].scroll.offset);
|
|
1411
|
+
try std.testing.expectEqual(@as(f32, 48), snapshot.widgets[0].scroll.viewport_extent);
|
|
1412
|
+
try std.testing.expectEqual(@as(f32, 80), snapshot.widgets[0].scroll.content_extent);
|
|
1413
|
+
try std.testing.expect(snapshot.widgets[0].actions.focus);
|
|
1414
|
+
try std.testing.expect(snapshot.widgets[0].actions.increment);
|
|
1415
|
+
try std.testing.expect(snapshot.widgets[0].actions.decrement);
|
|
1416
|
+
|
|
1417
|
+
harness.runtime.invalidated = false;
|
|
1418
|
+
harness.runtime.dirty_region_count = 0;
|
|
1419
|
+
const kinetic = try harness.runtime.stepCanvasWidgetKineticScroll(1, "canvas", 16);
|
|
1420
|
+
try std.testing.expectEqual(@as(u64, 1), kinetic.widget_revision);
|
|
1421
|
+
try std.testing.expect(!harness.runtime.invalidated);
|
|
1422
|
+
try std.testing.expectEqual(@as(usize, 0), harness.runtime.pendingDirtyRegions().len);
|
|
1423
|
+
}
|
|
1424
|
+
|
|
1425
|
+
test "user scroll offsets survive rebuilds until the source offset changes" {
|
|
1426
|
+
const TestApp = struct {
|
|
1427
|
+
fn app(self: *@This()) App {
|
|
1428
|
+
return .{ .context = self, .name = "gpu-scroll-reconcile", .source = platform.WebViewSource.html("<h1>Hello</h1>") };
|
|
1429
|
+
}
|
|
1430
|
+
};
|
|
1431
|
+
|
|
1432
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
1433
|
+
defer harness.destroy(std.testing.allocator);
|
|
1434
|
+
harness.null_platform.gpu_surfaces = true;
|
|
1435
|
+
var app_state: TestApp = .{};
|
|
1436
|
+
const app = app_state.app();
|
|
1437
|
+
try harness.start(app);
|
|
1438
|
+
|
|
1439
|
+
_ = try harness.runtime.createView(.{
|
|
1440
|
+
.window_id = 1,
|
|
1441
|
+
.label = "canvas",
|
|
1442
|
+
.kind = .gpu_surface,
|
|
1443
|
+
.frame = geometry.RectF.init(0, 0, 180, 64),
|
|
1444
|
+
});
|
|
1445
|
+
|
|
1446
|
+
const children = [_]canvas.Widget{
|
|
1447
|
+
.{ .id = 2, .kind = .button, .frame = geometry.RectF.init(0, 0, 0, 32), .text = "One" },
|
|
1448
|
+
.{ .id = 3, .kind = .button, .frame = geometry.RectF.init(0, 40, 0, 32), .text = "Two" },
|
|
1449
|
+
.{ .id = 4, .kind = .button, .frame = geometry.RectF.init(0, 80, 0, 32), .text = "Three" },
|
|
1450
|
+
};
|
|
1451
|
+
const source_root = canvas.Widget{ .id = 1, .kind = .scroll_view, .children = &children };
|
|
1452
|
+
var nodes: [4]canvas.WidgetLayoutNode = undefined;
|
|
1453
|
+
const layout = try canvas.layoutWidgetTree(source_root, geometry.RectF.init(0, 0, 180, 64), &nodes);
|
|
1454
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
1455
|
+
|
|
1456
|
+
// The user scrolls: runtime owns the offset.
|
|
1457
|
+
try harness.runtime.dispatchAutomationCommand(app, "widget-wheel canvas 1 18");
|
|
1458
|
+
try std.testing.expectEqual(@as(f32, 18), (try harness.runtime.canvasWidgetLayout(1, "canvas")).findById(1).?.widget.value);
|
|
1459
|
+
|
|
1460
|
+
// An elm-style rebuild with an unchanged source offset must not reset
|
|
1461
|
+
// the user's scroll position.
|
|
1462
|
+
var rebuild_nodes: [4]canvas.WidgetLayoutNode = undefined;
|
|
1463
|
+
const rebuild_layout = try canvas.layoutWidgetTree(source_root, geometry.RectF.init(0, 0, 180, 64), &rebuild_nodes);
|
|
1464
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", rebuild_layout);
|
|
1465
|
+
try std.testing.expectEqual(@as(f32, 18), (try harness.runtime.canvasWidgetLayout(1, "canvas")).findById(1).?.widget.value);
|
|
1466
|
+
|
|
1467
|
+
// A source-side offset change (programmatic scroll) wins over the
|
|
1468
|
+
// runtime offset.
|
|
1469
|
+
var scrolled_root = source_root;
|
|
1470
|
+
scrolled_root.value = 6;
|
|
1471
|
+
var programmatic_nodes: [4]canvas.WidgetLayoutNode = undefined;
|
|
1472
|
+
const programmatic_layout = try canvas.layoutWidgetTree(scrolled_root, geometry.RectF.init(0, 0, 180, 64), &programmatic_nodes);
|
|
1473
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", programmatic_layout);
|
|
1474
|
+
try std.testing.expectEqual(@as(f32, 6), (try harness.runtime.canvasWidgetLayout(1, "canvas")).findById(1).?.widget.value);
|
|
1475
|
+
|
|
1476
|
+
// And the runtime owns it again from the new baseline.
|
|
1477
|
+
var final_nodes: [4]canvas.WidgetLayoutNode = undefined;
|
|
1478
|
+
const final_layout = try canvas.layoutWidgetTree(scrolled_root, geometry.RectF.init(0, 0, 180, 64), &final_nodes);
|
|
1479
|
+
try harness.runtime.dispatchAutomationCommand(app, "widget-wheel canvas 1 12");
|
|
1480
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", final_layout);
|
|
1481
|
+
try std.testing.expectEqual(@as(f32, 18), (try harness.runtime.canvasWidgetLayout(1, "canvas")).findById(1).?.widget.value);
|
|
1482
|
+
}
|
|
1483
|
+
|
|
1484
|
+
test "engine wheel scrolls a windowed virtual list against its declared extent" {
|
|
1485
|
+
const TestApp = struct {
|
|
1486
|
+
fn app(self: *@This()) App {
|
|
1487
|
+
return .{ .context = self, .name = "gpu-virtual-window-scroll", .source = platform.WebViewSource.html("<h1>Hello</h1>") };
|
|
1488
|
+
}
|
|
1489
|
+
};
|
|
1490
|
+
|
|
1491
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
1492
|
+
defer harness.destroy(std.testing.allocator);
|
|
1493
|
+
harness.null_platform.gpu_surfaces = true;
|
|
1494
|
+
var app_state: TestApp = .{};
|
|
1495
|
+
const app = app_state.app();
|
|
1496
|
+
try harness.start(app);
|
|
1497
|
+
|
|
1498
|
+
_ = try harness.runtime.createView(.{
|
|
1499
|
+
.window_id = 1,
|
|
1500
|
+
.label = "canvas",
|
|
1501
|
+
.kind = .gpu_surface,
|
|
1502
|
+
.frame = geometry.RectF.init(0, 0, 180, 64),
|
|
1503
|
+
});
|
|
1504
|
+
|
|
1505
|
+
// A 1000-item windowed virtual list mounting a four-row window.
|
|
1506
|
+
// Legacy virtualized containers refuse engine scrolling (their offset
|
|
1507
|
+
// is model-driven); the DECLARED count makes this one runtime-owned.
|
|
1508
|
+
const window = [_]canvas.Widget{
|
|
1509
|
+
.{ .id = 2, .kind = .list_item, .frame = geometry.RectF.init(0, 0, 0, 20), .text = "Item 0" },
|
|
1510
|
+
.{ .id = 3, .kind = .list_item, .frame = geometry.RectF.init(0, 0, 0, 20), .text = "Item 1" },
|
|
1511
|
+
.{ .id = 4, .kind = .list_item, .frame = geometry.RectF.init(0, 0, 0, 20), .text = "Item 2" },
|
|
1512
|
+
.{ .id = 5, .kind = .list_item, .frame = geometry.RectF.init(0, 0, 0, 20), .text = "Item 3" },
|
|
1513
|
+
};
|
|
1514
|
+
const list = canvas.Widget{
|
|
1515
|
+
.id = 1,
|
|
1516
|
+
.kind = .scroll_view,
|
|
1517
|
+
.layout = .{
|
|
1518
|
+
.virtualized = true,
|
|
1519
|
+
.virtual_item_extent = 20,
|
|
1520
|
+
.virtual_overscan = 1,
|
|
1521
|
+
.virtual_item_count = 1000,
|
|
1522
|
+
},
|
|
1523
|
+
.children = &window,
|
|
1524
|
+
};
|
|
1525
|
+
var nodes: [8]canvas.WidgetLayoutNode = undefined;
|
|
1526
|
+
const layout = try canvas.layoutWidgetTree(list, geometry.RectF.init(0, 0, 180, 64), &nodes);
|
|
1527
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
1528
|
+
|
|
1529
|
+
// Wheel input applies through the ordinary engine scroll path.
|
|
1530
|
+
try harness.runtime.dispatchAutomationCommand(app, "widget-wheel canvas 1 30");
|
|
1531
|
+
var retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
1532
|
+
try std.testing.expectEqual(@as(f32, 30), retained.findById(1).?.widget.value);
|
|
1533
|
+
|
|
1534
|
+
// The scroll state reports the DECLARED virtual extent (1000 x 20),
|
|
1535
|
+
// not the four mounted rows.
|
|
1536
|
+
const state = harness.runtime.views[0].canvasWidgetScrollStateById(1).?;
|
|
1537
|
+
try std.testing.expectEqual(@as(f32, 20_000), state.content_extent);
|
|
1538
|
+
try std.testing.expectEqual(@as(f32, 64), state.viewport_extent);
|
|
1539
|
+
|
|
1540
|
+
// A rebuild whose source offset overshoots the end clamps against
|
|
1541
|
+
// the virtual extent (max offset 20_000 - 64).
|
|
1542
|
+
var overshoot = list;
|
|
1543
|
+
overshoot.value = 30_000;
|
|
1544
|
+
var overshoot_nodes: [8]canvas.WidgetLayoutNode = undefined;
|
|
1545
|
+
const overshoot_layout = try canvas.layoutWidgetTree(overshoot, geometry.RectF.init(0, 0, 180, 64), &overshoot_nodes);
|
|
1546
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", overshoot_layout);
|
|
1547
|
+
retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
1548
|
+
try std.testing.expectEqual(@as(f32, 19_936), retained.findById(1).?.widget.value);
|
|
1549
|
+
}
|