@native-sdk/cli 0.0.0 → 0.4.0
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/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 +44 -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,2691 @@
|
|
|
1
|
+
const support = @import("test_support.zig");
|
|
2
|
+
const std = support.std;
|
|
3
|
+
const geometry = support.geometry;
|
|
4
|
+
const canvas = support.canvas;
|
|
5
|
+
const drawing_model = support.drawing_model;
|
|
6
|
+
const text_model = support.text_model;
|
|
7
|
+
const render_model = support.render_model;
|
|
8
|
+
const event_model = support.event_model;
|
|
9
|
+
const equality_model = support.equality_model;
|
|
10
|
+
const widget_runtime = support.widget_runtime;
|
|
11
|
+
const Error = support.Error;
|
|
12
|
+
const ObjectId = support.ObjectId;
|
|
13
|
+
const ImageId = support.ImageId;
|
|
14
|
+
const FontId = support.FontId;
|
|
15
|
+
const default_sans_font_id = support.default_sans_font_id;
|
|
16
|
+
const default_mono_font_id = support.default_mono_font_id;
|
|
17
|
+
const default_sans_font_family = support.default_sans_font_family;
|
|
18
|
+
const default_mono_font_family = support.default_mono_font_family;
|
|
19
|
+
const default_glyph_atlas_cache_retention_frames = support.default_glyph_atlas_cache_retention_frames;
|
|
20
|
+
const default_text_layout_cache_retention_frames = support.default_text_layout_cache_retention_frames;
|
|
21
|
+
const Color = support.Color;
|
|
22
|
+
const Affine = support.Affine;
|
|
23
|
+
const Radius = support.Radius;
|
|
24
|
+
const GradientStop = support.GradientStop;
|
|
25
|
+
const LinearGradient = support.LinearGradient;
|
|
26
|
+
const Fill = support.Fill;
|
|
27
|
+
const Stroke = support.Stroke;
|
|
28
|
+
const Clip = support.Clip;
|
|
29
|
+
const FillRect = support.FillRect;
|
|
30
|
+
const StrokeRect = support.StrokeRect;
|
|
31
|
+
const FillRoundedRect = support.FillRoundedRect;
|
|
32
|
+
const Line = support.Line;
|
|
33
|
+
const PathVerb = support.PathVerb;
|
|
34
|
+
const PathElement = support.PathElement;
|
|
35
|
+
const FillPath = support.FillPath;
|
|
36
|
+
const StrokePath = support.StrokePath;
|
|
37
|
+
const ImageFit = support.ImageFit;
|
|
38
|
+
const ImageSampling = support.ImageSampling;
|
|
39
|
+
const DrawImage = support.DrawImage;
|
|
40
|
+
const Shadow = support.Shadow;
|
|
41
|
+
const Blur = support.Blur;
|
|
42
|
+
const Glyph = support.Glyph;
|
|
43
|
+
const GlyphAtlasKey = support.GlyphAtlasKey;
|
|
44
|
+
const GlyphAtlasEntry = support.GlyphAtlasEntry;
|
|
45
|
+
const GlyphAtlasPlan = support.GlyphAtlasPlan;
|
|
46
|
+
const GlyphAtlasPlanner = support.GlyphAtlasPlanner;
|
|
47
|
+
const GlyphAtlasCacheEntry = support.GlyphAtlasCacheEntry;
|
|
48
|
+
const GlyphAtlasCacheActionKind = support.GlyphAtlasCacheActionKind;
|
|
49
|
+
const GlyphAtlasCacheAction = support.GlyphAtlasCacheAction;
|
|
50
|
+
const GlyphAtlasCachePlan = support.GlyphAtlasCachePlan;
|
|
51
|
+
const GlyphAtlasCachePlanner = support.GlyphAtlasCachePlanner;
|
|
52
|
+
const DrawText = support.DrawText;
|
|
53
|
+
const TextWrap = support.TextWrap;
|
|
54
|
+
const TextAlign = support.TextAlign;
|
|
55
|
+
const TextLayoutOptions = support.TextLayoutOptions;
|
|
56
|
+
const TextLine = support.TextLine;
|
|
57
|
+
const TextLayout = support.TextLayout;
|
|
58
|
+
const TextLayoutKey = support.TextLayoutKey;
|
|
59
|
+
const TextLayoutPlan = support.TextLayoutPlan;
|
|
60
|
+
const TextLayoutPlanSet = support.TextLayoutPlanSet;
|
|
61
|
+
const TextLayoutPlanner = support.TextLayoutPlanner;
|
|
62
|
+
const TextLayoutCacheEntry = support.TextLayoutCacheEntry;
|
|
63
|
+
const TextLayoutCacheActionKind = support.TextLayoutCacheActionKind;
|
|
64
|
+
const TextLayoutCacheAction = support.TextLayoutCacheAction;
|
|
65
|
+
const TextLayoutCachePlan = support.TextLayoutCachePlan;
|
|
66
|
+
const TextLayoutCachePlanner = support.TextLayoutCachePlanner;
|
|
67
|
+
const TextRange = support.TextRange;
|
|
68
|
+
const TextSelectionRect = support.TextSelectionRect;
|
|
69
|
+
const TextSelection = support.TextSelection;
|
|
70
|
+
const TextCaretDirection = support.TextCaretDirection;
|
|
71
|
+
const TextCaretMove = support.TextCaretMove;
|
|
72
|
+
const TextCompositionUpdate = support.TextCompositionUpdate;
|
|
73
|
+
const TextInputEvent = support.TextInputEvent;
|
|
74
|
+
const TextEditState = support.TextEditState;
|
|
75
|
+
const CanvasCommand = support.CanvasCommand;
|
|
76
|
+
const CommandRef = support.CommandRef;
|
|
77
|
+
const DiffKind = support.DiffKind;
|
|
78
|
+
const DiffChange = support.DiffChange;
|
|
79
|
+
const Builder = support.Builder;
|
|
80
|
+
const max_render_state_stack = support.max_render_state_stack;
|
|
81
|
+
const RenderState = support.RenderState;
|
|
82
|
+
const RenderCommand = support.RenderCommand;
|
|
83
|
+
const CanvasRenderOverride = support.CanvasRenderOverride;
|
|
84
|
+
const CanvasRenderAnimation = support.CanvasRenderAnimation;
|
|
85
|
+
const applyRenderOverrides = support.applyRenderOverrides;
|
|
86
|
+
const renderOverrideDirtyBounds = support.renderOverrideDirtyBounds;
|
|
87
|
+
const RenderPlan = support.RenderPlan;
|
|
88
|
+
const RenderPlanner = support.RenderPlanner;
|
|
89
|
+
const RenderPipelineKind = support.RenderPipelineKind;
|
|
90
|
+
const RenderBatch = support.RenderBatch;
|
|
91
|
+
const RenderBatchPlanner = support.RenderBatchPlanner;
|
|
92
|
+
const RenderBatchPlan = support.RenderBatchPlan;
|
|
93
|
+
const RenderPipelineCacheEntry = support.RenderPipelineCacheEntry;
|
|
94
|
+
const RenderPipelineCacheActionKind = support.RenderPipelineCacheActionKind;
|
|
95
|
+
const RenderPipelineCacheAction = support.RenderPipelineCacheAction;
|
|
96
|
+
const RenderPipelineCachePlanner = support.RenderPipelineCachePlanner;
|
|
97
|
+
const RenderPipelineCachePlan = support.RenderPipelineCachePlan;
|
|
98
|
+
const RenderPathGeometryKind = support.RenderPathGeometryKind;
|
|
99
|
+
const RenderPathGeometry = support.RenderPathGeometry;
|
|
100
|
+
const RenderPathGeometryPlan = support.RenderPathGeometryPlan;
|
|
101
|
+
const RenderPathGeometryPlanner = support.RenderPathGeometryPlanner;
|
|
102
|
+
const RenderPathGeometryKey = support.RenderPathGeometryKey;
|
|
103
|
+
const RenderPathGeometryCacheEntry = support.RenderPathGeometryCacheEntry;
|
|
104
|
+
const RenderPathGeometryCacheActionKind = support.RenderPathGeometryCacheActionKind;
|
|
105
|
+
const RenderPathGeometryCacheAction = support.RenderPathGeometryCacheAction;
|
|
106
|
+
const RenderPathGeometryCachePlan = support.RenderPathGeometryCachePlan;
|
|
107
|
+
const RenderPathGeometryCachePlanner = support.RenderPathGeometryCachePlanner;
|
|
108
|
+
const RenderImage = support.RenderImage;
|
|
109
|
+
const RenderImagePlan = support.RenderImagePlan;
|
|
110
|
+
const RenderImagePlanner = support.RenderImagePlanner;
|
|
111
|
+
const RenderImageKey = support.RenderImageKey;
|
|
112
|
+
const RenderImageCacheEntry = support.RenderImageCacheEntry;
|
|
113
|
+
const RenderImageCacheActionKind = support.RenderImageCacheActionKind;
|
|
114
|
+
const RenderImageCacheAction = support.RenderImageCacheAction;
|
|
115
|
+
const RenderImageCachePlan = support.RenderImageCachePlan;
|
|
116
|
+
const RenderImageCachePlanner = support.RenderImageCachePlanner;
|
|
117
|
+
const RenderResourceKind = support.RenderResourceKind;
|
|
118
|
+
const RenderResource = support.RenderResource;
|
|
119
|
+
const RenderResourcePlan = support.RenderResourcePlan;
|
|
120
|
+
const RenderResourcePlanner = support.RenderResourcePlanner;
|
|
121
|
+
const RenderResourceKey = support.RenderResourceKey;
|
|
122
|
+
const RenderResourceCacheEntry = support.RenderResourceCacheEntry;
|
|
123
|
+
const RenderResourceCacheActionKind = support.RenderResourceCacheActionKind;
|
|
124
|
+
const RenderResourceCacheAction = support.RenderResourceCacheAction;
|
|
125
|
+
const RenderResourceCachePlan = support.RenderResourceCachePlan;
|
|
126
|
+
const RenderResourceCachePlanner = support.RenderResourceCachePlanner;
|
|
127
|
+
const RenderLayer = support.RenderLayer;
|
|
128
|
+
const RenderLayerPlan = support.RenderLayerPlan;
|
|
129
|
+
const RenderLayerPlanner = support.RenderLayerPlanner;
|
|
130
|
+
const RenderLayerKey = support.RenderLayerKey;
|
|
131
|
+
const RenderLayerCacheEntry = support.RenderLayerCacheEntry;
|
|
132
|
+
const RenderLayerCacheActionKind = support.RenderLayerCacheActionKind;
|
|
133
|
+
const RenderLayerCacheAction = support.RenderLayerCacheAction;
|
|
134
|
+
const RenderLayerCachePlan = support.RenderLayerCachePlan;
|
|
135
|
+
const RenderLayerCachePlanner = support.RenderLayerCachePlanner;
|
|
136
|
+
const VisualEffectKind = support.VisualEffectKind;
|
|
137
|
+
const VisualEffect = support.VisualEffect;
|
|
138
|
+
const VisualEffectPlan = support.VisualEffectPlan;
|
|
139
|
+
const VisualEffectPlanner = support.VisualEffectPlanner;
|
|
140
|
+
const VisualEffectKey = support.VisualEffectKey;
|
|
141
|
+
const VisualEffectCacheEntry = support.VisualEffectCacheEntry;
|
|
142
|
+
const VisualEffectCacheActionKind = support.VisualEffectCacheActionKind;
|
|
143
|
+
const VisualEffectCacheAction = support.VisualEffectCacheAction;
|
|
144
|
+
const VisualEffectCachePlan = support.VisualEffectCachePlan;
|
|
145
|
+
const VisualEffectCachePlanner = support.VisualEffectCachePlanner;
|
|
146
|
+
const CanvasFrameOptions = support.CanvasFrameOptions;
|
|
147
|
+
const CanvasFrameStorage = support.CanvasFrameStorage;
|
|
148
|
+
const CanvasFrameBudget = support.CanvasFrameBudget;
|
|
149
|
+
const CanvasFrameBudgetStatus = support.CanvasFrameBudgetStatus;
|
|
150
|
+
const CanvasFrameDiagnostics = support.CanvasFrameDiagnostics;
|
|
151
|
+
const CanvasFrameProfileRisk = support.CanvasFrameProfileRisk;
|
|
152
|
+
const CanvasFrameProfile = support.CanvasFrameProfile;
|
|
153
|
+
const CanvasRenderPass = support.CanvasRenderPass;
|
|
154
|
+
const CanvasFrame = support.CanvasFrame;
|
|
155
|
+
const buildCanvasFrame = support.buildCanvasFrame;
|
|
156
|
+
const CanvasRenderPassLoadAction = support.CanvasRenderPassLoadAction;
|
|
157
|
+
const RenderEncoderBeginPass = support.RenderEncoderBeginPass;
|
|
158
|
+
const RenderEncoderCommand = support.RenderEncoderCommand;
|
|
159
|
+
const RenderEncoderPlan = support.RenderEncoderPlan;
|
|
160
|
+
const RenderEncoderPlanner = support.RenderEncoderPlanner;
|
|
161
|
+
const CanvasGpuCommandKind = support.CanvasGpuCommandKind;
|
|
162
|
+
const CanvasGpuRoundedRect = support.CanvasGpuRoundedRect;
|
|
163
|
+
const CanvasGpuStrokeRect = support.CanvasGpuStrokeRect;
|
|
164
|
+
const CanvasGpuLine = support.CanvasGpuLine;
|
|
165
|
+
const CanvasGpuShape = support.CanvasGpuShape;
|
|
166
|
+
const CanvasGpuPaint = support.CanvasGpuPaint;
|
|
167
|
+
const CanvasGpuImage = support.CanvasGpuImage;
|
|
168
|
+
const CanvasGpuText = support.CanvasGpuText;
|
|
169
|
+
const CanvasGpuShadow = support.CanvasGpuShadow;
|
|
170
|
+
const CanvasGpuBlur = support.CanvasGpuBlur;
|
|
171
|
+
const CanvasGpuEffect = support.CanvasGpuEffect;
|
|
172
|
+
const CanvasGpuCommand = support.CanvasGpuCommand;
|
|
173
|
+
const CanvasGpuPacket = support.CanvasGpuPacket;
|
|
174
|
+
const CanvasGpuPacketSummary = support.CanvasGpuPacketSummary;
|
|
175
|
+
const CanvasGpuPacketPlanner = support.CanvasGpuPacketPlanner;
|
|
176
|
+
const ReferenceImage = support.ReferenceImage;
|
|
177
|
+
const ReferenceRenderSurface = support.ReferenceRenderSurface;
|
|
178
|
+
const Density = support.Density;
|
|
179
|
+
const Easing = support.Easing;
|
|
180
|
+
const ColorScheme = support.ColorScheme;
|
|
181
|
+
const ColorContrast = support.ColorContrast;
|
|
182
|
+
const ThemeOptions = support.ThemeOptions;
|
|
183
|
+
const ColorTokens = support.ColorTokens;
|
|
184
|
+
const FontFamily = support.FontFamily;
|
|
185
|
+
const TypographyTokens = support.TypographyTokens;
|
|
186
|
+
const SpacingTokens = support.SpacingTokens;
|
|
187
|
+
const RadiusTokens = support.RadiusTokens;
|
|
188
|
+
const StrokeTokens = support.StrokeTokens;
|
|
189
|
+
const ShadowToken = support.ShadowToken;
|
|
190
|
+
const ShadowTokens = support.ShadowTokens;
|
|
191
|
+
const BlurTokens = support.BlurTokens;
|
|
192
|
+
const MotionDuration = support.MotionDuration;
|
|
193
|
+
const MotionAnimationOptions = support.MotionAnimationOptions;
|
|
194
|
+
const MotionTokens = support.MotionTokens;
|
|
195
|
+
const SpringToken = support.SpringToken;
|
|
196
|
+
const BlurTokenRef = support.BlurTokenRef;
|
|
197
|
+
const ScrollPhysics = support.ScrollPhysics;
|
|
198
|
+
const ScrollState = support.ScrollState;
|
|
199
|
+
const VirtualListOptions = support.VirtualListOptions;
|
|
200
|
+
const VirtualListRange = support.VirtualListRange;
|
|
201
|
+
const virtualListRange = support.virtualListRange;
|
|
202
|
+
const LayerTokens = support.LayerTokens;
|
|
203
|
+
const PixelSnapTokens = support.PixelSnapTokens;
|
|
204
|
+
const ControlVisualTokens = support.ControlVisualTokens;
|
|
205
|
+
const ControlTokens = support.ControlTokens;
|
|
206
|
+
const ColorTokenOverrides = support.ColorTokenOverrides;
|
|
207
|
+
const TypographyTokenOverrides = support.TypographyTokenOverrides;
|
|
208
|
+
const SpacingTokenOverrides = support.SpacingTokenOverrides;
|
|
209
|
+
const RadiusTokenOverrides = support.RadiusTokenOverrides;
|
|
210
|
+
const StrokeTokenOverrides = support.StrokeTokenOverrides;
|
|
211
|
+
const ShadowTokenOverrides = support.ShadowTokenOverrides;
|
|
212
|
+
const ShadowTokensOverrides = support.ShadowTokensOverrides;
|
|
213
|
+
const BlurTokenOverrides = support.BlurTokenOverrides;
|
|
214
|
+
const SpringTokenOverrides = support.SpringTokenOverrides;
|
|
215
|
+
const MotionTokenOverrides = support.MotionTokenOverrides;
|
|
216
|
+
const ScrollPhysicsOverrides = support.ScrollPhysicsOverrides;
|
|
217
|
+
const LayerTokenOverrides = support.LayerTokenOverrides;
|
|
218
|
+
const PixelSnapTokenOverrides = support.PixelSnapTokenOverrides;
|
|
219
|
+
const ControlVisualTokenOverrides = support.ControlVisualTokenOverrides;
|
|
220
|
+
const ControlTokenOverrides = support.ControlTokenOverrides;
|
|
221
|
+
const DesignTokenOverrides = support.DesignTokenOverrides;
|
|
222
|
+
const DesignTokens = support.DesignTokens;
|
|
223
|
+
const WidgetKind = support.WidgetKind;
|
|
224
|
+
const WidgetCursor = support.WidgetCursor;
|
|
225
|
+
const WidgetState = support.WidgetState;
|
|
226
|
+
const WidgetRenderState = support.WidgetRenderState;
|
|
227
|
+
const WidgetMainAlignment = support.WidgetMainAlignment;
|
|
228
|
+
const WidgetCrossAlignment = support.WidgetCrossAlignment;
|
|
229
|
+
const WidgetLayoutStyle = support.WidgetLayoutStyle;
|
|
230
|
+
const WidgetStyle = support.WidgetStyle;
|
|
231
|
+
const WidgetVariant = support.WidgetVariant;
|
|
232
|
+
const WidgetSize = support.WidgetSize;
|
|
233
|
+
const WidgetRole = support.WidgetRole;
|
|
234
|
+
const BuiltinComponentStyle = support.BuiltinComponentStyle;
|
|
235
|
+
const BuiltinComponentKind = support.BuiltinComponentKind;
|
|
236
|
+
const builtin_component_kinds = support.builtin_component_kinds;
|
|
237
|
+
const builtin_component_names = support.builtin_component_names;
|
|
238
|
+
const BuiltinComponentDescriptor = support.BuiltinComponentDescriptor;
|
|
239
|
+
const builtinComponentCount = support.builtinComponentCount;
|
|
240
|
+
const builtinComponentName = support.builtinComponentName;
|
|
241
|
+
const builtinComponentDescriptor = support.builtinComponentDescriptor;
|
|
242
|
+
const WidgetActions = support.WidgetActions;
|
|
243
|
+
const WidgetSemantics = support.WidgetSemantics;
|
|
244
|
+
const Widget = support.Widget;
|
|
245
|
+
const BuiltinComponentOptions = support.BuiltinComponentOptions;
|
|
246
|
+
const WidgetCommandPart = support.WidgetCommandPart;
|
|
247
|
+
const BuiltinSurfacePlacementOptions = support.BuiltinSurfacePlacementOptions;
|
|
248
|
+
const BuiltinSurfaceBackdropOptions = support.BuiltinSurfaceBackdropOptions;
|
|
249
|
+
const BuiltinStatusBarOptions = support.BuiltinStatusBarOptions;
|
|
250
|
+
const BuiltinSurfaceEnterAnimationOptions = support.BuiltinSurfaceEnterAnimationOptions;
|
|
251
|
+
const builtinComponentWidget = support.builtinComponentWidget;
|
|
252
|
+
const widgetCommandPartId = support.widgetCommandPartId;
|
|
253
|
+
const builtinSurfaceBackdropWidget = support.builtinSurfaceBackdropWidget;
|
|
254
|
+
const builtinStatusBarWidget = support.builtinStatusBarWidget;
|
|
255
|
+
const builtinSurfaceFrame = support.builtinSurfaceFrame;
|
|
256
|
+
const appendBuiltinSurfaceEnterAnimations = support.appendBuiltinSurfaceEnterAnimations;
|
|
257
|
+
const builtinSurfaceEnterOffset = support.builtinSurfaceEnterOffset;
|
|
258
|
+
const max_widget_depth = support.max_widget_depth;
|
|
259
|
+
const max_widget_text_range_rects = support.max_widget_text_range_rects;
|
|
260
|
+
const WidgetLayoutNode = support.WidgetLayoutNode;
|
|
261
|
+
const WidgetHit = support.WidgetHit;
|
|
262
|
+
const WidgetPointerPhase = support.WidgetPointerPhase;
|
|
263
|
+
const WidgetPointerEvent = support.WidgetPointerEvent;
|
|
264
|
+
const WidgetKeyboardPhase = support.WidgetKeyboardPhase;
|
|
265
|
+
const WidgetKeyboardModifiers = support.WidgetKeyboardModifiers;
|
|
266
|
+
const WidgetKeyboardEvent = support.WidgetKeyboardEvent;
|
|
267
|
+
const WidgetControlIntentKind = support.WidgetControlIntentKind;
|
|
268
|
+
const WidgetControlIntent = support.WidgetControlIntent;
|
|
269
|
+
const WidgetSemanticAction = support.WidgetSemanticAction;
|
|
270
|
+
const WidgetFileDropEvent = support.WidgetFileDropEvent;
|
|
271
|
+
const WidgetDragEvent = support.WidgetDragEvent;
|
|
272
|
+
const WidgetEventPhase = support.WidgetEventPhase;
|
|
273
|
+
const WidgetEventRouteEntry = support.WidgetEventRouteEntry;
|
|
274
|
+
const WidgetEventRoute = support.WidgetEventRoute;
|
|
275
|
+
const WidgetKeyboardRoute = support.WidgetKeyboardRoute;
|
|
276
|
+
const WidgetFocusDirection = support.WidgetFocusDirection;
|
|
277
|
+
const WidgetFocusTarget = support.WidgetFocusTarget;
|
|
278
|
+
const WidgetScrollMetrics = support.WidgetScrollMetrics;
|
|
279
|
+
const WidgetListMetrics = support.WidgetListMetrics;
|
|
280
|
+
const WidgetSemanticsNode = support.WidgetSemanticsNode;
|
|
281
|
+
const WidgetInvalidationKind = support.WidgetInvalidationKind;
|
|
282
|
+
const WidgetInvalidation = support.WidgetInvalidation;
|
|
283
|
+
const widgetKeyboardControlIntent = support.widgetKeyboardControlIntent;
|
|
284
|
+
const widgetSemanticControlIntent = support.widgetSemanticControlIntent;
|
|
285
|
+
const widgetSemanticControlIntentWithActions = support.widgetSemanticControlIntentWithActions;
|
|
286
|
+
const isWidgetActivationKey = support.isWidgetActivationKey;
|
|
287
|
+
const widgetSliderKeyboardValue = support.widgetSliderKeyboardValue;
|
|
288
|
+
const widgetScrollKeyboardIntent = support.widgetScrollKeyboardIntent;
|
|
289
|
+
const widgetScrollKeyboardDelta = support.widgetScrollKeyboardDelta;
|
|
290
|
+
const WidgetLayoutTree = support.WidgetLayoutTree;
|
|
291
|
+
const DisplayList = support.DisplayList;
|
|
292
|
+
const emitWidgetTree = support.emitWidgetTree;
|
|
293
|
+
const layoutWidgetTree = support.layoutWidgetTree;
|
|
294
|
+
const layoutWidgetTreeWithTokens = support.layoutWidgetTreeWithTokens;
|
|
295
|
+
const layoutTextRun = support.layoutTextRun;
|
|
296
|
+
const layoutTextRunPlan = support.layoutTextRunPlan;
|
|
297
|
+
const layoutTextCaretRect = support.layoutTextCaretRect;
|
|
298
|
+
const textCaretRectForLayout = support.textCaretRectForLayout;
|
|
299
|
+
const layoutTextSelectionRects = support.layoutTextSelectionRects;
|
|
300
|
+
const textSelectionRectsForLayout = support.textSelectionRectsForLayout;
|
|
301
|
+
const layoutTextOffsetForPoint = support.layoutTextOffsetForPoint;
|
|
302
|
+
const textOffsetForLayoutPoint = support.textOffsetForLayoutPoint;
|
|
303
|
+
const applyTextInputEvent = support.applyTextInputEvent;
|
|
304
|
+
const sampleCanvasRenderAnimations = support.sampleCanvasRenderAnimations;
|
|
305
|
+
const emitWidgetLayout = support.emitWidgetLayout;
|
|
306
|
+
const toggleWidgetKnobCommandId = support.toggleWidgetKnobCommandId;
|
|
307
|
+
const toggleWidgetKnobTravel = support.toggleWidgetKnobTravel;
|
|
308
|
+
const textSelectionForWidgetPoint = support.textSelectionForWidgetPoint;
|
|
309
|
+
const textOffsetForWidgetPoint = support.textOffsetForWidgetPoint;
|
|
310
|
+
const textInputViewportForWidget = support.textInputViewportForWidget;
|
|
311
|
+
const textInputContentExtentForWidget = support.textInputContentExtentForWidget;
|
|
312
|
+
const textInputMaxScrollOffsetForWidget = support.textInputMaxScrollOffsetForWidget;
|
|
313
|
+
const clampedTextInputScrollOffsetForWidget = support.clampedTextInputScrollOffsetForWidget;
|
|
314
|
+
const intrinsicWidgetSize = support.intrinsicWidgetSize;
|
|
315
|
+
const cursorForWidgetHit = support.cursorForWidgetHit;
|
|
316
|
+
const cursorForWidgetTarget = support.cursorForWidgetTarget;
|
|
317
|
+
const WidgetTextGeometry = support.WidgetTextGeometry;
|
|
318
|
+
const textGeometryForWidget = support.textGeometryForWidget;
|
|
319
|
+
const virtualWidgetScrollContentExtent = support.virtualWidgetScrollContentExtent;
|
|
320
|
+
const virtualWidgetScrollContentExtentWithTokens = support.virtualWidgetScrollContentExtentWithTokens;
|
|
321
|
+
const writeCanvasGpuPacketJson = support.writeCanvasGpuPacketJson;
|
|
322
|
+
const strokeBounds = support.strokeBounds;
|
|
323
|
+
const shadowBounds = support.shadowBounds;
|
|
324
|
+
const semanticActions = support.semanticActions;
|
|
325
|
+
const defaultSemanticActions = support.defaultSemanticActions;
|
|
326
|
+
const defaultFocusable = support.defaultFocusable;
|
|
327
|
+
const textLineBounds = support.textLineBounds;
|
|
328
|
+
const textBounds = support.textBounds;
|
|
329
|
+
const estimateTextWidth = support.estimateTextWidth;
|
|
330
|
+
const estimateTextWidthForFont = support.estimateTextWidthForFont;
|
|
331
|
+
const estimateTextAdvanceForBytes = support.estimateTextAdvanceForBytes;
|
|
332
|
+
const estimatedGlyphAdvance = support.estimatedGlyphAdvance;
|
|
333
|
+
const snapTextSelection = support.snapTextSelection;
|
|
334
|
+
const snapTextRange = support.snapTextRange;
|
|
335
|
+
const nextTextOffset = support.nextTextOffset;
|
|
336
|
+
const nextTextLineEnd = support.nextTextLineEnd;
|
|
337
|
+
const isTextBreakByte = support.isTextBreakByte;
|
|
338
|
+
const textLineRange = support.textLineRange;
|
|
339
|
+
const textLineCaretX = support.textLineCaretX;
|
|
340
|
+
const motionProgress = support.motionProgress;
|
|
341
|
+
const renderImageFingerprint = support.renderImageFingerprint;
|
|
342
|
+
const renderImageFingerprintForResource = support.renderImageFingerprintForResource;
|
|
343
|
+
const commandsEqual = support.commandsEqual;
|
|
344
|
+
const rectsEqual = support.rectsEqual;
|
|
345
|
+
const optionalRectsEqual = support.optionalRectsEqual;
|
|
346
|
+
const sizesEqual = support.sizesEqual;
|
|
347
|
+
const insetsEqual = support.insetsEqual;
|
|
348
|
+
const optionalColorsEqual = support.optionalColorsEqual;
|
|
349
|
+
const radiiEqual = support.radiiEqual;
|
|
350
|
+
const affinesEqual = support.affinesEqual;
|
|
351
|
+
const optionalF32Equal = support.optionalF32Equal;
|
|
352
|
+
const optionalTextSelectionsEqual = support.optionalTextSelectionsEqual;
|
|
353
|
+
const optionalTextRangesEqual = support.optionalTextRangesEqual;
|
|
354
|
+
const widgetPartId = support.widgetPartId;
|
|
355
|
+
const colorWithAlpha = support.colorWithAlpha;
|
|
356
|
+
const widgetControlHeight = support.widgetControlHeight;
|
|
357
|
+
const textSelectionFillColor = support.textSelectionFillColor;
|
|
358
|
+
const transparentColor = support.transparentColor;
|
|
359
|
+
const expectRect = support.expectRect;
|
|
360
|
+
const expectRectApprox = support.expectRectApprox;
|
|
361
|
+
const expectPixelRgba8 = support.expectPixelRgba8;
|
|
362
|
+
const expectVisiblePixel = support.expectVisiblePixel;
|
|
363
|
+
const referenceSurfaceSignature = support.referenceSurfaceSignature;
|
|
364
|
+
const expectLayoutFrame = support.expectLayoutFrame;
|
|
365
|
+
const expectRouteEntry = support.expectRouteEntry;
|
|
366
|
+
const expectFillColor = support.expectFillColor;
|
|
367
|
+
const expectGpuPaintColor = support.expectGpuPaintColor;
|
|
368
|
+
|
|
369
|
+
test "widget layout resolves row sizing and emits laid out commands" {
|
|
370
|
+
const row_children = [_]Widget{
|
|
371
|
+
.{
|
|
372
|
+
.id = 2,
|
|
373
|
+
.kind = .button,
|
|
374
|
+
.frame = geometry.RectF.init(0, 0, 80, 32),
|
|
375
|
+
.text = "Run",
|
|
376
|
+
},
|
|
377
|
+
.{
|
|
378
|
+
.id = 3,
|
|
379
|
+
.kind = .progress,
|
|
380
|
+
.frame = geometry.RectF.init(0, 0, 0, 8),
|
|
381
|
+
.value = 0.5,
|
|
382
|
+
.layout = .{ .grow = 1, .min_size = geometry.SizeF.init(40, 8) },
|
|
383
|
+
},
|
|
384
|
+
.{
|
|
385
|
+
.id = 4,
|
|
386
|
+
.kind = .text,
|
|
387
|
+
.frame = geometry.RectF.init(0, 0, 60, 20),
|
|
388
|
+
.text = "Ready",
|
|
389
|
+
},
|
|
390
|
+
};
|
|
391
|
+
const panel_children = [_]Widget{
|
|
392
|
+
.{
|
|
393
|
+
.kind = .row,
|
|
394
|
+
.frame = geometry.RectF.init(0, 0, 0, 40),
|
|
395
|
+
.layout = .{ .gap = 8 },
|
|
396
|
+
.children = &row_children,
|
|
397
|
+
},
|
|
398
|
+
};
|
|
399
|
+
const root = Widget{
|
|
400
|
+
.id = 1,
|
|
401
|
+
.kind = .panel,
|
|
402
|
+
.layout = .{ .padding = geometry.InsetsF.all(12) },
|
|
403
|
+
.children = &panel_children,
|
|
404
|
+
};
|
|
405
|
+
|
|
406
|
+
var nodes: [8]WidgetLayoutNode = undefined;
|
|
407
|
+
const layout = try layoutWidgetTree(root, geometry.RectF.init(0, 0, 300, 80), &nodes);
|
|
408
|
+
try std.testing.expectEqual(@as(usize, 5), layout.nodeCount());
|
|
409
|
+
try expectLayoutFrame(layout, 1, geometry.RectF.init(0, 0, 300, 80));
|
|
410
|
+
try expectLayoutFrame(layout, 2, geometry.RectF.init(12, 12, 80, 32));
|
|
411
|
+
try expectLayoutFrame(layout, 3, geometry.RectF.init(100, 12, 120, 8));
|
|
412
|
+
try expectLayoutFrame(layout, 4, geometry.RectF.init(228, 12, 60, 20));
|
|
413
|
+
|
|
414
|
+
var commands: [12]CanvasCommand = undefined;
|
|
415
|
+
var builder = Builder.init(&commands);
|
|
416
|
+
try layout.emitDisplayList(&builder, .{});
|
|
417
|
+
// Panel chrome (shadow/fill/border), the flat button (fill/border/
|
|
418
|
+
// label), the progress track+value fills, then the text run.
|
|
419
|
+
const display_list = builder.displayList();
|
|
420
|
+
try std.testing.expectEqual(@as(usize, 9), display_list.commandCount());
|
|
421
|
+
switch (display_list.commands[7]) {
|
|
422
|
+
.fill_rounded_rect => |fill| try expectRect(geometry.RectF.init(100, 12, 60, 8), fill.rect),
|
|
423
|
+
else => return error.TestUnexpectedResult,
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
test "chat bubbles cap at the thread fraction, never the full thread" {
|
|
428
|
+
// A hug-sized bubble in a WIDE thread: its message wants 700 points,
|
|
429
|
+
// the row offers 600, and the reference contract caps the bubble at
|
|
430
|
+
// 80% of the thread — 480 — so a long message wraps into a readable
|
|
431
|
+
// column instead of spanning wall to wall.
|
|
432
|
+
const wide_message = [_]Widget{.{ .id = 3, .kind = .text, .frame = geometry.RectF.init(0, 0, 700, 18), .text = "long" }};
|
|
433
|
+
const wide_children = [_]Widget{.{ .id = 2, .kind = .bubble, .children = &wide_message }};
|
|
434
|
+
const wide_row = Widget{ .id = 1, .kind = .row, .children = &wide_children };
|
|
435
|
+
var wide_nodes: [4]WidgetLayoutNode = undefined;
|
|
436
|
+
const wide = try layoutWidgetTree(wide_row, geometry.RectF.init(0, 0, 600, 60), &wide_nodes);
|
|
437
|
+
try std.testing.expectEqual(@as(f32, 480), wide.nodes[1].frame.width);
|
|
438
|
+
|
|
439
|
+
// A NARROW thread: the cap follows the thread down, so the bubble
|
|
440
|
+
// never exceeds what the row can offer (160 = 80% of 200).
|
|
441
|
+
var narrow_nodes: [4]WidgetLayoutNode = undefined;
|
|
442
|
+
const narrow = try layoutWidgetTree(wide_row, geometry.RectF.init(0, 0, 200, 60), &narrow_nodes);
|
|
443
|
+
try std.testing.expectEqual(@as(f32, 160), narrow.nodes[1].frame.width);
|
|
444
|
+
|
|
445
|
+
// Ghost bubbles are exempt (the reference lets the chrome-less
|
|
446
|
+
// variant run full width), and an explicit author width is definite
|
|
447
|
+
// through the frame channel — both keep the classic result.
|
|
448
|
+
const ghost_children = [_]Widget{.{ .id = 2, .kind = .bubble, .variant = .ghost, .children = &wide_message }};
|
|
449
|
+
const ghost_row = Widget{ .id = 1, .kind = .row, .children = &ghost_children };
|
|
450
|
+
var ghost_nodes: [4]WidgetLayoutNode = undefined;
|
|
451
|
+
const ghost = try layoutWidgetTree(ghost_row, geometry.RectF.init(0, 0, 600, 60), &ghost_nodes);
|
|
452
|
+
try std.testing.expectEqual(@as(f32, 700), ghost.nodes[1].frame.width);
|
|
453
|
+
const sized_children = [_]Widget{.{ .id = 2, .kind = .bubble, .frame = geometry.RectF.init(0, 0, 550, 0), .children = &wide_message }};
|
|
454
|
+
const sized_row = Widget{ .id = 1, .kind = .row, .children = &sized_children };
|
|
455
|
+
var sized_nodes: [4]WidgetLayoutNode = undefined;
|
|
456
|
+
const sized = try layoutWidgetTree(sized_row, geometry.RectF.init(0, 0, 600, 60), &sized_nodes);
|
|
457
|
+
try std.testing.expectEqual(@as(f32, 550), sized.nodes[1].frame.width);
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
test "column-direct chat bubbles hug their message up to the fraction" {
|
|
461
|
+
// The bubble is a message-hugging surface even under a column's
|
|
462
|
+
// default stretch alignment: a short message hugs (100 points, at
|
|
463
|
+
// the column's leading edge), a long one caps at 80% of the column
|
|
464
|
+
// (240 of 300) — the reference's fit-content bubble, never a
|
|
465
|
+
// stretched band.
|
|
466
|
+
const short_message = [_]Widget{.{ .id = 3, .kind = .text, .frame = geometry.RectF.init(0, 0, 100, 18), .text = "hi" }};
|
|
467
|
+
const long_message = [_]Widget{.{ .id = 5, .kind = .text, .frame = geometry.RectF.init(0, 0, 700, 18), .text = "long" }};
|
|
468
|
+
const column_children = [_]Widget{
|
|
469
|
+
.{ .id = 2, .kind = .bubble, .children = &short_message },
|
|
470
|
+
.{ .id = 4, .kind = .bubble, .children = &long_message },
|
|
471
|
+
};
|
|
472
|
+
const column = Widget{ .id = 1, .kind = .column, .layout = .{ .gap = 8 }, .children = &column_children };
|
|
473
|
+
var nodes: [8]WidgetLayoutNode = undefined;
|
|
474
|
+
const layout = try layoutWidgetTree(column, geometry.RectF.init(0, 0, 300, 120), &nodes);
|
|
475
|
+
try std.testing.expectEqual(@as(f32, 100), layout.nodes[1].frame.width);
|
|
476
|
+
try std.testing.expectEqual(@as(f32, 0), layout.nodes[1].frame.x);
|
|
477
|
+
try std.testing.expectEqual(@as(f32, 240), layout.nodes[3].frame.width);
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
test "widget layout uses intrinsic sizes for unframed controls" {
|
|
481
|
+
const tokens = DesignTokens{};
|
|
482
|
+
const button = Widget{ .id = 2, .kind = .button, .text = "Run" };
|
|
483
|
+
const search = Widget{ .id = 3, .kind = .search_field, .text = "Find" };
|
|
484
|
+
const icon_button = Widget{ .id = 4, .kind = .icon_button, .text = "+", .size = .icon };
|
|
485
|
+
const row_children = [_]Widget{ button, search, icon_button };
|
|
486
|
+
const row = Widget{
|
|
487
|
+
.id = 1,
|
|
488
|
+
.kind = .row,
|
|
489
|
+
.layout = .{ .gap = 8, .cross_alignment = .center },
|
|
490
|
+
.children = &row_children,
|
|
491
|
+
};
|
|
492
|
+
|
|
493
|
+
var nodes: [4]WidgetLayoutNode = undefined;
|
|
494
|
+
const layout = try layoutWidgetTreeWithTokens(row, geometry.RectF.init(0, 0, 400, 64), tokens, &nodes);
|
|
495
|
+
|
|
496
|
+
const button_size = intrinsicWidgetSize(button, tokens);
|
|
497
|
+
const search_size = intrinsicWidgetSize(search, tokens);
|
|
498
|
+
const icon_size = intrinsicWidgetSize(icon_button, tokens);
|
|
499
|
+
try std.testing.expect(button_size.width > 0);
|
|
500
|
+
try std.testing.expect(search_size.width > button_size.width);
|
|
501
|
+
try expectLayoutFrame(layout, 2, geometry.RectF.init(0, (64 - button_size.height) * 0.5, button_size.width, button_size.height));
|
|
502
|
+
try expectLayoutFrame(layout, 3, geometry.RectF.init(button_size.width + 8, (64 - search_size.height) * 0.5, search_size.width, search_size.height));
|
|
503
|
+
// Accumulate x the way the row layout does — each step adds
|
|
504
|
+
// `width + gap` as ONE term — so the comparison stays bit-exact
|
|
505
|
+
// under f32 association.
|
|
506
|
+
try expectLayoutFrame(layout, 4, geometry.RectF.init((button_size.width + 8) + (search_size.width + 8), (64 - icon_size.height) * 0.5, icon_size.width, icon_size.height));
|
|
507
|
+
|
|
508
|
+
var custom_nodes: [4]WidgetLayoutNode = undefined;
|
|
509
|
+
const custom_tokens = DesignTokens{ .typography = .{ .button_size = 18 } };
|
|
510
|
+
const custom_layout = try layoutWidgetTreeWithTokens(row, geometry.RectF.init(0, 0, 400, 64), custom_tokens, &custom_nodes);
|
|
511
|
+
try std.testing.expect(custom_layout.findById(2).?.frame.width > layout.findById(2).?.frame.width);
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
test "spinner intrinsic size is the compact icon register" {
|
|
515
|
+
// The spinner sizes as an inline activity glyph — 16 (sm) / 20
|
|
516
|
+
// (default) / 24 (lg), density scaled — never the 36px control
|
|
517
|
+
// square that dwarfed neighboring compact controls.
|
|
518
|
+
const tokens = DesignTokens{};
|
|
519
|
+
const sm = Widget{ .id = 2, .kind = .spinner, .size = .sm };
|
|
520
|
+
const default_size = Widget{ .id = 3, .kind = .spinner };
|
|
521
|
+
const lg = Widget{ .id = 4, .kind = .spinner, .size = .lg };
|
|
522
|
+
try std.testing.expectEqualDeep(geometry.SizeF.init(16, 16), intrinsicWidgetSize(sm, tokens));
|
|
523
|
+
try std.testing.expectEqualDeep(geometry.SizeF.init(20, 20), intrinsicWidgetSize(default_size, tokens));
|
|
524
|
+
try std.testing.expectEqualDeep(geometry.SizeF.init(24, 24), intrinsicWidgetSize(lg, tokens));
|
|
525
|
+
|
|
526
|
+
const compact = DesignTokens{ .density = .compact };
|
|
527
|
+
try std.testing.expectEqualDeep(geometry.SizeF.init(16 * 0.875, 16 * 0.875), intrinsicWidgetSize(sm, compact));
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
test "widget layout aligns row children on main and cross axes" {
|
|
531
|
+
const centered_children = [_]Widget{
|
|
532
|
+
.{
|
|
533
|
+
.id = 2,
|
|
534
|
+
.kind = .text,
|
|
535
|
+
.frame = geometry.RectF.init(0, 0, 40, 12),
|
|
536
|
+
.text = "A",
|
|
537
|
+
},
|
|
538
|
+
.{
|
|
539
|
+
.id = 3,
|
|
540
|
+
.kind = .text,
|
|
541
|
+
.frame = geometry.RectF.init(0, 0, 20, 16),
|
|
542
|
+
.text = "B",
|
|
543
|
+
},
|
|
544
|
+
};
|
|
545
|
+
const centered = Widget{
|
|
546
|
+
.id = 1,
|
|
547
|
+
.kind = .row,
|
|
548
|
+
.layout = .{
|
|
549
|
+
.gap = 4,
|
|
550
|
+
.main_alignment = .center,
|
|
551
|
+
.cross_alignment = .center,
|
|
552
|
+
},
|
|
553
|
+
.children = ¢ered_children,
|
|
554
|
+
};
|
|
555
|
+
|
|
556
|
+
var centered_nodes: [3]WidgetLayoutNode = undefined;
|
|
557
|
+
const centered_layout = try layoutWidgetTree(centered, geometry.RectF.init(0, 0, 120, 40), ¢ered_nodes);
|
|
558
|
+
try expectLayoutFrame(centered_layout, 2, geometry.RectF.init(28, 14, 40, 12));
|
|
559
|
+
try expectLayoutFrame(centered_layout, 3, geometry.RectF.init(72, 12, 20, 16));
|
|
560
|
+
|
|
561
|
+
const spaced_children = [_]Widget{
|
|
562
|
+
.{ .id = 5, .kind = .text, .frame = geometry.RectF.init(0, 0, 40, 12), .text = "A" },
|
|
563
|
+
.{ .id = 6, .kind = .text, .frame = geometry.RectF.init(0, 0, 20, 16), .text = "B" },
|
|
564
|
+
};
|
|
565
|
+
const spaced = Widget{
|
|
566
|
+
.id = 4,
|
|
567
|
+
.kind = .row,
|
|
568
|
+
.layout = .{ .main_alignment = .space_between },
|
|
569
|
+
.children = &spaced_children,
|
|
570
|
+
};
|
|
571
|
+
|
|
572
|
+
var spaced_nodes: [3]WidgetLayoutNode = undefined;
|
|
573
|
+
const spaced_layout = try layoutWidgetTree(spaced, geometry.RectF.init(0, 0, 120, 40), &spaced_nodes);
|
|
574
|
+
try expectLayoutFrame(spaced_layout, 5, geometry.RectF.init(0, 0, 40, 12));
|
|
575
|
+
try expectLayoutFrame(spaced_layout, 6, geometry.RectF.init(100, 0, 20, 16));
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
test "cross-centering splits the overflow of a taller-than-band child evenly" {
|
|
579
|
+
// A fixed-height list row whose centered text stack is TALLER than
|
|
580
|
+
// the padded band: the stack keeps its intrinsic height and the
|
|
581
|
+
// overflow splits evenly across both edges (the free extent goes
|
|
582
|
+
// negative and halves), so the content sits optically centered.
|
|
583
|
+
// Before this pin the stack was clamped to the band and its inner
|
|
584
|
+
// flow spilled past the bottom edge only — a visible top gap with
|
|
585
|
+
// the last line pressed against the row's bottom edge.
|
|
586
|
+
// Fixed-size leaves stand in for the text lines so the pinned
|
|
587
|
+
// numbers stay independent of font metrics.
|
|
588
|
+
const stack_children = [_]Widget{
|
|
589
|
+
.{ .id = 3, .kind = .stack, .frame = geometry.RectF.init(0, 0, 80, 18) },
|
|
590
|
+
.{ .id = 4, .kind = .stack, .frame = geometry.RectF.init(0, 0, 80, 16) },
|
|
591
|
+
};
|
|
592
|
+
const row_children = [_]Widget{
|
|
593
|
+
.{ .id = 2, .kind = .column, .layout = .{ .gap = 2 }, .children = &stack_children },
|
|
594
|
+
};
|
|
595
|
+
const row = Widget{
|
|
596
|
+
.id = 1,
|
|
597
|
+
.kind = .list_item,
|
|
598
|
+
.frame = geometry.RectF.init(0, 0, 300, 44),
|
|
599
|
+
.layout = .{ .padding = geometry.InsetsF.all(10), .cross_alignment = .center },
|
|
600
|
+
.children = &row_children,
|
|
601
|
+
};
|
|
602
|
+
|
|
603
|
+
var nodes: [4]WidgetLayoutNode = undefined;
|
|
604
|
+
const layout = try layoutWidgetTree(row, geometry.RectF.init(0, 0, 300, 44), &nodes);
|
|
605
|
+
// Stack intrinsic height 18 + 2 + 16 = 36 against the 24-point band
|
|
606
|
+
// (44 minus 10 padding per edge): the frame keeps 36 and centers at
|
|
607
|
+
// 10 + (24 - 36) / 2 = 4 — six points of overflow on EACH side.
|
|
608
|
+
try expectLayoutFrame(layout, 2, geometry.RectF.init(10, 4, 80, 36));
|
|
609
|
+
// The lines flow inside the centered stack: both sit symmetric
|
|
610
|
+
// around the row's vertical middle (22).
|
|
611
|
+
try expectLayoutFrame(layout, 3, geometry.RectF.init(10, 4, 80, 18));
|
|
612
|
+
try expectLayoutFrame(layout, 4, geometry.RectF.init(10, 24, 80, 16));
|
|
613
|
+
|
|
614
|
+
// A child that FITS the band keeps the classic centering unchanged.
|
|
615
|
+
const fitting_children = [_]Widget{
|
|
616
|
+
.{ .id = 6, .kind = .stack, .frame = geometry.RectF.init(0, 0, 80, 16) },
|
|
617
|
+
};
|
|
618
|
+
const fitting = Widget{
|
|
619
|
+
.id = 5,
|
|
620
|
+
.kind = .list_item,
|
|
621
|
+
.frame = geometry.RectF.init(0, 0, 300, 44),
|
|
622
|
+
.layout = .{ .padding = geometry.InsetsF.all(10), .cross_alignment = .center },
|
|
623
|
+
.children = &fitting_children,
|
|
624
|
+
};
|
|
625
|
+
var fitting_nodes: [3]WidgetLayoutNode = undefined;
|
|
626
|
+
const fitting_layout = try layoutWidgetTree(fitting, geometry.RectF.init(0, 0, 300, 44), &fitting_nodes);
|
|
627
|
+
try expectLayoutFrame(fitting_layout, 6, geometry.RectF.init(10, 14, 80, 16));
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
test "widget text alignment emits local text layout options" {
|
|
631
|
+
const tokens = DesignTokens{
|
|
632
|
+
.typography = .{ .font_id = 1, .body_size = 10 },
|
|
633
|
+
};
|
|
634
|
+
|
|
635
|
+
const centered = Widget{
|
|
636
|
+
.id = 1,
|
|
637
|
+
.kind = .text,
|
|
638
|
+
.frame = geometry.RectF.init(10, 20, 100, 20),
|
|
639
|
+
.text = "Hi",
|
|
640
|
+
.text_alignment = .center,
|
|
641
|
+
};
|
|
642
|
+
var center_commands: [1]CanvasCommand = undefined;
|
|
643
|
+
var center_builder = Builder.init(¢er_commands);
|
|
644
|
+
try emitWidgetTree(¢er_builder, centered, tokens);
|
|
645
|
+
switch (center_builder.displayList().commands[0]) {
|
|
646
|
+
.draw_text => |text| {
|
|
647
|
+
try std.testing.expectEqual(@as(ObjectId, widgetPartId(1, 1)), text.id);
|
|
648
|
+
try std.testing.expectApproxEqAbs(@as(f32, 10), text.origin.x, 0.001);
|
|
649
|
+
try std.testing.expectApproxEqAbs(@as(f32, 33.75), text.origin.y, 0.001);
|
|
650
|
+
try std.testing.expect(text.text_layout != null);
|
|
651
|
+
try std.testing.expectEqual(@as(f32, 100), text.text_layout.?.max_width);
|
|
652
|
+
try std.testing.expectEqual(TextAlign.center, text.text_layout.?.alignment);
|
|
653
|
+
},
|
|
654
|
+
else => return error.TestUnexpectedResult,
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
const end = Widget{
|
|
658
|
+
.id = 2,
|
|
659
|
+
.kind = .text,
|
|
660
|
+
.frame = geometry.RectF.init(10, 20, 100, 20),
|
|
661
|
+
.text = "Hi",
|
|
662
|
+
.text_alignment = .end,
|
|
663
|
+
};
|
|
664
|
+
var end_commands: [1]CanvasCommand = undefined;
|
|
665
|
+
var end_builder = Builder.init(&end_commands);
|
|
666
|
+
try emitWidgetTree(&end_builder, end, tokens);
|
|
667
|
+
switch (end_builder.displayList().commands[0]) {
|
|
668
|
+
.draw_text => |text| {
|
|
669
|
+
try std.testing.expectApproxEqAbs(@as(f32, 10), text.origin.x, 0.001);
|
|
670
|
+
try std.testing.expect(text.text_layout != null);
|
|
671
|
+
try std.testing.expectEqual(TextAlign.end, text.text_layout.?.alignment);
|
|
672
|
+
},
|
|
673
|
+
else => return error.TestUnexpectedResult,
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
test "widget opacity wraps subtree display list commands" {
|
|
678
|
+
const children = [_]Widget{.{
|
|
679
|
+
.id = 2,
|
|
680
|
+
.kind = .text,
|
|
681
|
+
.frame = geometry.RectF.init(8, 10, 80, 20),
|
|
682
|
+
.text = "Fade",
|
|
683
|
+
}};
|
|
684
|
+
const root = Widget{
|
|
685
|
+
.id = 1,
|
|
686
|
+
.kind = .stack,
|
|
687
|
+
.opacity = 0.5,
|
|
688
|
+
.children = &children,
|
|
689
|
+
};
|
|
690
|
+
|
|
691
|
+
var direct_commands: [3]CanvasCommand = undefined;
|
|
692
|
+
var direct_builder = Builder.init(&direct_commands);
|
|
693
|
+
try emitWidgetTree(&direct_builder, root, .{});
|
|
694
|
+
const direct_display_list = direct_builder.displayList();
|
|
695
|
+
try std.testing.expectEqual(@as(usize, 3), direct_display_list.commandCount());
|
|
696
|
+
switch (direct_display_list.commands[0]) {
|
|
697
|
+
.push_opacity => |opacity| try std.testing.expectEqual(@as(f32, 0.5), opacity),
|
|
698
|
+
else => return error.TestUnexpectedResult,
|
|
699
|
+
}
|
|
700
|
+
switch (direct_display_list.commands[1]) {
|
|
701
|
+
.draw_text => |text| try std.testing.expectEqualStrings("Fade", text.text),
|
|
702
|
+
else => return error.TestUnexpectedResult,
|
|
703
|
+
}
|
|
704
|
+
try std.testing.expect(direct_display_list.commands[2] == .pop_opacity);
|
|
705
|
+
|
|
706
|
+
var render_commands: [1]RenderCommand = undefined;
|
|
707
|
+
const render_plan = try direct_display_list.renderPlan(&render_commands);
|
|
708
|
+
try std.testing.expectEqual(@as(usize, 1), render_plan.commandCount());
|
|
709
|
+
try std.testing.expectEqual(@as(f32, 0.5), render_plan.commands[0].opacity);
|
|
710
|
+
|
|
711
|
+
var nodes: [2]WidgetLayoutNode = undefined;
|
|
712
|
+
const layout = try layoutWidgetTree(root, geometry.RectF.init(0, 0, 100, 40), &nodes);
|
|
713
|
+
var layout_commands: [3]CanvasCommand = undefined;
|
|
714
|
+
var layout_builder = Builder.init(&layout_commands);
|
|
715
|
+
try layout.emitDisplayList(&layout_builder, .{});
|
|
716
|
+
const layout_display_list = layout_builder.displayList();
|
|
717
|
+
try std.testing.expectEqual(@as(usize, 3), layout_display_list.commandCount());
|
|
718
|
+
switch (layout_display_list.commands[0]) {
|
|
719
|
+
.push_opacity => |opacity| try std.testing.expectEqual(@as(f32, 0.5), opacity),
|
|
720
|
+
else => return error.TestUnexpectedResult,
|
|
721
|
+
}
|
|
722
|
+
try std.testing.expect(layout_display_list.commands[2] == .pop_opacity);
|
|
723
|
+
|
|
724
|
+
var transparent_commands: [1]CanvasCommand = undefined;
|
|
725
|
+
var transparent_builder = Builder.init(&transparent_commands);
|
|
726
|
+
try emitWidgetTree(&transparent_builder, .{ .kind = .stack, .opacity = 0, .children = &children }, .{});
|
|
727
|
+
try std.testing.expectEqual(@as(usize, 0), transparent_builder.displayList().commandCount());
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
test "widget transform wraps subtree display list commands" {
|
|
731
|
+
const children = [_]Widget{
|
|
732
|
+
.{
|
|
733
|
+
.id = 2,
|
|
734
|
+
.kind = .text,
|
|
735
|
+
.frame = geometry.RectF.init(0, 0, 40, 20),
|
|
736
|
+
.transform = Affine.translate(20, 0),
|
|
737
|
+
.text = "Move",
|
|
738
|
+
},
|
|
739
|
+
.{
|
|
740
|
+
.id = 3,
|
|
741
|
+
.kind = .text,
|
|
742
|
+
.frame = geometry.RectF.init(0, 24, 40, 20),
|
|
743
|
+
.text = "Still",
|
|
744
|
+
},
|
|
745
|
+
};
|
|
746
|
+
const root = Widget{ .kind = .stack, .children = &children };
|
|
747
|
+
|
|
748
|
+
var commands: [4]CanvasCommand = undefined;
|
|
749
|
+
var builder = Builder.init(&commands);
|
|
750
|
+
try emitWidgetTree(&builder, root, .{});
|
|
751
|
+
const display_list = builder.displayList();
|
|
752
|
+
try std.testing.expectEqual(@as(usize, 4), display_list.commandCount());
|
|
753
|
+
switch (display_list.commands[0]) {
|
|
754
|
+
.transform => |transform| try std.testing.expectEqualDeep(Affine.translate(20, 0), transform),
|
|
755
|
+
else => return error.TestUnexpectedResult,
|
|
756
|
+
}
|
|
757
|
+
switch (display_list.commands[1]) {
|
|
758
|
+
.draw_text => |text| try std.testing.expectEqualStrings("Move", text.text),
|
|
759
|
+
else => return error.TestUnexpectedResult,
|
|
760
|
+
}
|
|
761
|
+
switch (display_list.commands[2]) {
|
|
762
|
+
.transform => |transform| try std.testing.expectEqualDeep(Affine.translate(-20, 0), transform),
|
|
763
|
+
else => return error.TestUnexpectedResult,
|
|
764
|
+
}
|
|
765
|
+
switch (display_list.commands[3]) {
|
|
766
|
+
.draw_text => |text| try std.testing.expectEqualStrings("Still", text.text),
|
|
767
|
+
else => return error.TestUnexpectedResult,
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
var render_commands: [2]RenderCommand = undefined;
|
|
771
|
+
const render_plan = try display_list.renderPlan(&render_commands);
|
|
772
|
+
try std.testing.expectEqual(@as(usize, 2), render_plan.commandCount());
|
|
773
|
+
try std.testing.expectEqualDeep(Affine.translate(20, 0), render_plan.commands[0].transform);
|
|
774
|
+
try std.testing.expectEqualDeep(Affine.identity(), render_plan.commands[1].transform);
|
|
775
|
+
|
|
776
|
+
var invalid_commands: [1]CanvasCommand = undefined;
|
|
777
|
+
var invalid_builder = Builder.init(&invalid_commands);
|
|
778
|
+
try std.testing.expectError(error.InvalidTransform, emitWidgetTree(&invalid_builder, .{
|
|
779
|
+
.kind = .text,
|
|
780
|
+
.transform = Affine.scale(0, 1),
|
|
781
|
+
.text = "Bad",
|
|
782
|
+
}, .{}));
|
|
783
|
+
try std.testing.expectEqual(@as(usize, 0), invalid_builder.displayList().commandCount());
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
test "widget transform affects hit testing" {
|
|
787
|
+
const button = Widget{
|
|
788
|
+
.id = 4,
|
|
789
|
+
.kind = .button,
|
|
790
|
+
.frame = geometry.RectF.init(0, 0, 32, 24),
|
|
791
|
+
.transform = Affine.translate(40, 0),
|
|
792
|
+
.text = "Go",
|
|
793
|
+
};
|
|
794
|
+
|
|
795
|
+
var nodes: [1]WidgetLayoutNode = undefined;
|
|
796
|
+
const layout = try layoutWidgetTree(button, button.frame, &nodes);
|
|
797
|
+
try std.testing.expect(layout.hitTest(geometry.PointF.init(8, 12)) == null);
|
|
798
|
+
const hit = layout.hitTest(geometry.PointF.init(48, 12)).?;
|
|
799
|
+
try std.testing.expectEqual(@as(ObjectId, 4), hit.id);
|
|
800
|
+
try std.testing.expectEqual(WidgetKind.button, hit.kind);
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
test "widget clip content wraps subtree display list and hit testing" {
|
|
804
|
+
const children = [_]Widget{.{
|
|
805
|
+
.id = 2,
|
|
806
|
+
.kind = .text,
|
|
807
|
+
.frame = geometry.RectF.init(40, 0, 40, 20),
|
|
808
|
+
.text = "Clip",
|
|
809
|
+
.semantics = .{ .focusable = true },
|
|
810
|
+
}};
|
|
811
|
+
const root = Widget{
|
|
812
|
+
.id = 1,
|
|
813
|
+
.kind = .stack,
|
|
814
|
+
.frame = geometry.RectF.init(0, 0, 50, 20),
|
|
815
|
+
.layout = .{ .clip_content = true },
|
|
816
|
+
.children = &children,
|
|
817
|
+
};
|
|
818
|
+
|
|
819
|
+
var direct_commands: [3]CanvasCommand = undefined;
|
|
820
|
+
var direct_builder = Builder.init(&direct_commands);
|
|
821
|
+
try emitWidgetTree(&direct_builder, root, .{});
|
|
822
|
+
const direct_display_list = direct_builder.displayList();
|
|
823
|
+
try std.testing.expectEqual(@as(usize, 3), direct_display_list.commandCount());
|
|
824
|
+
switch (direct_display_list.commands[0]) {
|
|
825
|
+
.push_clip => |clip| try expectRect(geometry.RectF.init(0, 0, 50, 20), clip.rect),
|
|
826
|
+
else => return error.TestUnexpectedResult,
|
|
827
|
+
}
|
|
828
|
+
switch (direct_display_list.commands[1]) {
|
|
829
|
+
.draw_text => |text| try std.testing.expectEqualStrings("Clip", text.text),
|
|
830
|
+
else => return error.TestUnexpectedResult,
|
|
831
|
+
}
|
|
832
|
+
try std.testing.expect(direct_display_list.commands[2] == .pop_clip);
|
|
833
|
+
|
|
834
|
+
var nodes: [2]WidgetLayoutNode = undefined;
|
|
835
|
+
const layout = try layoutWidgetTree(root, root.frame, &nodes);
|
|
836
|
+
var layout_commands: [3]CanvasCommand = undefined;
|
|
837
|
+
var layout_builder = Builder.init(&layout_commands);
|
|
838
|
+
try layout.emitDisplayList(&layout_builder, .{});
|
|
839
|
+
const layout_display_list = layout_builder.displayList();
|
|
840
|
+
try std.testing.expectEqual(@as(usize, 3), layout_display_list.commandCount());
|
|
841
|
+
try std.testing.expect(layout_display_list.commands[0] == .push_clip);
|
|
842
|
+
try std.testing.expect(layout_display_list.commands[2] == .pop_clip);
|
|
843
|
+
|
|
844
|
+
try std.testing.expectEqual(@as(ObjectId, 2), layout.hitTest(geometry.PointF.init(45, 10)).?.id);
|
|
845
|
+
try std.testing.expect(layout.hitTest(geometry.PointF.init(55, 10)) == null);
|
|
846
|
+
try std.testing.expectEqual(@as(ObjectId, 2), layout.focusTarget(null, .forward).?.id);
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
test "widget layout hit testing prefers deepest topmost enabled target" {
|
|
850
|
+
const children = [_]Widget{
|
|
851
|
+
.{
|
|
852
|
+
.id = 2,
|
|
853
|
+
.kind = .button,
|
|
854
|
+
.frame = geometry.RectF.init(8, 8, 90, 32),
|
|
855
|
+
.text = "Disabled",
|
|
856
|
+
.state = .{ .disabled = true },
|
|
857
|
+
},
|
|
858
|
+
.{
|
|
859
|
+
.id = 3,
|
|
860
|
+
.kind = .button,
|
|
861
|
+
.frame = geometry.RectF.init(16, 16, 90, 32),
|
|
862
|
+
.text = "Active",
|
|
863
|
+
},
|
|
864
|
+
};
|
|
865
|
+
const root = Widget{
|
|
866
|
+
.id = 1,
|
|
867
|
+
.kind = .panel,
|
|
868
|
+
.children = &children,
|
|
869
|
+
};
|
|
870
|
+
|
|
871
|
+
var nodes: [4]WidgetLayoutNode = undefined;
|
|
872
|
+
const layout = try layoutWidgetTree(root, geometry.RectF.init(0, 0, 140, 80), &nodes);
|
|
873
|
+
const active_hit = layout.hitTest(geometry.PointF.init(24, 24)).?;
|
|
874
|
+
try std.testing.expectEqual(@as(ObjectId, 3), active_hit.id);
|
|
875
|
+
try std.testing.expectEqual(WidgetKind.button, active_hit.kind);
|
|
876
|
+
|
|
877
|
+
const panel_hit = layout.hitTest(geometry.PointF.init(10, 10)).?;
|
|
878
|
+
try std.testing.expectEqual(@as(ObjectId, 1), panel_hit.id);
|
|
879
|
+
try std.testing.expect(layout.hitTest(geometry.PointF.init(200, 10)) == null);
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
test "widget layout resolves cursor intent from hit targets" {
|
|
883
|
+
const children = [_]Widget{
|
|
884
|
+
.{ .id = 2, .kind = .button, .frame = geometry.RectF.init(8, 8, 90, 32), .text = "Run" },
|
|
885
|
+
.{ .id = 3, .kind = .text_field, .frame = geometry.RectF.init(8, 48, 120, 32), .text = "Query" },
|
|
886
|
+
.{ .id = 4, .kind = .slider, .frame = geometry.RectF.init(8, 88, 120, 32), .value = 0.5 },
|
|
887
|
+
.{ .id = 5, .kind = .resizable, .frame = geometry.RectF.init(8, 128, 120, 40) },
|
|
888
|
+
};
|
|
889
|
+
const root = Widget{
|
|
890
|
+
.id = 1,
|
|
891
|
+
.kind = .panel,
|
|
892
|
+
.children = &children,
|
|
893
|
+
};
|
|
894
|
+
|
|
895
|
+
var nodes: [6]WidgetLayoutNode = undefined;
|
|
896
|
+
const layout = try layoutWidgetTree(root, geometry.RectF.init(0, 0, 160, 180), &nodes);
|
|
897
|
+
// The native register: buttons AND sliders show the arrow (the hand
|
|
898
|
+
// is reserved for hyperlinks), editable text shows the I-beam, and
|
|
899
|
+
// only resize affordances show resize arrows.
|
|
900
|
+
try std.testing.expectEqual(WidgetCursor.arrow, layout.cursorForHit(layout.hitTest(geometry.PointF.init(16, 16))));
|
|
901
|
+
try std.testing.expectEqual(WidgetCursor.text, layout.cursorForHit(layout.hitTest(geometry.PointF.init(16, 56))));
|
|
902
|
+
try std.testing.expectEqual(WidgetCursor.arrow, layout.cursorForHit(layout.hitTest(geometry.PointF.init(16, 96))));
|
|
903
|
+
try std.testing.expectEqual(WidgetCursor.resize_horizontal, layout.cursorForHit(layout.hitTest(geometry.PointF.init(120, 140))));
|
|
904
|
+
try std.testing.expectEqual(WidgetCursor.arrow, layout.cursorForHit(layout.hitTest(geometry.PointF.init(150, 170))));
|
|
905
|
+
try std.testing.expectEqual(WidgetCursor.arrow, cursorForWidgetTarget(.button, .{ .disabled = true }));
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
test "widget grid layout places children in deterministic cells" {
|
|
909
|
+
const children = [_]Widget{
|
|
910
|
+
.{ .id = 2, .kind = .text, .text = "One" },
|
|
911
|
+
.{ .id = 3, .kind = .text, .text = "Two" },
|
|
912
|
+
.{ .id = 4, .kind = .button, .text = "Three" },
|
|
913
|
+
.{ .id = 5, .kind = .button, .text = "Four" },
|
|
914
|
+
};
|
|
915
|
+
const grid = Widget{
|
|
916
|
+
.id = 1,
|
|
917
|
+
.kind = .grid,
|
|
918
|
+
.layout = .{ .gap = 8, .columns = 2 },
|
|
919
|
+
.children = &children,
|
|
920
|
+
};
|
|
921
|
+
|
|
922
|
+
var nodes: [6]WidgetLayoutNode = undefined;
|
|
923
|
+
const layout = try layoutWidgetTree(grid, geometry.RectF.init(0, 0, 208, 88), &nodes);
|
|
924
|
+
try std.testing.expectEqual(@as(usize, 5), layout.nodeCount());
|
|
925
|
+
try expectLayoutFrame(layout, 2, geometry.RectF.init(0, 0, 100, 40));
|
|
926
|
+
try expectLayoutFrame(layout, 3, geometry.RectF.init(108, 0, 100, 40));
|
|
927
|
+
try expectLayoutFrame(layout, 4, geometry.RectF.init(0, 48, 100, 40));
|
|
928
|
+
try expectLayoutFrame(layout, 5, geometry.RectF.init(108, 48, 100, 40));
|
|
929
|
+
|
|
930
|
+
var commands: [10]CanvasCommand = undefined;
|
|
931
|
+
var builder = Builder.init(&commands);
|
|
932
|
+
try layout.emitDisplayList(&builder, .{});
|
|
933
|
+
// Each flat button contributes 3 commands (fill/border/label); the
|
|
934
|
+
// two text cells stay at 1.
|
|
935
|
+
try std.testing.expectEqual(@as(usize, 8), builder.displayList().commandCount());
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
test "widget virtualized grid lays out visible cells by row" {
|
|
939
|
+
const children = [_]Widget{
|
|
940
|
+
.{ .id = 2, .kind = .button, .text = "Zero" },
|
|
941
|
+
.{ .id = 3, .kind = .button, .text = "One" },
|
|
942
|
+
.{ .id = 4, .kind = .button, .text = "Two" },
|
|
943
|
+
.{ .id = 5, .kind = .button, .text = "Three" },
|
|
944
|
+
.{ .id = 6, .kind = .button, .text = "Four" },
|
|
945
|
+
.{ .id = 7, .kind = .button, .text = "Five" },
|
|
946
|
+
.{ .id = 8, .kind = .button, .text = "Six" },
|
|
947
|
+
.{ .id = 9, .kind = .button, .text = "Seven" },
|
|
948
|
+
};
|
|
949
|
+
const grid = Widget{
|
|
950
|
+
.id = 1,
|
|
951
|
+
.kind = .grid,
|
|
952
|
+
.value = 25,
|
|
953
|
+
.semantics = .{ .role = .grid, .label = "Tile grid" },
|
|
954
|
+
.layout = .{
|
|
955
|
+
.gap = 5,
|
|
956
|
+
.columns = 2,
|
|
957
|
+
.virtualized = true,
|
|
958
|
+
.virtual_item_extent = 20,
|
|
959
|
+
},
|
|
960
|
+
.children = &children,
|
|
961
|
+
};
|
|
962
|
+
|
|
963
|
+
var nodes: [6]WidgetLayoutNode = undefined;
|
|
964
|
+
const layout = try layoutWidgetTree(grid, geometry.RectF.init(0, 0, 105, 45), &nodes);
|
|
965
|
+
try std.testing.expectEqual(@as(usize, 5), layout.nodeCount());
|
|
966
|
+
try std.testing.expectEqual(@as(?u32, 4), layout.nodes[0].widget.semantics.list_item_count);
|
|
967
|
+
try std.testing.expectEqual(@as(f32, 20), layout.nodes[0].widget.layout.virtual_item_extent);
|
|
968
|
+
const grid_range = layout.virtualRangeById(1).?;
|
|
969
|
+
try std.testing.expectEqual(@as(usize, 1), grid_range.start_index);
|
|
970
|
+
try std.testing.expectEqual(@as(usize, 3), grid_range.end_index);
|
|
971
|
+
try std.testing.expectEqual(@as(usize, 1), grid_range.first_visible_index);
|
|
972
|
+
try std.testing.expectEqual(@as(usize, 2), grid_range.last_visible_index);
|
|
973
|
+
try expectLayoutFrame(layout, 1, geometry.RectF.init(0, 0, 105, 45));
|
|
974
|
+
try expectLayoutFrame(layout, 4, geometry.RectF.init(0, 0, 50, 20));
|
|
975
|
+
try expectLayoutFrame(layout, 5, geometry.RectF.init(55, 0, 50, 20));
|
|
976
|
+
try expectLayoutFrame(layout, 6, geometry.RectF.init(0, 25, 50, 20));
|
|
977
|
+
try expectLayoutFrame(layout, 7, geometry.RectF.init(55, 25, 50, 20));
|
|
978
|
+
try std.testing.expect(layout.findById(2) == null);
|
|
979
|
+
try std.testing.expect(layout.findById(3) == null);
|
|
980
|
+
try std.testing.expect(layout.findById(8) == null);
|
|
981
|
+
try std.testing.expect(layout.findById(9) == null);
|
|
982
|
+
try std.testing.expectEqual(@as(?u32, 2), layout.findById(4).?.widget.semantics.list_item_index);
|
|
983
|
+
try std.testing.expectEqual(@as(?u32, 8), layout.findById(4).?.widget.semantics.list_item_count);
|
|
984
|
+
try std.testing.expectEqual(@as(?u32, 5), layout.findById(7).?.widget.semantics.list_item_index);
|
|
985
|
+
|
|
986
|
+
var semantics_buffer: [6]WidgetSemanticsNode = undefined;
|
|
987
|
+
const semantics = try layout.collectSemantics(&semantics_buffer);
|
|
988
|
+
try std.testing.expectEqual(@as(usize, 5), semantics.len);
|
|
989
|
+
try std.testing.expectEqual(WidgetRole.grid, semantics[0].role);
|
|
990
|
+
try std.testing.expectEqualStrings("Tile grid", semantics[0].label);
|
|
991
|
+
try std.testing.expectEqual(@as(?usize, 4), semantics[0].grid_row_count);
|
|
992
|
+
try std.testing.expectEqual(@as(?usize, 2), semantics[0].grid_column_count);
|
|
993
|
+
try std.testing.expect(semantics[0].scroll.present);
|
|
994
|
+
try std.testing.expectEqual(@as(f32, 25), semantics[0].scroll.offset);
|
|
995
|
+
try std.testing.expectEqual(@as(f32, 45), semantics[0].scroll.viewport_extent);
|
|
996
|
+
try std.testing.expectEqual(@as(f32, 95), semantics[0].scroll.content_extent);
|
|
997
|
+
try std.testing.expect(semantics[0].focusable);
|
|
998
|
+
try std.testing.expect(semantics[0].actions.focus);
|
|
999
|
+
try std.testing.expect(semantics[0].actions.increment);
|
|
1000
|
+
try std.testing.expect(semantics[0].actions.decrement);
|
|
1001
|
+
try std.testing.expectEqual(@as(f32, 95), virtualWidgetScrollContentExtent(grid, 45));
|
|
1002
|
+
try std.testing.expectEqual(WidgetRole.button, semantics[1].role);
|
|
1003
|
+
try std.testing.expectEqual(@as(?usize, 1), semantics[1].grid_row_index);
|
|
1004
|
+
try std.testing.expectEqual(@as(?usize, 0), semantics[1].grid_column_index);
|
|
1005
|
+
try std.testing.expectEqual(@as(?usize, 4), semantics[1].grid_row_count);
|
|
1006
|
+
try std.testing.expectEqual(@as(?usize, 2), semantics[1].grid_column_count);
|
|
1007
|
+
try std.testing.expectEqual(WidgetRole.button, semantics[2].role);
|
|
1008
|
+
try std.testing.expectEqual(@as(?usize, 1), semantics[2].grid_row_index);
|
|
1009
|
+
try std.testing.expectEqual(@as(?usize, 1), semantics[2].grid_column_index);
|
|
1010
|
+
try std.testing.expectEqual(WidgetRole.button, semantics[3].role);
|
|
1011
|
+
try std.testing.expectEqual(@as(?usize, 2), semantics[3].grid_row_index);
|
|
1012
|
+
try std.testing.expectEqual(@as(?usize, 0), semantics[3].grid_column_index);
|
|
1013
|
+
try std.testing.expectEqual(WidgetRole.button, semantics[4].role);
|
|
1014
|
+
try std.testing.expectEqual(@as(?usize, 2), semantics[4].grid_row_index);
|
|
1015
|
+
try std.testing.expectEqual(@as(?usize, 1), semantics[4].grid_column_index);
|
|
1016
|
+
|
|
1017
|
+
const laid_out_grid = layout.findById(1).?.widget;
|
|
1018
|
+
const page_down = WidgetKeyboardEvent{ .phase = .key_down, .key = "pagedown" };
|
|
1019
|
+
const keyboard_intent = widgetKeyboardControlIntent(laid_out_grid, page_down).?;
|
|
1020
|
+
try std.testing.expectEqual(WidgetControlIntentKind.scroll_by, keyboard_intent.kind);
|
|
1021
|
+
try std.testing.expect(keyboard_intent.actions.increment);
|
|
1022
|
+
const semantic_intent = widgetSemanticControlIntentWithActions(laid_out_grid, .increment, .{ .increment = true }).?;
|
|
1023
|
+
try std.testing.expectEqual(WidgetControlIntentKind.scroll_by, semantic_intent.kind);
|
|
1024
|
+
try std.testing.expect(semantic_intent.actions.increment);
|
|
1025
|
+
|
|
1026
|
+
var commands: [32]CanvasCommand = undefined;
|
|
1027
|
+
var builder = Builder.init(&commands);
|
|
1028
|
+
try layout.emitDisplayList(&builder, .{});
|
|
1029
|
+
const display_list = builder.displayList();
|
|
1030
|
+
switch (display_list.findCommandById(widgetPartId(1, 1)).?.command) {
|
|
1031
|
+
.push_clip => |clip| try expectRect(geometry.RectF.init(0, 0, 105, 45), clip.rect),
|
|
1032
|
+
else => return error.TestUnexpectedResult,
|
|
1033
|
+
}
|
|
1034
|
+
switch (display_list.findCommandById(widgetPartId(1, 2)).?.command) {
|
|
1035
|
+
.fill_rounded_rect => |track| try expectRect(geometry.RectF.init(99, 3, 3, 39), track.rect),
|
|
1036
|
+
else => return error.TestUnexpectedResult,
|
|
1037
|
+
}
|
|
1038
|
+
switch (display_list.findCommandById(widgetPartId(1, 3)).?.command) {
|
|
1039
|
+
.fill_rounded_rect => |thumb| {
|
|
1040
|
+
try std.testing.expectApproxEqAbs(@as(f32, 13.263), thumb.rect.y, 0.001);
|
|
1041
|
+
try std.testing.expectApproxEqAbs(@as(f32, 18.474), thumb.rect.height, 0.001);
|
|
1042
|
+
},
|
|
1043
|
+
else => return error.TestUnexpectedResult,
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
test "widget data grid exposes rows cells semantics and display list" {
|
|
1048
|
+
const header_cells = [_]Widget{
|
|
1049
|
+
.{ .id = 3, .kind = .data_cell, .text = "Name", .layout = .{ .grow = 1 } },
|
|
1050
|
+
.{ .id = 4, .kind = .data_cell, .text = "Status", .layout = .{ .grow = 1 } },
|
|
1051
|
+
};
|
|
1052
|
+
const deployment_cells = [_]Widget{
|
|
1053
|
+
.{ .id = 6, .kind = .data_cell, .text = "Edge API", .command = "cell.open", .layout = .{ .grow = 1 } },
|
|
1054
|
+
.{ .id = 7, .kind = .data_cell, .text = "Live", .layout = .{ .grow = 1 } },
|
|
1055
|
+
};
|
|
1056
|
+
const rows = [_]Widget{
|
|
1057
|
+
.{ .id = 2, .kind = .data_row, .frame = geometry.RectF.init(0, 0, 0, 28), .children = &header_cells },
|
|
1058
|
+
.{ .id = 5, .kind = .data_row, .frame = geometry.RectF.init(0, 0, 0, 28), .children = &deployment_cells },
|
|
1059
|
+
};
|
|
1060
|
+
const grid = Widget{
|
|
1061
|
+
.id = 1,
|
|
1062
|
+
.kind = .data_grid,
|
|
1063
|
+
.text = "Deployments",
|
|
1064
|
+
.layout = .{ .gap = 2 },
|
|
1065
|
+
.children = &rows,
|
|
1066
|
+
};
|
|
1067
|
+
|
|
1068
|
+
var nodes: [8]WidgetLayoutNode = undefined;
|
|
1069
|
+
const layout = try layoutWidgetTree(grid, geometry.RectF.init(0, 0, 240, 58), &nodes);
|
|
1070
|
+
try std.testing.expectEqual(@as(usize, 7), layout.nodeCount());
|
|
1071
|
+
try expectLayoutFrame(layout, 1, geometry.RectF.init(0, 0, 240, 58));
|
|
1072
|
+
try expectLayoutFrame(layout, 2, geometry.RectF.init(0, 0, 240, 28));
|
|
1073
|
+
try expectLayoutFrame(layout, 3, geometry.RectF.init(0, 0, 120, 28));
|
|
1074
|
+
try expectLayoutFrame(layout, 4, geometry.RectF.init(120, 0, 120, 28));
|
|
1075
|
+
try expectLayoutFrame(layout, 5, geometry.RectF.init(0, 30, 240, 28));
|
|
1076
|
+
try expectLayoutFrame(layout, 6, geometry.RectF.init(0, 30, 120, 28));
|
|
1077
|
+
try expectLayoutFrame(layout, 7, geometry.RectF.init(120, 30, 120, 28));
|
|
1078
|
+
|
|
1079
|
+
const hit = layout.hitTest(geometry.PointF.init(8, 38)).?;
|
|
1080
|
+
try std.testing.expectEqual(@as(ObjectId, 6), hit.id);
|
|
1081
|
+
try std.testing.expectEqual(WidgetKind.data_cell, hit.kind);
|
|
1082
|
+
|
|
1083
|
+
var semantics_buffer: [8]WidgetSemanticsNode = undefined;
|
|
1084
|
+
const semantics = try layout.collectSemantics(&semantics_buffer);
|
|
1085
|
+
try std.testing.expectEqual(@as(usize, 7), semantics.len);
|
|
1086
|
+
try std.testing.expectEqual(WidgetRole.grid, semantics[0].role);
|
|
1087
|
+
try std.testing.expectEqualStrings("Deployments", semantics[0].label);
|
|
1088
|
+
try std.testing.expect(semantics[0].parent_index == null);
|
|
1089
|
+
try std.testing.expectEqual(WidgetRole.row, semantics[1].role);
|
|
1090
|
+
try std.testing.expectEqual(@as(?usize, 0), semantics[1].parent_index);
|
|
1091
|
+
try std.testing.expectEqual(WidgetRole.gridcell, semantics[2].role);
|
|
1092
|
+
try std.testing.expectEqualStrings("Name", semantics[2].label);
|
|
1093
|
+
try std.testing.expectEqual(@as(?usize, 1), semantics[2].parent_index);
|
|
1094
|
+
try std.testing.expect(semantics[2].focusable);
|
|
1095
|
+
try std.testing.expect(semantics[2].actions.focus);
|
|
1096
|
+
try std.testing.expect(semantics[2].actions.select);
|
|
1097
|
+
try std.testing.expect(!semantics[2].actions.press);
|
|
1098
|
+
try std.testing.expectEqual(WidgetRole.row, semantics[4].role);
|
|
1099
|
+
try std.testing.expectEqual(@as(?usize, 0), semantics[4].parent_index);
|
|
1100
|
+
try std.testing.expectEqual(WidgetRole.gridcell, semantics[5].role);
|
|
1101
|
+
try std.testing.expectEqualStrings("Edge API", semantics[5].label);
|
|
1102
|
+
try std.testing.expect(semantics[5].actions.select);
|
|
1103
|
+
try std.testing.expect(semantics[5].actions.press);
|
|
1104
|
+
try expectRect(geometry.RectF.init(0, 30, 120, 28), semantics[5].bounds);
|
|
1105
|
+
|
|
1106
|
+
var commands: [16]CanvasCommand = undefined;
|
|
1107
|
+
var builder = Builder.init(&commands);
|
|
1108
|
+
try layout.emitDisplayList(&builder, .{});
|
|
1109
|
+
const display_list = builder.displayList();
|
|
1110
|
+
// Borderless cells (text only) plus ONE hairline row separator under
|
|
1111
|
+
// the first row — the table register: no cell boxes, no line under
|
|
1112
|
+
// the last row.
|
|
1113
|
+
try std.testing.expectEqual(@as(usize, 5), display_list.commandCount());
|
|
1114
|
+
switch (display_list.commands[0]) {
|
|
1115
|
+
.draw_text => |text| try std.testing.expectEqualStrings("Name", text.text),
|
|
1116
|
+
else => return error.UnexpectedCommand,
|
|
1117
|
+
}
|
|
1118
|
+
switch (display_list.commands[4]) {
|
|
1119
|
+
.draw_line => |line| try std.testing.expectEqual(@as(ObjectId, widgetPartId(2, 2)), line.id),
|
|
1120
|
+
else => return error.UnexpectedCommand,
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
1123
|
+
|
|
1124
|
+
test "widget virtualized data grid lays out visible rows" {
|
|
1125
|
+
const rows = [_]Widget{
|
|
1126
|
+
.{ .id = 2, .kind = .data_row, .frame = geometry.RectF.init(0, 0, 0, 20), .text = "Zero" },
|
|
1127
|
+
.{ .id = 3, .kind = .data_row, .frame = geometry.RectF.init(0, 0, 0, 20), .text = "One" },
|
|
1128
|
+
.{ .id = 4, .kind = .data_row, .frame = geometry.RectF.init(0, 0, 0, 20), .text = "Two" },
|
|
1129
|
+
.{ .id = 5, .kind = .data_row, .frame = geometry.RectF.init(0, 0, 0, 20), .text = "Three" },
|
|
1130
|
+
};
|
|
1131
|
+
const grid = Widget{
|
|
1132
|
+
.id = 1,
|
|
1133
|
+
.kind = .data_grid,
|
|
1134
|
+
.value = 25,
|
|
1135
|
+
.layout = .{
|
|
1136
|
+
.gap = 5,
|
|
1137
|
+
.virtualized = true,
|
|
1138
|
+
.virtual_item_extent = 20,
|
|
1139
|
+
},
|
|
1140
|
+
.children = &rows,
|
|
1141
|
+
};
|
|
1142
|
+
|
|
1143
|
+
var nodes: [4]WidgetLayoutNode = undefined;
|
|
1144
|
+
const layout = try layoutWidgetTree(grid, geometry.RectF.init(0, 0, 160, 45), &nodes);
|
|
1145
|
+
try std.testing.expectEqual(@as(usize, 3), layout.nodeCount());
|
|
1146
|
+
try std.testing.expectEqual(@as(?u32, 4), layout.nodes[0].widget.semantics.list_item_count);
|
|
1147
|
+
try std.testing.expectEqual(@as(f32, 20), layout.nodes[0].widget.layout.virtual_item_extent);
|
|
1148
|
+
const grid_range = layout.virtualRangeById(1).?;
|
|
1149
|
+
try std.testing.expectEqual(@as(usize, 1), grid_range.start_index);
|
|
1150
|
+
try std.testing.expectEqual(@as(usize, 3), grid_range.end_index);
|
|
1151
|
+
try std.testing.expectEqual(@as(usize, 1), grid_range.first_visible_index);
|
|
1152
|
+
try std.testing.expectEqual(@as(usize, 2), grid_range.last_visible_index);
|
|
1153
|
+
try std.testing.expectEqual(@as(?u32, 1), layout.nodes[1].widget.semantics.list_item_index);
|
|
1154
|
+
try std.testing.expectEqual(@as(?u32, 2), layout.nodes[2].widget.semantics.list_item_index);
|
|
1155
|
+
try expectLayoutFrame(layout, 1, geometry.RectF.init(0, 0, 160, 45));
|
|
1156
|
+
try expectLayoutFrame(layout, 3, geometry.RectF.init(0, 0, 160, 20));
|
|
1157
|
+
try expectLayoutFrame(layout, 4, geometry.RectF.init(0, 25, 160, 20));
|
|
1158
|
+
try std.testing.expect(layout.findById(2) == null);
|
|
1159
|
+
try std.testing.expect(layout.findById(5) == null);
|
|
1160
|
+
|
|
1161
|
+
var semantics_buffer: [4]WidgetSemanticsNode = undefined;
|
|
1162
|
+
const semantics = try layout.collectSemantics(&semantics_buffer);
|
|
1163
|
+
try std.testing.expectEqual(@as(usize, 3), semantics.len);
|
|
1164
|
+
try std.testing.expectEqual(WidgetRole.grid, semantics[0].role);
|
|
1165
|
+
try std.testing.expectEqual(@as(?usize, 4), semantics[0].grid_row_count);
|
|
1166
|
+
try std.testing.expectEqual(@as(?usize, 0), semantics[0].grid_column_count);
|
|
1167
|
+
try std.testing.expect(semantics[0].scroll.present);
|
|
1168
|
+
try std.testing.expectEqual(@as(f32, 25), semantics[0].scroll.offset);
|
|
1169
|
+
try std.testing.expectEqual(@as(f32, 45), semantics[0].scroll.viewport_extent);
|
|
1170
|
+
try std.testing.expectEqual(@as(f32, 95), semantics[0].scroll.content_extent);
|
|
1171
|
+
try std.testing.expect(semantics[0].focusable);
|
|
1172
|
+
try std.testing.expect(semantics[0].actions.focus);
|
|
1173
|
+
try std.testing.expect(semantics[0].actions.increment);
|
|
1174
|
+
try std.testing.expect(semantics[0].actions.decrement);
|
|
1175
|
+
try std.testing.expectEqual(@as(ObjectId, 1), layout.focusTargetById(1).?.id);
|
|
1176
|
+
|
|
1177
|
+
try std.testing.expectEqual(WidgetRole.row, semantics[1].role);
|
|
1178
|
+
try std.testing.expectEqual(@as(ObjectId, 3), semantics[1].id);
|
|
1179
|
+
try std.testing.expectEqual(@as(?usize, 1), semantics[1].grid_row_index);
|
|
1180
|
+
try std.testing.expectEqual(@as(?usize, 4), semantics[1].grid_row_count);
|
|
1181
|
+
|
|
1182
|
+
try std.testing.expectEqual(WidgetRole.row, semantics[2].role);
|
|
1183
|
+
try std.testing.expectEqual(@as(ObjectId, 4), semantics[2].id);
|
|
1184
|
+
try std.testing.expectEqual(@as(?usize, 2), semantics[2].grid_row_index);
|
|
1185
|
+
try std.testing.expectEqual(@as(?usize, 4), semantics[2].grid_row_count);
|
|
1186
|
+
|
|
1187
|
+
var commands: [16]CanvasCommand = undefined;
|
|
1188
|
+
var builder = Builder.init(&commands);
|
|
1189
|
+
try layout.emitDisplayList(&builder, .{});
|
|
1190
|
+
const display_list = builder.displayList();
|
|
1191
|
+
switch (display_list.findCommandById(widgetPartId(1, 1)).?.command) {
|
|
1192
|
+
.push_clip => |clip| try expectRect(geometry.RectF.init(0, 0, 160, 45), clip.rect),
|
|
1193
|
+
else => return error.TestUnexpectedResult,
|
|
1194
|
+
}
|
|
1195
|
+
switch (display_list.findCommandById(widgetPartId(1, 2)).?.command) {
|
|
1196
|
+
.fill_rounded_rect => |track| try expectRect(geometry.RectF.init(154, 3, 3, 39), track.rect),
|
|
1197
|
+
else => return error.TestUnexpectedResult,
|
|
1198
|
+
}
|
|
1199
|
+
switch (display_list.findCommandById(widgetPartId(1, 3)).?.command) {
|
|
1200
|
+
.fill_rounded_rect => |thumb| {
|
|
1201
|
+
try std.testing.expectApproxEqAbs(@as(f32, 13.263), thumb.rect.y, 0.001);
|
|
1202
|
+
try std.testing.expectApproxEqAbs(@as(f32, 18.474), thumb.rect.height, 0.001);
|
|
1203
|
+
},
|
|
1204
|
+
else => return error.TestUnexpectedResult,
|
|
1205
|
+
}
|
|
1206
|
+
}
|
|
1207
|
+
|
|
1208
|
+
test "widget scroll view offsets children and clips display list" {
|
|
1209
|
+
const children = [_]Widget{
|
|
1210
|
+
.{ .id = 2, .kind = .button, .frame = geometry.RectF.init(0, 0, 0, 32), .text = "One" },
|
|
1211
|
+
.{ .id = 3, .kind = .button, .frame = geometry.RectF.init(0, 44, 0, 32), .text = "Two" },
|
|
1212
|
+
.{ .id = 4, .kind = .button, .frame = geometry.RectF.init(0, 80, 0, 32), .text = "Three" },
|
|
1213
|
+
};
|
|
1214
|
+
const scroll = Widget{
|
|
1215
|
+
.id = 1,
|
|
1216
|
+
.kind = .scroll_view,
|
|
1217
|
+
.value = 20,
|
|
1218
|
+
.children = &children,
|
|
1219
|
+
};
|
|
1220
|
+
|
|
1221
|
+
var nodes: [5]WidgetLayoutNode = undefined;
|
|
1222
|
+
const layout = try layoutWidgetTree(scroll, geometry.RectF.init(0, 0, 120, 60), &nodes);
|
|
1223
|
+
try std.testing.expectEqual(@as(usize, 4), layout.nodeCount());
|
|
1224
|
+
try expectLayoutFrame(layout, 1, geometry.RectF.init(0, 0, 120, 60));
|
|
1225
|
+
try expectLayoutFrame(layout, 2, geometry.RectF.init(0, -20, 120, 32));
|
|
1226
|
+
try expectLayoutFrame(layout, 3, geometry.RectF.init(0, 24, 120, 32));
|
|
1227
|
+
try expectLayoutFrame(layout, 4, geometry.RectF.init(0, 60, 120, 32));
|
|
1228
|
+
|
|
1229
|
+
var commands: [16]CanvasCommand = undefined;
|
|
1230
|
+
const tokens: DesignTokens = .{};
|
|
1231
|
+
var builder = Builder.init(&commands);
|
|
1232
|
+
try layout.emitDisplayList(&builder, tokens);
|
|
1233
|
+
// Three visible flat buttons at 3 commands each inside the clip
|
|
1234
|
+
// pair, then the scrollbar track and thumb.
|
|
1235
|
+
const display_list = builder.displayList();
|
|
1236
|
+
try std.testing.expectEqual(@as(usize, 13), display_list.commandCount());
|
|
1237
|
+
switch (display_list.commands[0]) {
|
|
1238
|
+
.push_clip => |clip| try expectRect(geometry.RectF.init(0, 0, 120, 60), clip.rect),
|
|
1239
|
+
else => return error.TestUnexpectedResult,
|
|
1240
|
+
}
|
|
1241
|
+
try std.testing.expect(display_list.commands[10] == .pop_clip);
|
|
1242
|
+
switch (display_list.commands[11]) {
|
|
1243
|
+
.fill_rounded_rect => |track| {
|
|
1244
|
+
try std.testing.expectEqual(@as(ObjectId, widgetPartId(1, 2)), track.id);
|
|
1245
|
+
try expectRect(geometry.RectF.init(114, 3, 3, 54), track.rect);
|
|
1246
|
+
try expectFillColor(colorWithAlpha(tokens.colors.border, 0.22), track.fill);
|
|
1247
|
+
},
|
|
1248
|
+
else => return error.TestUnexpectedResult,
|
|
1249
|
+
}
|
|
1250
|
+
switch (display_list.commands[12]) {
|
|
1251
|
+
.fill_rounded_rect => |thumb| {
|
|
1252
|
+
try std.testing.expectEqual(@as(ObjectId, widgetPartId(1, 3)), thumb.id);
|
|
1253
|
+
try std.testing.expectApproxEqAbs(@as(f32, 12.642), thumb.rect.y, 0.001);
|
|
1254
|
+
try std.testing.expectApproxEqAbs(@as(f32, 28.928), thumb.rect.height, 0.001);
|
|
1255
|
+
try expectFillColor(colorWithAlpha(tokens.colors.text_muted, 0.55), thumb.fill);
|
|
1256
|
+
},
|
|
1257
|
+
else => return error.TestUnexpectedResult,
|
|
1258
|
+
}
|
|
1259
|
+
|
|
1260
|
+
try std.testing.expectEqual(@as(ObjectId, 2), layout.hitTest(geometry.PointF.init(10, 4)).?.id);
|
|
1261
|
+
try std.testing.expectEqual(@as(ObjectId, 3), layout.hitTest(geometry.PointF.init(10, 50)).?.id);
|
|
1262
|
+
const blank_hit = layout.hitTest(geometry.PointF.init(10, 58)).?;
|
|
1263
|
+
try std.testing.expectEqual(@as(ObjectId, 1), blank_hit.id);
|
|
1264
|
+
try std.testing.expectEqual(WidgetKind.scroll_view, blank_hit.kind);
|
|
1265
|
+
try std.testing.expect(layout.hitTest(geometry.PointF.init(10, 70)) == null);
|
|
1266
|
+
|
|
1267
|
+
var route_buffer: [2]WidgetEventRouteEntry = undefined;
|
|
1268
|
+
const route = try layout.routePointerEvent(.{ .phase = .wheel, .point = geometry.PointF.init(10, 58), .delta = geometry.OffsetF.init(0, -12) }, &route_buffer);
|
|
1269
|
+
try std.testing.expectEqual(@as(ObjectId, 1), route.target.?.id);
|
|
1270
|
+
try std.testing.expectEqual(@as(usize, 1), route.entries.len);
|
|
1271
|
+
try std.testing.expectEqual(WidgetEventPhase.target, route.entries[0].phase);
|
|
1272
|
+
|
|
1273
|
+
var semantics_buffer: [4]WidgetSemanticsNode = undefined;
|
|
1274
|
+
const semantics = try layout.collectSemantics(&semantics_buffer);
|
|
1275
|
+
try std.testing.expectEqual(@as(usize, 4), semantics.len);
|
|
1276
|
+
try std.testing.expectEqual(WidgetRole.group, semantics[0].role);
|
|
1277
|
+
try std.testing.expectApproxEqAbs(@as(f32, 20.0 / 52.0), semantics[0].value.?, 0.001);
|
|
1278
|
+
try std.testing.expect(semantics[0].scroll.present);
|
|
1279
|
+
try std.testing.expectEqual(@as(f32, 20.0), semantics[0].scroll.offset);
|
|
1280
|
+
try std.testing.expectEqual(@as(f32, 60.0), semantics[0].scroll.viewport_extent);
|
|
1281
|
+
try std.testing.expectEqual(@as(f32, 112.0), semantics[0].scroll.content_extent);
|
|
1282
|
+
try std.testing.expect(semantics[0].focusable);
|
|
1283
|
+
try std.testing.expect(semantics[0].actions.focus);
|
|
1284
|
+
try std.testing.expect(semantics[0].actions.increment);
|
|
1285
|
+
try std.testing.expect(semantics[0].actions.decrement);
|
|
1286
|
+
}
|
|
1287
|
+
|
|
1288
|
+
test "widget scroll view scrollbars use control visual tokens" {
|
|
1289
|
+
const children = [_]Widget{
|
|
1290
|
+
.{ .id = 2, .kind = .button, .frame = geometry.RectF.init(0, 0, 0, 32), .text = "One" },
|
|
1291
|
+
.{ .id = 3, .kind = .button, .frame = geometry.RectF.init(0, 44, 0, 32), .text = "Two" },
|
|
1292
|
+
.{ .id = 4, .kind = .button, .frame = geometry.RectF.init(0, 80, 0, 32), .text = "Three" },
|
|
1293
|
+
};
|
|
1294
|
+
const scroll = Widget{
|
|
1295
|
+
.id = 1,
|
|
1296
|
+
.kind = .scroll_view,
|
|
1297
|
+
.value = 20,
|
|
1298
|
+
.children = &children,
|
|
1299
|
+
};
|
|
1300
|
+
const tokens = DesignTokens{
|
|
1301
|
+
.controls = .{
|
|
1302
|
+
.scrollbar = .{
|
|
1303
|
+
.background = Color.rgb8(25, 31, 37),
|
|
1304
|
+
.foreground = Color.rgb8(132, 144, 156),
|
|
1305
|
+
.radius = 4,
|
|
1306
|
+
},
|
|
1307
|
+
},
|
|
1308
|
+
};
|
|
1309
|
+
|
|
1310
|
+
var nodes: [5]WidgetLayoutNode = undefined;
|
|
1311
|
+
const layout = try layoutWidgetTree(scroll, geometry.RectF.init(0, 0, 120, 60), &nodes);
|
|
1312
|
+
|
|
1313
|
+
var commands: [16]CanvasCommand = undefined;
|
|
1314
|
+
var builder = Builder.init(&commands);
|
|
1315
|
+
try layout.emitDisplayList(&builder, tokens);
|
|
1316
|
+
const display_list = builder.displayList();
|
|
1317
|
+
switch (display_list.findCommandById(widgetPartId(1, 2)).?.command) {
|
|
1318
|
+
.fill_rounded_rect => |track| {
|
|
1319
|
+
try std.testing.expectEqualDeep(Radius.all(4), track.radius);
|
|
1320
|
+
try expectFillColor(Color.rgb8(25, 31, 37), track.fill);
|
|
1321
|
+
},
|
|
1322
|
+
else => return error.TestUnexpectedResult,
|
|
1323
|
+
}
|
|
1324
|
+
switch (display_list.findCommandById(widgetPartId(1, 3)).?.command) {
|
|
1325
|
+
.fill_rounded_rect => |thumb| {
|
|
1326
|
+
try std.testing.expectEqualDeep(Radius.all(4), thumb.radius);
|
|
1327
|
+
try expectFillColor(Color.rgb8(132, 144, 156), thumb.fill);
|
|
1328
|
+
},
|
|
1329
|
+
else => return error.TestUnexpectedResult,
|
|
1330
|
+
}
|
|
1331
|
+
}
|
|
1332
|
+
|
|
1333
|
+
test "widget focus traversal skips scroll clipped children" {
|
|
1334
|
+
const children = [_]Widget{
|
|
1335
|
+
.{ .id = 2, .kind = .button, .frame = geometry.RectF.init(0, 0, 0, 32), .text = "One" },
|
|
1336
|
+
.{ .id = 3, .kind = .button, .frame = geometry.RectF.init(0, 44, 0, 32), .text = "Two" },
|
|
1337
|
+
.{ .id = 4, .kind = .button, .frame = geometry.RectF.init(0, 80, 0, 32), .text = "Three" },
|
|
1338
|
+
};
|
|
1339
|
+
const scroll = Widget{
|
|
1340
|
+
.id = 1,
|
|
1341
|
+
.kind = .scroll_view,
|
|
1342
|
+
.value = 20,
|
|
1343
|
+
.children = &children,
|
|
1344
|
+
};
|
|
1345
|
+
|
|
1346
|
+
var nodes: [5]WidgetLayoutNode = undefined;
|
|
1347
|
+
const layout = try layoutWidgetTree(scroll, geometry.RectF.init(0, 0, 120, 60), &nodes);
|
|
1348
|
+
try expectLayoutFrame(layout, 2, geometry.RectF.init(0, -20, 120, 32));
|
|
1349
|
+
try expectLayoutFrame(layout, 3, geometry.RectF.init(0, 24, 120, 32));
|
|
1350
|
+
try expectLayoutFrame(layout, 4, geometry.RectF.init(0, 60, 120, 32));
|
|
1351
|
+
|
|
1352
|
+
try std.testing.expectEqual(@as(ObjectId, 1), layout.focusTarget(null, .forward).?.id);
|
|
1353
|
+
try std.testing.expectEqual(@as(ObjectId, 2), layout.focusTarget(1, .forward).?.id);
|
|
1354
|
+
try std.testing.expectEqual(@as(ObjectId, 3), layout.focusTarget(2, .forward).?.id);
|
|
1355
|
+
try std.testing.expectEqual(@as(ObjectId, 1), layout.focusTarget(3, .forward).?.id);
|
|
1356
|
+
try std.testing.expectEqual(@as(ObjectId, 3), layout.focusTarget(1, .backward).?.id);
|
|
1357
|
+
try std.testing.expect(layout.focusTargetById(4) == null);
|
|
1358
|
+
}
|
|
1359
|
+
|
|
1360
|
+
test "scroll state applies wheel deltas kinetic decay and bounds" {
|
|
1361
|
+
const physics = ScrollPhysics{
|
|
1362
|
+
.wheel_multiplier = 2,
|
|
1363
|
+
.wheel_velocity_scale = 10,
|
|
1364
|
+
.deceleration_per_second = 0.5,
|
|
1365
|
+
.stop_velocity = 1,
|
|
1366
|
+
};
|
|
1367
|
+
const start = ScrollState{
|
|
1368
|
+
.offset = 10,
|
|
1369
|
+
.viewport_extent = 100,
|
|
1370
|
+
.content_extent = 360,
|
|
1371
|
+
};
|
|
1372
|
+
|
|
1373
|
+
const wheeled = start.applyWheel(30, physics);
|
|
1374
|
+
try std.testing.expectEqual(@as(f32, 70), wheeled.offset);
|
|
1375
|
+
try std.testing.expectEqual(@as(f32, 600), wheeled.velocity);
|
|
1376
|
+
|
|
1377
|
+
const stepped = wheeled.stepKinetic(100, physics);
|
|
1378
|
+
try std.testing.expect(stepped.offset > wheeled.offset);
|
|
1379
|
+
try std.testing.expect(stepped.velocity > 0);
|
|
1380
|
+
try std.testing.expect(stepped.velocity < wheeled.velocity);
|
|
1381
|
+
|
|
1382
|
+
const clamped_by_default = wheeled.applyWheel(1000, physics);
|
|
1383
|
+
try std.testing.expectEqual(@as(f32, 260), clamped_by_default.offset);
|
|
1384
|
+
try std.testing.expectEqual(@as(f32, 0), clamped_by_default.velocity);
|
|
1385
|
+
|
|
1386
|
+
const clamped = wheeled.applyWheelClamped(1000, physics);
|
|
1387
|
+
try std.testing.expectEqual(@as(f32, 260), clamped.offset);
|
|
1388
|
+
try std.testing.expectEqual(@as(f32, 0), clamped.velocity);
|
|
1389
|
+
}
|
|
1390
|
+
|
|
1391
|
+
test "scroll overscroll gates rubber-band: none pins at the edges, rubber_band excursions recover" {
|
|
1392
|
+
const start = ScrollState{
|
|
1393
|
+
.offset = 250,
|
|
1394
|
+
.viewport_extent = 100,
|
|
1395
|
+
.content_extent = 360,
|
|
1396
|
+
};
|
|
1397
|
+
|
|
1398
|
+
// Overscroll off (the default): a wheel past the edge clamps and
|
|
1399
|
+
// zeroes velocity — the clean stop — and kinetic stepping never
|
|
1400
|
+
// carries the offset past the boundary.
|
|
1401
|
+
const pinned_physics = ScrollPhysics{};
|
|
1402
|
+
try std.testing.expectEqual(canvas.ScrollOverscroll.none, pinned_physics.overscroll);
|
|
1403
|
+
const pinned = start.applyWheel(1000, pinned_physics);
|
|
1404
|
+
try std.testing.expectEqual(@as(f32, 260), pinned.offset);
|
|
1405
|
+
try std.testing.expectEqual(@as(f32, 0), pinned.velocity);
|
|
1406
|
+
var rolling = ScrollState{
|
|
1407
|
+
.offset = 250,
|
|
1408
|
+
.velocity = 400,
|
|
1409
|
+
.viewport_extent = 100,
|
|
1410
|
+
.content_extent = 360,
|
|
1411
|
+
};
|
|
1412
|
+
rolling = rolling.stepKinetic(100, pinned_physics);
|
|
1413
|
+
try std.testing.expectEqual(@as(f32, 260), rolling.offset);
|
|
1414
|
+
try std.testing.expectEqual(@as(f32, 0), rolling.velocity);
|
|
1415
|
+
try std.testing.expect(!rolling.needsKineticStep(pinned_physics));
|
|
1416
|
+
|
|
1417
|
+
// Overscroll on: the same wheel travels past the edge under
|
|
1418
|
+
// resistance, and kinetic steps pull the excursion back to the edge.
|
|
1419
|
+
const bouncy_physics = ScrollPhysics{ .overscroll = .rubber_band };
|
|
1420
|
+
const bounced = start.applyWheel(1000, bouncy_physics);
|
|
1421
|
+
try std.testing.expect(bounced.offset > 260);
|
|
1422
|
+
try std.testing.expect(bounced.overscroll() > 0);
|
|
1423
|
+
var recovering = bounced;
|
|
1424
|
+
recovering.velocity = 0;
|
|
1425
|
+
var steps: usize = 0;
|
|
1426
|
+
while (recovering.overscroll() != 0 and steps < 200) : (steps += 1) {
|
|
1427
|
+
recovering = recovering.stepKinetic(16, bouncy_physics);
|
|
1428
|
+
}
|
|
1429
|
+
try std.testing.expectEqual(@as(f32, 260), recovering.offset);
|
|
1430
|
+
|
|
1431
|
+
// A stale out-of-range offset on a pinned region self-heals in one
|
|
1432
|
+
// kinetic step instead of animating a return.
|
|
1433
|
+
const stale = ScrollState{
|
|
1434
|
+
.offset = 300,
|
|
1435
|
+
.viewport_extent = 100,
|
|
1436
|
+
.content_extent = 360,
|
|
1437
|
+
};
|
|
1438
|
+
const healed = stale.stepKinetic(16, pinned_physics);
|
|
1439
|
+
try std.testing.expectEqual(@as(f32, 260), healed.offset);
|
|
1440
|
+
}
|
|
1441
|
+
|
|
1442
|
+
test "virtual list range computes visible and overscan windows" {
|
|
1443
|
+
const range = virtualListRange(.{
|
|
1444
|
+
.item_count = 100,
|
|
1445
|
+
.item_extent = 24,
|
|
1446
|
+
.item_gap = 4,
|
|
1447
|
+
.viewport_extent = 70,
|
|
1448
|
+
.scroll_offset = 50,
|
|
1449
|
+
.overscan = 1,
|
|
1450
|
+
});
|
|
1451
|
+
|
|
1452
|
+
try std.testing.expectEqual(@as(usize, 0), range.start_index);
|
|
1453
|
+
try std.testing.expectEqual(@as(usize, 6), range.end_index);
|
|
1454
|
+
try std.testing.expectEqual(@as(usize, 1), range.first_visible_index);
|
|
1455
|
+
try std.testing.expectEqual(@as(usize, 4), range.last_visible_index);
|
|
1456
|
+
try std.testing.expectEqual(@as(usize, 6), range.itemCount());
|
|
1457
|
+
try std.testing.expectEqual(@as(f32, 2796), range.content_extent);
|
|
1458
|
+
try std.testing.expectEqual(@as(f32, 2632), range.after_extent);
|
|
1459
|
+
|
|
1460
|
+
const top_rubberband = virtualListRange(.{
|
|
1461
|
+
.item_count = 10,
|
|
1462
|
+
.item_extent = 20,
|
|
1463
|
+
.item_gap = 5,
|
|
1464
|
+
.viewport_extent = 50,
|
|
1465
|
+
.scroll_offset = -14,
|
|
1466
|
+
.overscan = 1,
|
|
1467
|
+
});
|
|
1468
|
+
try std.testing.expectEqual(@as(f32, 0), top_rubberband.scroll_offset);
|
|
1469
|
+
try std.testing.expectEqual(@as(f32, -14), top_rubberband.layout_offset);
|
|
1470
|
+
try std.testing.expectEqual(@as(usize, 0), top_rubberband.first_visible_index);
|
|
1471
|
+
|
|
1472
|
+
const bottom_rubberband = virtualListRange(.{
|
|
1473
|
+
.item_count = 10,
|
|
1474
|
+
.item_extent = 20,
|
|
1475
|
+
.item_gap = 5,
|
|
1476
|
+
.viewport_extent = 50,
|
|
1477
|
+
.scroll_offset = 216,
|
|
1478
|
+
.overscan = 1,
|
|
1479
|
+
});
|
|
1480
|
+
try std.testing.expectEqual(@as(f32, 195), bottom_rubberband.scroll_offset);
|
|
1481
|
+
try std.testing.expectEqual(@as(f32, 216), bottom_rubberband.layout_offset);
|
|
1482
|
+
try std.testing.expectEqual(@as(usize, 7), bottom_rubberband.first_visible_index);
|
|
1483
|
+
|
|
1484
|
+
const bounded_rubberband = virtualListRange(.{
|
|
1485
|
+
.item_count = 10,
|
|
1486
|
+
.item_extent = 20,
|
|
1487
|
+
.item_gap = 5,
|
|
1488
|
+
.viewport_extent = 50,
|
|
1489
|
+
.scroll_offset = 1000,
|
|
1490
|
+
.overscan = 1,
|
|
1491
|
+
});
|
|
1492
|
+
try std.testing.expectEqual(@as(f32, 195), bounded_rubberband.scroll_offset);
|
|
1493
|
+
try std.testing.expectEqual(@as(f32, 245), bounded_rubberband.layout_offset);
|
|
1494
|
+
|
|
1495
|
+
const empty = virtualListRange(.{
|
|
1496
|
+
.item_count = 10,
|
|
1497
|
+
.item_extent = 0,
|
|
1498
|
+
.viewport_extent = 100,
|
|
1499
|
+
});
|
|
1500
|
+
try std.testing.expect(empty.isEmpty());
|
|
1501
|
+
}
|
|
1502
|
+
|
|
1503
|
+
test "widget virtualized scroll view lays out only visible overscan children" {
|
|
1504
|
+
const children = [_]Widget{
|
|
1505
|
+
.{ .id = 2, .kind = .button, .frame = geometry.RectF.init(0, 0, 0, 20), .text = "Zero" },
|
|
1506
|
+
.{ .id = 3, .kind = .button, .frame = geometry.RectF.init(0, 0, 0, 20), .text = "One" },
|
|
1507
|
+
.{ .id = 4, .kind = .button, .frame = geometry.RectF.init(0, 0, 0, 20), .text = "Two" },
|
|
1508
|
+
.{ .id = 5, .kind = .button, .frame = geometry.RectF.init(0, 0, 0, 20), .text = "Three" },
|
|
1509
|
+
.{ .id = 6, .kind = .button, .frame = geometry.RectF.init(0, 0, 0, 20), .text = "Four" },
|
|
1510
|
+
.{ .id = 7, .kind = .button, .frame = geometry.RectF.init(0, 0, 0, 20), .text = "Five" },
|
|
1511
|
+
.{ .id = 8, .kind = .button, .frame = geometry.RectF.init(0, 0, 0, 20), .text = "Six" },
|
|
1512
|
+
.{ .id = 9, .kind = .button, .frame = geometry.RectF.init(0, 0, 0, 20), .text = "Seven" },
|
|
1513
|
+
.{ .id = 10, .kind = .button, .frame = geometry.RectF.init(0, 0, 0, 20), .text = "Eight" },
|
|
1514
|
+
.{ .id = 11, .kind = .button, .frame = geometry.RectF.init(0, 0, 0, 20), .text = "Nine" },
|
|
1515
|
+
};
|
|
1516
|
+
const scroll = Widget{
|
|
1517
|
+
.id = 1,
|
|
1518
|
+
.kind = .scroll_view,
|
|
1519
|
+
.value = 45,
|
|
1520
|
+
.layout = .{
|
|
1521
|
+
.gap = 5,
|
|
1522
|
+
.virtualized = true,
|
|
1523
|
+
.virtual_item_extent = 20,
|
|
1524
|
+
.virtual_overscan = 1,
|
|
1525
|
+
},
|
|
1526
|
+
.children = &children,
|
|
1527
|
+
};
|
|
1528
|
+
|
|
1529
|
+
var nodes: [6]WidgetLayoutNode = undefined;
|
|
1530
|
+
const layout = try layoutWidgetTree(scroll, geometry.RectF.init(0, 0, 120, 50), &nodes);
|
|
1531
|
+
try std.testing.expectEqual(@as(usize, 6), layout.nodeCount());
|
|
1532
|
+
try std.testing.expectEqual(@as(?u32, 10), layout.nodes[0].widget.semantics.list_item_count);
|
|
1533
|
+
try std.testing.expectEqual(@as(f32, 20), layout.nodes[0].widget.layout.virtual_item_extent);
|
|
1534
|
+
const scroll_range = layout.virtualRangeById(1).?;
|
|
1535
|
+
try std.testing.expectEqual(@as(usize, 0), scroll_range.start_index);
|
|
1536
|
+
try std.testing.expectEqual(@as(usize, 5), scroll_range.end_index);
|
|
1537
|
+
try std.testing.expectEqual(@as(usize, 1), scroll_range.first_visible_index);
|
|
1538
|
+
try std.testing.expectEqual(@as(usize, 3), scroll_range.last_visible_index);
|
|
1539
|
+
try expectLayoutFrame(layout, 1, geometry.RectF.init(0, 0, 120, 50));
|
|
1540
|
+
try expectLayoutFrame(layout, 2, geometry.RectF.init(0, -45, 120, 20));
|
|
1541
|
+
try expectLayoutFrame(layout, 3, geometry.RectF.init(0, -20, 120, 20));
|
|
1542
|
+
try expectLayoutFrame(layout, 4, geometry.RectF.init(0, 5, 120, 20));
|
|
1543
|
+
try expectLayoutFrame(layout, 5, geometry.RectF.init(0, 30, 120, 20));
|
|
1544
|
+
try expectLayoutFrame(layout, 6, geometry.RectF.init(0, 55, 120, 20));
|
|
1545
|
+
try std.testing.expect(layout.findById(7) == null);
|
|
1546
|
+
|
|
1547
|
+
try std.testing.expectEqual(@as(ObjectId, 4), layout.hitTest(geometry.PointF.init(10, 8)).?.id);
|
|
1548
|
+
try std.testing.expect(layout.hitTest(geometry.PointF.init(10, 56)) == null);
|
|
1549
|
+
|
|
1550
|
+
const top_overscroll = Widget{
|
|
1551
|
+
.id = 20,
|
|
1552
|
+
.kind = .scroll_view,
|
|
1553
|
+
.value = -12,
|
|
1554
|
+
.layout = .{
|
|
1555
|
+
.gap = 5,
|
|
1556
|
+
.virtualized = true,
|
|
1557
|
+
.virtual_item_extent = 20,
|
|
1558
|
+
.virtual_overscan = 1,
|
|
1559
|
+
},
|
|
1560
|
+
.children = &children,
|
|
1561
|
+
};
|
|
1562
|
+
var top_nodes: [5]WidgetLayoutNode = undefined;
|
|
1563
|
+
const top_layout = try layoutWidgetTree(top_overscroll, geometry.RectF.init(0, 0, 120, 50), &top_nodes);
|
|
1564
|
+
try expectLayoutFrame(top_layout, 2, geometry.RectF.init(0, 12, 120, 20));
|
|
1565
|
+
try expectLayoutFrame(top_layout, 3, geometry.RectF.init(0, 37, 120, 20));
|
|
1566
|
+
try std.testing.expectEqual(@as(f32, 0), top_layout.virtualRangeById(20).?.scroll_offset);
|
|
1567
|
+
try std.testing.expectEqual(@as(f32, -12), top_layout.virtualRangeById(20).?.layout_offset);
|
|
1568
|
+
}
|
|
1569
|
+
|
|
1570
|
+
test "windowed virtual list lays out the built window at absolute virtual positions" {
|
|
1571
|
+
// The WINDOWED contract: children are the built slice (here items
|
|
1572
|
+
// 100..106 of a 100k list), `virtual_first_index` names where it
|
|
1573
|
+
// starts, and the declared `virtual_item_count` drives the content
|
|
1574
|
+
// extent, the range math, and the list_item semantics — the view
|
|
1575
|
+
// never materializes the other 99_994 items.
|
|
1576
|
+
const window = [_]Widget{
|
|
1577
|
+
.{ .id = 2, .kind = .list_item, .frame = geometry.RectF.init(0, 0, 0, 20), .text = "Item 100" },
|
|
1578
|
+
.{ .id = 3, .kind = .list_item, .frame = geometry.RectF.init(0, 0, 0, 20), .text = "Item 101" },
|
|
1579
|
+
.{ .id = 4, .kind = .list_item, .frame = geometry.RectF.init(0, 0, 0, 20), .text = "Item 102" },
|
|
1580
|
+
.{ .id = 5, .kind = .list_item, .frame = geometry.RectF.init(0, 0, 0, 20), .text = "Item 103" },
|
|
1581
|
+
.{ .id = 6, .kind = .list_item, .frame = geometry.RectF.init(0, 0, 0, 20), .text = "Item 104" },
|
|
1582
|
+
.{ .id = 7, .kind = .list_item, .frame = geometry.RectF.init(0, 0, 0, 20), .text = "Item 105" },
|
|
1583
|
+
};
|
|
1584
|
+
const list = Widget{
|
|
1585
|
+
.id = 1,
|
|
1586
|
+
.kind = .scroll_view,
|
|
1587
|
+
// Item 100's row top: 100 * (20 + 5).
|
|
1588
|
+
.value = 2500,
|
|
1589
|
+
.layout = .{
|
|
1590
|
+
.gap = 5,
|
|
1591
|
+
.virtualized = true,
|
|
1592
|
+
.virtual_item_extent = 20,
|
|
1593
|
+
.virtual_overscan = 1,
|
|
1594
|
+
.virtual_item_count = 100_000,
|
|
1595
|
+
.virtual_first_index = 100,
|
|
1596
|
+
},
|
|
1597
|
+
.children = &window,
|
|
1598
|
+
};
|
|
1599
|
+
|
|
1600
|
+
var nodes: [8]WidgetLayoutNode = undefined;
|
|
1601
|
+
const layout = try layoutWidgetTree(list, geometry.RectF.init(0, 0, 120, 50), &nodes);
|
|
1602
|
+
|
|
1603
|
+
// The runtime-scrolled predicate holds for exactly this shape.
|
|
1604
|
+
try std.testing.expect(support.canvas.widgetVirtualRuntimeScrolled(layout.nodes[0].widget));
|
|
1605
|
+
|
|
1606
|
+
// Semantics and extent derive from the DECLARED count: 100k items of
|
|
1607
|
+
// stride 25 (minus the trailing gap), not the six built children.
|
|
1608
|
+
try std.testing.expectEqual(@as(?u32, 100_000), layout.nodes[0].widget.semantics.list_item_count);
|
|
1609
|
+
try std.testing.expectEqual(@as(f32, 2_499_995), virtualWidgetScrollContentExtent(layout.nodes[0].widget, 50));
|
|
1610
|
+
|
|
1611
|
+
// The visible range (offset 2500, viewport 50, overscan 1) is items
|
|
1612
|
+
// 99..104 (end exclusive); intersected with the built window it
|
|
1613
|
+
// mounts 100..103, each at its ABSOLUTE virtual position.
|
|
1614
|
+
const range = layout.virtualRangeById(1).?;
|
|
1615
|
+
try std.testing.expectEqual(@as(usize, 99), range.start_index);
|
|
1616
|
+
try std.testing.expectEqual(@as(usize, 104), range.end_index);
|
|
1617
|
+
try std.testing.expectEqual(@as(usize, 5), layout.nodeCount());
|
|
1618
|
+
try expectLayoutFrame(layout, 2, geometry.RectF.init(0, 0, 120, 20));
|
|
1619
|
+
try expectLayoutFrame(layout, 3, geometry.RectF.init(0, 25, 120, 20));
|
|
1620
|
+
try expectLayoutFrame(layout, 4, geometry.RectF.init(0, 50, 120, 20));
|
|
1621
|
+
try expectLayoutFrame(layout, 5, geometry.RectF.init(0, 75, 120, 20));
|
|
1622
|
+
try std.testing.expect(layout.findById(6) == null);
|
|
1623
|
+
try std.testing.expect(layout.findById(7) == null);
|
|
1624
|
+
|
|
1625
|
+
// Built rows carry their absolute item indices against the declared
|
|
1626
|
+
// count — assistive tech reads "item 101 of 100000".
|
|
1627
|
+
try std.testing.expectEqual(@as(?u32, 100), layout.findById(2).?.widget.semantics.list_item_index);
|
|
1628
|
+
try std.testing.expectEqual(@as(?u32, 100_000), layout.findById(2).?.widget.semantics.list_item_count);
|
|
1629
|
+
try std.testing.expectEqual(@as(?u32, 103), layout.findById(5).?.widget.semantics.list_item_index);
|
|
1630
|
+
|
|
1631
|
+
// A window that under-covers the visible range mounts only the
|
|
1632
|
+
// intersection (the coverage-retry rebuild widens it): scrolled to
|
|
1633
|
+
// the very end, the same 100..106 window mounts nothing.
|
|
1634
|
+
var tail = list;
|
|
1635
|
+
tail.value = 2_499_995 - 50;
|
|
1636
|
+
var tail_nodes: [8]WidgetLayoutNode = undefined;
|
|
1637
|
+
const tail_layout = try layoutWidgetTree(tail, geometry.RectF.init(0, 0, 120, 50), &tail_nodes);
|
|
1638
|
+
try std.testing.expectEqual(@as(usize, 1), tail_layout.nodeCount());
|
|
1639
|
+
const tail_range = tail_layout.virtualRangeById(1).?;
|
|
1640
|
+
try std.testing.expectEqual(@as(usize, 99_996), tail_range.start_index);
|
|
1641
|
+
try std.testing.expectEqual(@as(usize, 100_000), tail_range.end_index);
|
|
1642
|
+
}
|
|
1643
|
+
|
|
1644
|
+
// The overflow diagnostic's test seam lives on the layout module itself
|
|
1645
|
+
// (same canvas-module instance `layoutWidgetTree` runs through), so
|
|
1646
|
+
// these tests read exactly the counter the diagnostic path increments.
|
|
1647
|
+
const widget_layout_module = @import("widget_layout.zig");
|
|
1648
|
+
|
|
1649
|
+
test "scroll scopes silence the vertical overflow diagnostic; bare overflow still warns" {
|
|
1650
|
+
// A trailing virtualized scroll in a flex column, with the mounted
|
|
1651
|
+
// window's extent (10 rows x 25 stride = 250) far past the space
|
|
1652
|
+
// the column can give it (140 - 40 header = 100). This is the
|
|
1653
|
+
// normal virtual-list operating mode — the runtime scrolls the
|
|
1654
|
+
// window — so the layout must be correct AND no overflow
|
|
1655
|
+
// diagnostic may fire for it. The diagnostic used to blame the
|
|
1656
|
+
// parent bookkeeping here on every rebuild (hundreds of identical
|
|
1657
|
+
// lines in a scrolling app) while the layout audit stayed clean.
|
|
1658
|
+
var window_rows: [10]Widget = undefined;
|
|
1659
|
+
for (&window_rows, 0..) |*row, index| {
|
|
1660
|
+
row.* = .{
|
|
1661
|
+
.id = @intCast(10 + index),
|
|
1662
|
+
.kind = .list_item,
|
|
1663
|
+
.frame = geometry.RectF.init(0, 0, 0, 20),
|
|
1664
|
+
.text = "Row",
|
|
1665
|
+
};
|
|
1666
|
+
}
|
|
1667
|
+
const virtual_column = Widget{
|
|
1668
|
+
.id = 1,
|
|
1669
|
+
.kind = .column,
|
|
1670
|
+
.children = &.{
|
|
1671
|
+
.{ .id = 2, .kind = .row, .frame = geometry.RectF.init(0, 0, 0, 40) },
|
|
1672
|
+
.{
|
|
1673
|
+
.id = 3,
|
|
1674
|
+
.kind = .scroll_view,
|
|
1675
|
+
// Deep in the list: the window tracks a virtualized
|
|
1676
|
+
// offset (items 100.. of 100k mounted).
|
|
1677
|
+
.value = 2500,
|
|
1678
|
+
.layout = .{
|
|
1679
|
+
.grow = 1,
|
|
1680
|
+
.gap = 5,
|
|
1681
|
+
.virtualized = true,
|
|
1682
|
+
.virtual_item_extent = 20,
|
|
1683
|
+
.virtual_item_count = 100_000,
|
|
1684
|
+
.virtual_first_index = 100,
|
|
1685
|
+
},
|
|
1686
|
+
.children = &window_rows,
|
|
1687
|
+
},
|
|
1688
|
+
},
|
|
1689
|
+
};
|
|
1690
|
+
widget_layout_module.test_axis_overflow_diagnostics = 0;
|
|
1691
|
+
var nodes: [16]WidgetLayoutNode = undefined;
|
|
1692
|
+
const layout = try layoutWidgetTree(virtual_column, geometry.RectF.init(0, 0, 120, 140), &nodes);
|
|
1693
|
+
try std.testing.expectEqual(@as(usize, 0), widget_layout_module.test_axis_overflow_diagnostics);
|
|
1694
|
+
// The flex math is untouched by the silenced diagnostic: the grow
|
|
1695
|
+
// scroll takes exactly the space after the header, and the first
|
|
1696
|
+
// mounted row sits at its absolute virtual position (100 * 25 -
|
|
1697
|
+
// 2500 = 0 into the viewport).
|
|
1698
|
+
try expectLayoutFrame(layout, 3, geometry.RectF.init(0, 40, 120, 100));
|
|
1699
|
+
try expectLayoutFrame(layout, 10, geometry.RectF.init(0, 40, 120, 20));
|
|
1700
|
+
|
|
1701
|
+
// The tracked-offset plain scroll shape (a markup `<scroll>` with a
|
|
1702
|
+
// model-owned offset over a column of rows): the wrapper column is
|
|
1703
|
+
// sized to the viewport, its rows extend far past it, pixels are
|
|
1704
|
+
// correct — and the diagnostic stays quiet on every rebuild.
|
|
1705
|
+
var tall_rows: [10]Widget = undefined;
|
|
1706
|
+
for (&tall_rows, 0..) |*row, index| {
|
|
1707
|
+
row.* = .{
|
|
1708
|
+
.id = @intCast(30 + index),
|
|
1709
|
+
.kind = .list_item,
|
|
1710
|
+
.frame = geometry.RectF.init(0, 0, 0, 60),
|
|
1711
|
+
.text = "Note",
|
|
1712
|
+
};
|
|
1713
|
+
}
|
|
1714
|
+
const tracked_column = Widget{
|
|
1715
|
+
.id = 1,
|
|
1716
|
+
.kind = .column,
|
|
1717
|
+
.children = &.{
|
|
1718
|
+
.{ .id = 2, .kind = .row, .frame = geometry.RectF.init(0, 0, 0, 40) },
|
|
1719
|
+
.{
|
|
1720
|
+
.id = 3,
|
|
1721
|
+
.kind = .scroll_view,
|
|
1722
|
+
.value = 50,
|
|
1723
|
+
.layout = .{ .grow = 1 },
|
|
1724
|
+
.children = &.{
|
|
1725
|
+
.{ .id = 4, .kind = .column, .children = &tall_rows },
|
|
1726
|
+
},
|
|
1727
|
+
},
|
|
1728
|
+
},
|
|
1729
|
+
};
|
|
1730
|
+
widget_layout_module.test_axis_overflow_diagnostics = 0;
|
|
1731
|
+
var tracked_nodes: [16]WidgetLayoutNode = undefined;
|
|
1732
|
+
const tracked_layout = try layoutWidgetTree(tracked_column, geometry.RectF.init(0, 0, 120, 140), &tracked_nodes);
|
|
1733
|
+
try std.testing.expectEqual(@as(usize, 0), widget_layout_module.test_axis_overflow_diagnostics);
|
|
1734
|
+
// The wrapper is viewport-sized and scrolled up by the offset; the
|
|
1735
|
+
// rows stack from there — correct pixels, no warning.
|
|
1736
|
+
try expectLayoutFrame(tracked_layout, 4, geometry.RectF.init(0, -10, 120, 100));
|
|
1737
|
+
try expectLayoutFrame(tracked_layout, 30, geometry.RectF.init(0, -10, 120, 60));
|
|
1738
|
+
|
|
1739
|
+
// Control: the same tall column with NO scroll ancestor is real
|
|
1740
|
+
// silent damage — the diagnostic must still fire for it.
|
|
1741
|
+
const bare_column = Widget{
|
|
1742
|
+
.id = 1,
|
|
1743
|
+
.kind = .column,
|
|
1744
|
+
.children = &tall_rows,
|
|
1745
|
+
};
|
|
1746
|
+
widget_layout_module.test_axis_overflow_diagnostics = 0;
|
|
1747
|
+
var bare_nodes: [16]WidgetLayoutNode = undefined;
|
|
1748
|
+
_ = try layoutWidgetTree(bare_column, geometry.RectF.init(0, 0, 120, 140), &bare_nodes);
|
|
1749
|
+
try std.testing.expectEqual(@as(usize, 1), widget_layout_module.test_axis_overflow_diagnostics);
|
|
1750
|
+
|
|
1751
|
+
// Horizontal overflow inside a vertical scroll still warns: nothing
|
|
1752
|
+
// scrolls sideways to reveal those pixels.
|
|
1753
|
+
const wide_row_scroll = Widget{
|
|
1754
|
+
.id = 1,
|
|
1755
|
+
.kind = .scroll_view,
|
|
1756
|
+
.children = &.{
|
|
1757
|
+
.{
|
|
1758
|
+
.id = 2,
|
|
1759
|
+
.kind = .row,
|
|
1760
|
+
.children = &.{
|
|
1761
|
+
.{ .id = 3, .kind = .badge, .frame = geometry.RectF.init(0, 0, 200, 20), .text = "Wide" },
|
|
1762
|
+
.{ .id = 4, .kind = .badge, .frame = geometry.RectF.init(0, 0, 200, 20), .text = "Wider" },
|
|
1763
|
+
},
|
|
1764
|
+
},
|
|
1765
|
+
},
|
|
1766
|
+
};
|
|
1767
|
+
widget_layout_module.test_axis_overflow_diagnostics = 0;
|
|
1768
|
+
var wide_nodes: [8]WidgetLayoutNode = undefined;
|
|
1769
|
+
_ = try layoutWidgetTree(wide_row_scroll, geometry.RectF.init(0, 0, 120, 140), &wide_nodes);
|
|
1770
|
+
try std.testing.expectEqual(@as(usize, 1), widget_layout_module.test_axis_overflow_diagnostics);
|
|
1771
|
+
}
|
|
1772
|
+
|
|
1773
|
+
test "widget virtualized list exposes logical item semantics" {
|
|
1774
|
+
const children = [_]Widget{
|
|
1775
|
+
.{ .id = 2, .kind = .list_item, .frame = geometry.RectF.init(0, 0, 0, 20), .text = "Zero" },
|
|
1776
|
+
.{ .id = 3, .kind = .list_item, .frame = geometry.RectF.init(0, 0, 0, 20), .text = "One" },
|
|
1777
|
+
.{ .id = 4, .kind = .list_item, .frame = geometry.RectF.init(0, 0, 0, 20), .text = "Two" },
|
|
1778
|
+
.{ .id = 5, .kind = .list_item, .frame = geometry.RectF.init(0, 0, 0, 20), .text = "Three" },
|
|
1779
|
+
.{ .id = 6, .kind = .list_item, .frame = geometry.RectF.init(0, 0, 0, 20), .text = "Four" },
|
|
1780
|
+
.{ .id = 7, .kind = .list_item, .frame = geometry.RectF.init(0, 0, 0, 20), .text = "Five" },
|
|
1781
|
+
.{ .id = 8, .kind = .list_item, .frame = geometry.RectF.init(0, 0, 0, 20), .text = "Six" },
|
|
1782
|
+
.{ .id = 9, .kind = .list_item, .frame = geometry.RectF.init(0, 0, 0, 20), .text = "Seven" },
|
|
1783
|
+
.{ .id = 10, .kind = .list_item, .frame = geometry.RectF.init(0, 0, 0, 20), .text = "Eight" },
|
|
1784
|
+
.{ .id = 11, .kind = .list_item, .frame = geometry.RectF.init(0, 0, 0, 20), .text = "Nine" },
|
|
1785
|
+
};
|
|
1786
|
+
const list = Widget{
|
|
1787
|
+
.id = 1,
|
|
1788
|
+
.kind = .list,
|
|
1789
|
+
.value = 45,
|
|
1790
|
+
.layout = .{
|
|
1791
|
+
.gap = 5,
|
|
1792
|
+
.virtualized = true,
|
|
1793
|
+
.virtual_item_extent = 20,
|
|
1794
|
+
.virtual_overscan = 1,
|
|
1795
|
+
},
|
|
1796
|
+
.children = &children,
|
|
1797
|
+
};
|
|
1798
|
+
|
|
1799
|
+
var nodes: [6]WidgetLayoutNode = undefined;
|
|
1800
|
+
const layout = try layoutWidgetTree(list, geometry.RectF.init(0, 0, 120, 50), &nodes);
|
|
1801
|
+
try std.testing.expectEqual(@as(usize, 6), layout.nodeCount());
|
|
1802
|
+
try std.testing.expect(layout.findById(7) == null);
|
|
1803
|
+
|
|
1804
|
+
var semantics_buffer: [6]WidgetSemanticsNode = undefined;
|
|
1805
|
+
const semantics = try layout.collectSemantics(&semantics_buffer);
|
|
1806
|
+
try std.testing.expectEqual(@as(usize, 6), semantics.len);
|
|
1807
|
+
try std.testing.expectEqual(WidgetRole.list, semantics[0].role);
|
|
1808
|
+
try std.testing.expect(!semantics[0].list.present);
|
|
1809
|
+
try std.testing.expect(semantics[0].scroll.present);
|
|
1810
|
+
try std.testing.expectEqual(@as(f32, 45), semantics[0].scroll.offset);
|
|
1811
|
+
try std.testing.expectEqual(@as(f32, 50), semantics[0].scroll.viewport_extent);
|
|
1812
|
+
try std.testing.expectEqual(@as(f32, 245), semantics[0].scroll.content_extent);
|
|
1813
|
+
try std.testing.expect(semantics[0].focusable);
|
|
1814
|
+
try std.testing.expect(semantics[0].actions.focus);
|
|
1815
|
+
try std.testing.expect(semantics[0].actions.increment);
|
|
1816
|
+
try std.testing.expect(semantics[0].actions.decrement);
|
|
1817
|
+
try std.testing.expectEqual(@as(ObjectId, 1), layout.focusTargetById(1).?.id);
|
|
1818
|
+
|
|
1819
|
+
try std.testing.expectEqual(WidgetRole.listitem, semantics[1].role);
|
|
1820
|
+
try std.testing.expectEqual(@as(ObjectId, 2), semantics[1].id);
|
|
1821
|
+
try std.testing.expect(semantics[1].list.present);
|
|
1822
|
+
try std.testing.expectEqual(@as(u32, 0), semantics[1].list.item_index);
|
|
1823
|
+
try std.testing.expectEqual(@as(u32, 10), semantics[1].list.item_count);
|
|
1824
|
+
|
|
1825
|
+
try std.testing.expectEqual(WidgetRole.listitem, semantics[3].role);
|
|
1826
|
+
try std.testing.expectEqual(@as(ObjectId, 4), semantics[3].id);
|
|
1827
|
+
try std.testing.expect(semantics[3].list.present);
|
|
1828
|
+
try std.testing.expectEqual(@as(u32, 2), semantics[3].list.item_index);
|
|
1829
|
+
try std.testing.expectEqual(@as(u32, 10), semantics[3].list.item_count);
|
|
1830
|
+
|
|
1831
|
+
try std.testing.expectEqual(WidgetRole.listitem, semantics[5].role);
|
|
1832
|
+
try std.testing.expectEqual(@as(ObjectId, 6), semantics[5].id);
|
|
1833
|
+
try std.testing.expect(semantics[5].list.present);
|
|
1834
|
+
try std.testing.expectEqual(@as(u32, 4), semantics[5].list.item_index);
|
|
1835
|
+
try std.testing.expectEqual(@as(u32, 10), semantics[5].list.item_count);
|
|
1836
|
+
}
|
|
1837
|
+
|
|
1838
|
+
test "widget virtualized list preserves component child roles and item metrics" {
|
|
1839
|
+
const children = [_]Widget{
|
|
1840
|
+
.{ .id = 2, .kind = .button, .frame = geometry.RectF.init(0, 0, 0, 20), .text = "Button" },
|
|
1841
|
+
.{ .id = 3, .kind = .checkbox, .frame = geometry.RectF.init(0, 0, 0, 20), .text = "Checkbox" },
|
|
1842
|
+
.{ .id = 4, .kind = .alert, .frame = geometry.RectF.init(0, 0, 0, 20), .text = "Alert" },
|
|
1843
|
+
.{ .id = 5, .kind = .badge, .frame = geometry.RectF.init(0, 0, 0, 20), .text = "Badge" },
|
|
1844
|
+
};
|
|
1845
|
+
const list = Widget{
|
|
1846
|
+
.id = 1,
|
|
1847
|
+
.kind = .list,
|
|
1848
|
+
.layout = .{
|
|
1849
|
+
.virtualized = true,
|
|
1850
|
+
.virtual_item_extent = 20,
|
|
1851
|
+
},
|
|
1852
|
+
.children = &children,
|
|
1853
|
+
};
|
|
1854
|
+
|
|
1855
|
+
var nodes: [5]WidgetLayoutNode = undefined;
|
|
1856
|
+
const layout = try layoutWidgetTree(list, geometry.RectF.init(0, 0, 120, 60), &nodes);
|
|
1857
|
+
var semantics_buffer: [5]WidgetSemanticsNode = undefined;
|
|
1858
|
+
const semantics = try layout.collectSemantics(&semantics_buffer);
|
|
1859
|
+
|
|
1860
|
+
try std.testing.expectEqual(@as(usize, 4), semantics.len);
|
|
1861
|
+
try std.testing.expectEqual(WidgetRole.list, semantics[0].role);
|
|
1862
|
+
try std.testing.expectEqual(WidgetRole.button, semantics[1].role);
|
|
1863
|
+
try std.testing.expect(semantics[1].list.present);
|
|
1864
|
+
try std.testing.expectEqual(@as(u32, 0), semantics[1].list.item_index);
|
|
1865
|
+
try std.testing.expectEqual(@as(u32, 4), semantics[1].list.item_count);
|
|
1866
|
+
try std.testing.expectEqual(WidgetRole.checkbox, semantics[2].role);
|
|
1867
|
+
try std.testing.expect(semantics[2].list.present);
|
|
1868
|
+
try std.testing.expectEqual(@as(u32, 1), semantics[2].list.item_index);
|
|
1869
|
+
try std.testing.expectEqual(WidgetRole.group, semantics[3].role);
|
|
1870
|
+
try std.testing.expect(semantics[3].list.present);
|
|
1871
|
+
try std.testing.expectEqual(@as(u32, 2), semantics[3].list.item_index);
|
|
1872
|
+
}
|
|
1873
|
+
|
|
1874
|
+
test "widget pointer route includes capture target and bubble phases" {
|
|
1875
|
+
const row_children = [_]Widget{.{
|
|
1876
|
+
.id = 2,
|
|
1877
|
+
.kind = .button,
|
|
1878
|
+
.frame = geometry.RectF.init(0, 0, 80, 32),
|
|
1879
|
+
.text = "Run",
|
|
1880
|
+
}};
|
|
1881
|
+
const root_children = [_]Widget{.{
|
|
1882
|
+
.id = 5,
|
|
1883
|
+
.kind = .row,
|
|
1884
|
+
.frame = geometry.RectF.init(8, 8, 120, 40),
|
|
1885
|
+
.children = &row_children,
|
|
1886
|
+
}};
|
|
1887
|
+
const root = Widget{
|
|
1888
|
+
.id = 1,
|
|
1889
|
+
.kind = .panel,
|
|
1890
|
+
.children = &root_children,
|
|
1891
|
+
};
|
|
1892
|
+
|
|
1893
|
+
var nodes: [4]WidgetLayoutNode = undefined;
|
|
1894
|
+
const layout = try layoutWidgetTree(root, geometry.RectF.init(0, 0, 160, 80), &nodes);
|
|
1895
|
+
var route_entries: [5]WidgetEventRouteEntry = undefined;
|
|
1896
|
+
const route = try layout.routePointerEvent(.{
|
|
1897
|
+
.phase = .down,
|
|
1898
|
+
.point = geometry.PointF.init(20, 20),
|
|
1899
|
+
}, &route_entries);
|
|
1900
|
+
|
|
1901
|
+
try std.testing.expect(route.target != null);
|
|
1902
|
+
try std.testing.expectEqual(@as(ObjectId, 2), route.target.?.id);
|
|
1903
|
+
try std.testing.expectEqual(@as(usize, 5), route.entries.len);
|
|
1904
|
+
try expectRouteEntry(route.entries[0], .capture, 1);
|
|
1905
|
+
try expectRouteEntry(route.entries[1], .capture, 5);
|
|
1906
|
+
try expectRouteEntry(route.entries[2], .target, 2);
|
|
1907
|
+
try expectRouteEntry(route.entries[3], .bubble, 5);
|
|
1908
|
+
try expectRouteEntry(route.entries[4], .bubble, 1);
|
|
1909
|
+
}
|
|
1910
|
+
|
|
1911
|
+
test "widget pointer route honors captured target for drag lifecycle" {
|
|
1912
|
+
const row_children = [_]Widget{.{
|
|
1913
|
+
.id = 2,
|
|
1914
|
+
.kind = .button,
|
|
1915
|
+
.frame = geometry.RectF.init(0, 0, 80, 32),
|
|
1916
|
+
.text = "Run",
|
|
1917
|
+
}};
|
|
1918
|
+
const root_children = [_]Widget{.{
|
|
1919
|
+
.id = 5,
|
|
1920
|
+
.kind = .row,
|
|
1921
|
+
.frame = geometry.RectF.init(8, 8, 120, 40),
|
|
1922
|
+
.children = &row_children,
|
|
1923
|
+
}};
|
|
1924
|
+
const root = Widget{
|
|
1925
|
+
.id = 1,
|
|
1926
|
+
.kind = .panel,
|
|
1927
|
+
.children = &root_children,
|
|
1928
|
+
};
|
|
1929
|
+
|
|
1930
|
+
var nodes: [4]WidgetLayoutNode = undefined;
|
|
1931
|
+
const layout = try layoutWidgetTree(root, geometry.RectF.init(0, 0, 160, 80), &nodes);
|
|
1932
|
+
|
|
1933
|
+
var move_entries: [5]WidgetEventRouteEntry = undefined;
|
|
1934
|
+
const move_route = try layout.routePointerEvent(.{
|
|
1935
|
+
.phase = .move,
|
|
1936
|
+
.point = geometry.PointF.init(220, 120),
|
|
1937
|
+
.captured_id = 2,
|
|
1938
|
+
}, &move_entries);
|
|
1939
|
+
try std.testing.expect(move_route.target != null);
|
|
1940
|
+
try std.testing.expectEqual(@as(ObjectId, 2), move_route.target.?.id);
|
|
1941
|
+
try std.testing.expectEqual(@as(usize, 5), move_route.entries.len);
|
|
1942
|
+
try expectRouteEntry(move_route.entries[0], .capture, 1);
|
|
1943
|
+
try expectRouteEntry(move_route.entries[1], .capture, 5);
|
|
1944
|
+
try expectRouteEntry(move_route.entries[2], .target, 2);
|
|
1945
|
+
try expectRouteEntry(move_route.entries[3], .bubble, 5);
|
|
1946
|
+
try expectRouteEntry(move_route.entries[4], .bubble, 1);
|
|
1947
|
+
|
|
1948
|
+
var up_entries: [5]WidgetEventRouteEntry = undefined;
|
|
1949
|
+
const up_route = try layout.routePointerEvent(.{
|
|
1950
|
+
.phase = .up,
|
|
1951
|
+
.point = geometry.PointF.init(220, 120),
|
|
1952
|
+
.captured_id = 2,
|
|
1953
|
+
}, &up_entries);
|
|
1954
|
+
try std.testing.expectEqual(@as(ObjectId, 2), up_route.target.?.id);
|
|
1955
|
+
|
|
1956
|
+
var cancel_entries: [5]WidgetEventRouteEntry = undefined;
|
|
1957
|
+
const cancel_route = try layout.routePointerEvent(.{
|
|
1958
|
+
.phase = .cancel,
|
|
1959
|
+
.point = geometry.PointF.init(220, 120),
|
|
1960
|
+
.captured_id = 2,
|
|
1961
|
+
}, &cancel_entries);
|
|
1962
|
+
try std.testing.expectEqual(@as(ObjectId, 2), cancel_route.target.?.id);
|
|
1963
|
+
}
|
|
1964
|
+
|
|
1965
|
+
test "widget pointer route skips scroll clipped captured targets" {
|
|
1966
|
+
const children = [_]Widget{
|
|
1967
|
+
.{ .id = 2, .kind = .button, .frame = geometry.RectF.init(0, 0, 0, 32), .text = "Hidden" },
|
|
1968
|
+
.{ .id = 3, .kind = .button, .frame = geometry.RectF.init(0, 48, 0, 32), .text = "Visible" },
|
|
1969
|
+
};
|
|
1970
|
+
const scroll = Widget{
|
|
1971
|
+
.id = 1,
|
|
1972
|
+
.kind = .scroll_view,
|
|
1973
|
+
.value = 40,
|
|
1974
|
+
.children = &children,
|
|
1975
|
+
};
|
|
1976
|
+
|
|
1977
|
+
var nodes: [3]WidgetLayoutNode = undefined;
|
|
1978
|
+
const layout = try layoutWidgetTree(scroll, geometry.RectF.init(0, 0, 120, 48), &nodes);
|
|
1979
|
+
try expectLayoutFrame(layout, 2, geometry.RectF.init(0, -40, 120, 32));
|
|
1980
|
+
try expectLayoutFrame(layout, 3, geometry.RectF.init(0, 8, 120, 32));
|
|
1981
|
+
|
|
1982
|
+
var hidden_entries: [0]WidgetEventRouteEntry = .{};
|
|
1983
|
+
const hidden_route = try layout.routePointerEvent(.{
|
|
1984
|
+
.phase = .move,
|
|
1985
|
+
.point = geometry.PointF.init(10, 20),
|
|
1986
|
+
.captured_id = 2,
|
|
1987
|
+
}, &hidden_entries);
|
|
1988
|
+
try std.testing.expect(hidden_route.target == null);
|
|
1989
|
+
try std.testing.expectEqual(@as(usize, 0), hidden_route.entries.len);
|
|
1990
|
+
|
|
1991
|
+
var visible_entries: [3]WidgetEventRouteEntry = undefined;
|
|
1992
|
+
const visible_route = try layout.routePointerEvent(.{
|
|
1993
|
+
.phase = .move,
|
|
1994
|
+
.point = geometry.PointF.init(180, 80),
|
|
1995
|
+
.captured_id = 3,
|
|
1996
|
+
}, &visible_entries);
|
|
1997
|
+
try std.testing.expect(visible_route.target != null);
|
|
1998
|
+
try std.testing.expectEqual(@as(ObjectId, 3), visible_route.target.?.id);
|
|
1999
|
+
try std.testing.expectEqual(@as(usize, 3), visible_route.entries.len);
|
|
2000
|
+
try expectRouteEntry(visible_route.entries[0], .capture, 1);
|
|
2001
|
+
try expectRouteEntry(visible_route.entries[1], .target, 3);
|
|
2002
|
+
try expectRouteEntry(visible_route.entries[2], .bubble, 1);
|
|
2003
|
+
}
|
|
2004
|
+
|
|
2005
|
+
test "widget pointer capture does not retarget hover down or wheel" {
|
|
2006
|
+
const root = Widget{
|
|
2007
|
+
.id = 1,
|
|
2008
|
+
.kind = .panel,
|
|
2009
|
+
.children = &.{.{
|
|
2010
|
+
.id = 2,
|
|
2011
|
+
.kind = .button,
|
|
2012
|
+
.frame = geometry.RectF.init(10, 10, 80, 32),
|
|
2013
|
+
.text = "Run",
|
|
2014
|
+
}},
|
|
2015
|
+
};
|
|
2016
|
+
|
|
2017
|
+
var nodes: [3]WidgetLayoutNode = undefined;
|
|
2018
|
+
const layout = try layoutWidgetTree(root, geometry.RectF.init(0, 0, 120, 80), &nodes);
|
|
2019
|
+
var empty_entries: [0]WidgetEventRouteEntry = .{};
|
|
2020
|
+
|
|
2021
|
+
const hover_route = try layout.routePointerEvent(.{
|
|
2022
|
+
.phase = .hover,
|
|
2023
|
+
.point = geometry.PointF.init(200, 20),
|
|
2024
|
+
.captured_id = 2,
|
|
2025
|
+
}, &empty_entries);
|
|
2026
|
+
try std.testing.expect(hover_route.target == null);
|
|
2027
|
+
try std.testing.expectEqual(@as(usize, 0), hover_route.entries.len);
|
|
2028
|
+
|
|
2029
|
+
const down_route = try layout.routePointerEvent(.{
|
|
2030
|
+
.phase = .down,
|
|
2031
|
+
.point = geometry.PointF.init(200, 20),
|
|
2032
|
+
.captured_id = 2,
|
|
2033
|
+
}, &empty_entries);
|
|
2034
|
+
try std.testing.expect(down_route.target == null);
|
|
2035
|
+
try std.testing.expectEqual(@as(usize, 0), down_route.entries.len);
|
|
2036
|
+
|
|
2037
|
+
const wheel_route = try layout.routePointerEvent(.{
|
|
2038
|
+
.phase = .wheel,
|
|
2039
|
+
.point = geometry.PointF.init(200, 20),
|
|
2040
|
+
.delta = geometry.OffsetF.init(0, -16),
|
|
2041
|
+
.captured_id = 2,
|
|
2042
|
+
}, &empty_entries);
|
|
2043
|
+
try std.testing.expect(wheel_route.target == null);
|
|
2044
|
+
try std.testing.expectEqual(@as(usize, 0), wheel_route.entries.len);
|
|
2045
|
+
}
|
|
2046
|
+
|
|
2047
|
+
test "widget pointer route handles no hit and bounded output" {
|
|
2048
|
+
const root = Widget{
|
|
2049
|
+
.id = 1,
|
|
2050
|
+
.kind = .panel,
|
|
2051
|
+
.children = &.{.{
|
|
2052
|
+
.id = 2,
|
|
2053
|
+
.kind = .button,
|
|
2054
|
+
.frame = geometry.RectF.init(10, 10, 80, 32),
|
|
2055
|
+
.text = "Run",
|
|
2056
|
+
}},
|
|
2057
|
+
};
|
|
2058
|
+
|
|
2059
|
+
var nodes: [3]WidgetLayoutNode = undefined;
|
|
2060
|
+
const layout = try layoutWidgetTree(root, geometry.RectF.init(0, 0, 120, 80), &nodes);
|
|
2061
|
+
var empty_entries: [0]WidgetEventRouteEntry = .{};
|
|
2062
|
+
const no_hit = try layout.routePointerEvent(.{
|
|
2063
|
+
.phase = .down,
|
|
2064
|
+
.point = geometry.PointF.init(200, 20),
|
|
2065
|
+
}, &empty_entries);
|
|
2066
|
+
try std.testing.expect(no_hit.target == null);
|
|
2067
|
+
try std.testing.expectEqual(@as(usize, 0), no_hit.entries.len);
|
|
2068
|
+
|
|
2069
|
+
var small_entries: [1]WidgetEventRouteEntry = undefined;
|
|
2070
|
+
try std.testing.expectError(error.WidgetEventRouteListFull, layout.routePointerEvent(.{
|
|
2071
|
+
.phase = .down,
|
|
2072
|
+
.point = geometry.PointF.init(20, 20),
|
|
2073
|
+
}, &small_entries));
|
|
2074
|
+
}
|
|
2075
|
+
|
|
2076
|
+
test "widget file drop route targets explicit drop semantics" {
|
|
2077
|
+
const row_children = [_]Widget{.{
|
|
2078
|
+
.id = 3,
|
|
2079
|
+
.kind = .button,
|
|
2080
|
+
.frame = geometry.RectF.init(0, 0, 80, 32),
|
|
2081
|
+
.text = "Upload",
|
|
2082
|
+
}};
|
|
2083
|
+
const root_children = [_]Widget{.{
|
|
2084
|
+
.id = 2,
|
|
2085
|
+
.kind = .row,
|
|
2086
|
+
.frame = geometry.RectF.init(8, 8, 120, 44),
|
|
2087
|
+
.semantics = .{ .actions = .{ .drop_files = true } },
|
|
2088
|
+
.children = &row_children,
|
|
2089
|
+
}};
|
|
2090
|
+
const root = Widget{
|
|
2091
|
+
.id = 1,
|
|
2092
|
+
.kind = .panel,
|
|
2093
|
+
.children = &root_children,
|
|
2094
|
+
};
|
|
2095
|
+
|
|
2096
|
+
var nodes: [4]WidgetLayoutNode = undefined;
|
|
2097
|
+
const layout = try layoutWidgetTree(root, geometry.RectF.init(0, 0, 160, 80), &nodes);
|
|
2098
|
+
const paths = [_][]const u8{"/tmp/image.png"};
|
|
2099
|
+
var route_entries: [3]WidgetEventRouteEntry = undefined;
|
|
2100
|
+
const route = try layout.routeFileDropEvent(.{
|
|
2101
|
+
.point = geometry.PointF.init(20, 20),
|
|
2102
|
+
.paths = &paths,
|
|
2103
|
+
}, &route_entries);
|
|
2104
|
+
|
|
2105
|
+
try std.testing.expect(route.target != null);
|
|
2106
|
+
try std.testing.expectEqual(@as(ObjectId, 2), route.target.?.id);
|
|
2107
|
+
try std.testing.expectEqual(WidgetKind.row, route.target.?.kind);
|
|
2108
|
+
try std.testing.expectEqual(@as(usize, 3), route.entries.len);
|
|
2109
|
+
try expectRouteEntry(route.entries[0], .capture, 1);
|
|
2110
|
+
try expectRouteEntry(route.entries[1], .target, 2);
|
|
2111
|
+
try expectRouteEntry(route.entries[2], .bubble, 1);
|
|
2112
|
+
|
|
2113
|
+
var semantics_buffer: [4]WidgetSemanticsNode = undefined;
|
|
2114
|
+
const semantics = try layout.collectSemantics(&semantics_buffer);
|
|
2115
|
+
for (semantics) |semantic| {
|
|
2116
|
+
if (semantic.id == 2) {
|
|
2117
|
+
try std.testing.expect(semantic.actions.drop_files);
|
|
2118
|
+
return;
|
|
2119
|
+
}
|
|
2120
|
+
}
|
|
2121
|
+
return error.TestUnexpectedResult;
|
|
2122
|
+
}
|
|
2123
|
+
|
|
2124
|
+
test "widget file drop route ignores missing paths disabled and non-drop targets" {
|
|
2125
|
+
const root = Widget{
|
|
2126
|
+
.id = 1,
|
|
2127
|
+
.kind = .panel,
|
|
2128
|
+
.children = &.{
|
|
2129
|
+
.{
|
|
2130
|
+
.id = 2,
|
|
2131
|
+
.kind = .panel,
|
|
2132
|
+
.frame = geometry.RectF.init(8, 8, 80, 44),
|
|
2133
|
+
.semantics = .{ .actions = .{ .drop_files = true } },
|
|
2134
|
+
.state = .{ .disabled = true },
|
|
2135
|
+
},
|
|
2136
|
+
.{
|
|
2137
|
+
.id = 3,
|
|
2138
|
+
.kind = .button,
|
|
2139
|
+
.frame = geometry.RectF.init(96, 8, 80, 44),
|
|
2140
|
+
.text = "Plain",
|
|
2141
|
+
},
|
|
2142
|
+
},
|
|
2143
|
+
};
|
|
2144
|
+
|
|
2145
|
+
var nodes: [4]WidgetLayoutNode = undefined;
|
|
2146
|
+
const layout = try layoutWidgetTree(root, geometry.RectF.init(0, 0, 200, 80), &nodes);
|
|
2147
|
+
const paths = [_][]const u8{"/tmp/report.csv"};
|
|
2148
|
+
var empty_entries: [0]WidgetEventRouteEntry = .{};
|
|
2149
|
+
|
|
2150
|
+
const no_paths = try layout.routeFileDropEvent(.{
|
|
2151
|
+
.point = geometry.PointF.init(20, 20),
|
|
2152
|
+
}, &empty_entries);
|
|
2153
|
+
try std.testing.expect(no_paths.target == null);
|
|
2154
|
+
try std.testing.expectEqual(@as(usize, 0), no_paths.entries.len);
|
|
2155
|
+
|
|
2156
|
+
const disabled = try layout.routeFileDropEvent(.{
|
|
2157
|
+
.point = geometry.PointF.init(20, 20),
|
|
2158
|
+
.paths = &paths,
|
|
2159
|
+
}, &empty_entries);
|
|
2160
|
+
try std.testing.expect(disabled.target == null);
|
|
2161
|
+
try std.testing.expectEqual(@as(usize, 0), disabled.entries.len);
|
|
2162
|
+
|
|
2163
|
+
const plain = try layout.routeFileDropEvent(.{
|
|
2164
|
+
.point = geometry.PointF.init(110, 20),
|
|
2165
|
+
.paths = &paths,
|
|
2166
|
+
}, &empty_entries);
|
|
2167
|
+
try std.testing.expect(plain.target == null);
|
|
2168
|
+
try std.testing.expectEqual(@as(usize, 0), plain.entries.len);
|
|
2169
|
+
}
|
|
2170
|
+
|
|
2171
|
+
test "widget drag route targets explicit drag source semantics" {
|
|
2172
|
+
const row_children = [_]Widget{.{
|
|
2173
|
+
.id = 3,
|
|
2174
|
+
.kind = .button,
|
|
2175
|
+
.frame = geometry.RectF.init(0, 0, 80, 32),
|
|
2176
|
+
.text = "Move",
|
|
2177
|
+
}};
|
|
2178
|
+
const root_children = [_]Widget{.{
|
|
2179
|
+
.id = 2,
|
|
2180
|
+
.kind = .row,
|
|
2181
|
+
.frame = geometry.RectF.init(8, 8, 120, 44),
|
|
2182
|
+
.semantics = .{ .actions = .{ .drag = true } },
|
|
2183
|
+
.children = &row_children,
|
|
2184
|
+
}};
|
|
2185
|
+
const root = Widget{
|
|
2186
|
+
.id = 1,
|
|
2187
|
+
.kind = .panel,
|
|
2188
|
+
.children = &root_children,
|
|
2189
|
+
};
|
|
2190
|
+
|
|
2191
|
+
var nodes: [4]WidgetLayoutNode = undefined;
|
|
2192
|
+
const layout = try layoutWidgetTree(root, geometry.RectF.init(0, 0, 160, 80), &nodes);
|
|
2193
|
+
var route_entries: [3]WidgetEventRouteEntry = undefined;
|
|
2194
|
+
const route = try layout.routeDragEvent(.{
|
|
2195
|
+
.source_id = 2,
|
|
2196
|
+
.point = geometry.PointF.init(60, 40),
|
|
2197
|
+
.delta = geometry.OffsetF.init(20, 4),
|
|
2198
|
+
}, &route_entries);
|
|
2199
|
+
|
|
2200
|
+
try std.testing.expect(route.target != null);
|
|
2201
|
+
try std.testing.expectEqual(@as(ObjectId, 2), route.target.?.id);
|
|
2202
|
+
try std.testing.expectEqual(WidgetKind.row, route.target.?.kind);
|
|
2203
|
+
try std.testing.expectEqual(@as(usize, 3), route.entries.len);
|
|
2204
|
+
try expectRouteEntry(route.entries[0], .capture, 1);
|
|
2205
|
+
try expectRouteEntry(route.entries[1], .target, 2);
|
|
2206
|
+
try expectRouteEntry(route.entries[2], .bubble, 1);
|
|
2207
|
+
|
|
2208
|
+
var semantics_buffer: [4]WidgetSemanticsNode = undefined;
|
|
2209
|
+
const semantics = try layout.collectSemantics(&semantics_buffer);
|
|
2210
|
+
for (semantics) |semantic| {
|
|
2211
|
+
if (semantic.id == 2) {
|
|
2212
|
+
try std.testing.expect(semantic.actions.drag);
|
|
2213
|
+
return;
|
|
2214
|
+
}
|
|
2215
|
+
}
|
|
2216
|
+
return error.TestUnexpectedResult;
|
|
2217
|
+
}
|
|
2218
|
+
|
|
2219
|
+
test "widget drag route ignores missing disabled and non-drag sources" {
|
|
2220
|
+
const root = Widget{
|
|
2221
|
+
.id = 1,
|
|
2222
|
+
.kind = .panel,
|
|
2223
|
+
.children = &.{
|
|
2224
|
+
.{
|
|
2225
|
+
.id = 2,
|
|
2226
|
+
.kind = .panel,
|
|
2227
|
+
.frame = geometry.RectF.init(8, 8, 80, 44),
|
|
2228
|
+
.semantics = .{ .actions = .{ .drag = true } },
|
|
2229
|
+
.state = .{ .disabled = true },
|
|
2230
|
+
},
|
|
2231
|
+
.{
|
|
2232
|
+
.id = 3,
|
|
2233
|
+
.kind = .button,
|
|
2234
|
+
.frame = geometry.RectF.init(96, 8, 80, 44),
|
|
2235
|
+
.text = "Plain",
|
|
2236
|
+
},
|
|
2237
|
+
},
|
|
2238
|
+
};
|
|
2239
|
+
|
|
2240
|
+
var nodes: [4]WidgetLayoutNode = undefined;
|
|
2241
|
+
const layout = try layoutWidgetTree(root, geometry.RectF.init(0, 0, 200, 80), &nodes);
|
|
2242
|
+
var empty_entries: [0]WidgetEventRouteEntry = .{};
|
|
2243
|
+
|
|
2244
|
+
const no_source = try layout.routeDragEvent(.{
|
|
2245
|
+
.point = geometry.PointF.init(20, 20),
|
|
2246
|
+
}, &empty_entries);
|
|
2247
|
+
try std.testing.expect(no_source.target == null);
|
|
2248
|
+
try std.testing.expectEqual(@as(usize, 0), no_source.entries.len);
|
|
2249
|
+
|
|
2250
|
+
const disabled = try layout.routeDragEvent(.{
|
|
2251
|
+
.source_id = 2,
|
|
2252
|
+
.point = geometry.PointF.init(20, 20),
|
|
2253
|
+
}, &empty_entries);
|
|
2254
|
+
try std.testing.expect(disabled.target == null);
|
|
2255
|
+
try std.testing.expectEqual(@as(usize, 0), disabled.entries.len);
|
|
2256
|
+
|
|
2257
|
+
const plain = try layout.routeDragEvent(.{
|
|
2258
|
+
.source_id = 3,
|
|
2259
|
+
.point = geometry.PointF.init(110, 20),
|
|
2260
|
+
}, &empty_entries);
|
|
2261
|
+
try std.testing.expect(plain.target == null);
|
|
2262
|
+
try std.testing.expectEqual(@as(usize, 0), plain.entries.len);
|
|
2263
|
+
}
|
|
2264
|
+
|
|
2265
|
+
test "widget drag route skips scroll clipped sources" {
|
|
2266
|
+
const children = [_]Widget{
|
|
2267
|
+
.{ .id = 2, .kind = .button, .frame = geometry.RectF.init(0, 0, 0, 32), .text = "Hidden", .semantics = .{ .actions = .{ .drag = true } } },
|
|
2268
|
+
.{ .id = 3, .kind = .button, .frame = geometry.RectF.init(0, 48, 0, 32), .text = "Visible", .semantics = .{ .actions = .{ .drag = true } } },
|
|
2269
|
+
};
|
|
2270
|
+
const scroll = Widget{
|
|
2271
|
+
.id = 1,
|
|
2272
|
+
.kind = .scroll_view,
|
|
2273
|
+
.value = 40,
|
|
2274
|
+
.children = &children,
|
|
2275
|
+
};
|
|
2276
|
+
|
|
2277
|
+
var nodes: [3]WidgetLayoutNode = undefined;
|
|
2278
|
+
const layout = try layoutWidgetTree(scroll, geometry.RectF.init(0, 0, 120, 48), &nodes);
|
|
2279
|
+
try expectLayoutFrame(layout, 2, geometry.RectF.init(0, -40, 120, 32));
|
|
2280
|
+
try expectLayoutFrame(layout, 3, geometry.RectF.init(0, 8, 120, 32));
|
|
2281
|
+
|
|
2282
|
+
var hidden_entries: [0]WidgetEventRouteEntry = .{};
|
|
2283
|
+
const hidden = try layout.routeDragEvent(.{
|
|
2284
|
+
.source_id = 2,
|
|
2285
|
+
.point = geometry.PointF.init(180, 80),
|
|
2286
|
+
.delta = geometry.OffsetF.init(12, 0),
|
|
2287
|
+
}, &hidden_entries);
|
|
2288
|
+
try std.testing.expect(hidden.target == null);
|
|
2289
|
+
try std.testing.expectEqual(@as(usize, 0), hidden.entries.len);
|
|
2290
|
+
|
|
2291
|
+
var visible_entries: [3]WidgetEventRouteEntry = undefined;
|
|
2292
|
+
const visible = try layout.routeDragEvent(.{
|
|
2293
|
+
.source_id = 3,
|
|
2294
|
+
.point = geometry.PointF.init(180, 80),
|
|
2295
|
+
.delta = geometry.OffsetF.init(12, 0),
|
|
2296
|
+
}, &visible_entries);
|
|
2297
|
+
try std.testing.expect(visible.target != null);
|
|
2298
|
+
try std.testing.expectEqual(@as(ObjectId, 3), visible.target.?.id);
|
|
2299
|
+
try std.testing.expectEqual(@as(usize, 3), visible.entries.len);
|
|
2300
|
+
try expectRouteEntry(visible.entries[0], .capture, 1);
|
|
2301
|
+
try expectRouteEntry(visible.entries[1], .target, 3);
|
|
2302
|
+
try expectRouteEntry(visible.entries[2], .bubble, 1);
|
|
2303
|
+
}
|
|
2304
|
+
|
|
2305
|
+
test "widget keyboard route uses focused target and ancestors" {
|
|
2306
|
+
const row_children = [_]Widget{.{
|
|
2307
|
+
.id = 2,
|
|
2308
|
+
.kind = .text_field,
|
|
2309
|
+
.frame = geometry.RectF.init(0, 0, 120, 32),
|
|
2310
|
+
.text = "Find",
|
|
2311
|
+
}};
|
|
2312
|
+
const root_children = [_]Widget{.{
|
|
2313
|
+
.id = 5,
|
|
2314
|
+
.kind = .row,
|
|
2315
|
+
.frame = geometry.RectF.init(8, 8, 140, 40),
|
|
2316
|
+
.children = &row_children,
|
|
2317
|
+
}};
|
|
2318
|
+
const root = Widget{
|
|
2319
|
+
.id = 1,
|
|
2320
|
+
.kind = .panel,
|
|
2321
|
+
.children = &root_children,
|
|
2322
|
+
};
|
|
2323
|
+
|
|
2324
|
+
var nodes: [4]WidgetLayoutNode = undefined;
|
|
2325
|
+
const layout = try layoutWidgetTree(root, geometry.RectF.init(0, 0, 180, 80), &nodes);
|
|
2326
|
+
var route_entries: [5]WidgetEventRouteEntry = undefined;
|
|
2327
|
+
const route = try layout.routeKeyboardEvent(.{
|
|
2328
|
+
.phase = .key_down,
|
|
2329
|
+
.focused_id = 2,
|
|
2330
|
+
.key = "enter",
|
|
2331
|
+
}, &route_entries);
|
|
2332
|
+
|
|
2333
|
+
try std.testing.expect(route.target != null);
|
|
2334
|
+
try std.testing.expectEqual(@as(ObjectId, 2), route.target.?.id);
|
|
2335
|
+
try std.testing.expectEqual(WidgetKind.text_field, route.target.?.kind);
|
|
2336
|
+
try std.testing.expectEqual(@as(usize, 5), route.entries.len);
|
|
2337
|
+
try expectRouteEntry(route.entries[0], .capture, 1);
|
|
2338
|
+
try expectRouteEntry(route.entries[1], .capture, 5);
|
|
2339
|
+
try expectRouteEntry(route.entries[2], .target, 2);
|
|
2340
|
+
try expectRouteEntry(route.entries[3], .bubble, 5);
|
|
2341
|
+
try expectRouteEntry(route.entries[4], .bubble, 1);
|
|
2342
|
+
}
|
|
2343
|
+
|
|
2344
|
+
test "widget keyboard route handles missing focus non-focus targets and bounded output" {
|
|
2345
|
+
const children = [_]Widget{
|
|
2346
|
+
.{
|
|
2347
|
+
.id = 2,
|
|
2348
|
+
.kind = .text,
|
|
2349
|
+
.frame = geometry.RectF.init(8, 8, 100, 20),
|
|
2350
|
+
.text = "Title",
|
|
2351
|
+
},
|
|
2352
|
+
.{
|
|
2353
|
+
.id = 3,
|
|
2354
|
+
.kind = .button,
|
|
2355
|
+
.frame = geometry.RectF.init(8, 36, 100, 32),
|
|
2356
|
+
.text = "Disabled",
|
|
2357
|
+
.state = .{ .disabled = true },
|
|
2358
|
+
},
|
|
2359
|
+
.{
|
|
2360
|
+
.id = 4,
|
|
2361
|
+
.kind = .button,
|
|
2362
|
+
.frame = geometry.RectF.init(8, 76, 100, 32),
|
|
2363
|
+
.text = "Run",
|
|
2364
|
+
},
|
|
2365
|
+
};
|
|
2366
|
+
const root = Widget{ .id = 1, .kind = .panel, .children = &children };
|
|
2367
|
+
|
|
2368
|
+
var nodes: [5]WidgetLayoutNode = undefined;
|
|
2369
|
+
const layout = try layoutWidgetTree(root, geometry.RectF.init(0, 0, 140, 120), &nodes);
|
|
2370
|
+
|
|
2371
|
+
var empty_entries: [0]WidgetEventRouteEntry = .{};
|
|
2372
|
+
const no_focus = try layout.routeKeyboardEvent(.{ .phase = .key_down, .key = "enter" }, &empty_entries);
|
|
2373
|
+
try std.testing.expect(no_focus.target == null);
|
|
2374
|
+
try std.testing.expectEqual(@as(usize, 0), no_focus.entries.len);
|
|
2375
|
+
|
|
2376
|
+
const text_target = try layout.routeKeyboardEvent(.{ .phase = .key_down, .focused_id = 2, .key = "enter" }, &empty_entries);
|
|
2377
|
+
try std.testing.expect(text_target.target == null);
|
|
2378
|
+
try std.testing.expectEqual(@as(usize, 0), text_target.entries.len);
|
|
2379
|
+
|
|
2380
|
+
const disabled_target = try layout.routeKeyboardEvent(.{ .phase = .key_down, .focused_id = 3, .key = "enter" }, &empty_entries);
|
|
2381
|
+
try std.testing.expect(disabled_target.target == null);
|
|
2382
|
+
try std.testing.expectEqual(@as(usize, 0), disabled_target.entries.len);
|
|
2383
|
+
|
|
2384
|
+
var small_entries: [1]WidgetEventRouteEntry = undefined;
|
|
2385
|
+
try std.testing.expectError(error.WidgetEventRouteListFull, layout.routeKeyboardEvent(.{
|
|
2386
|
+
.phase = .key_down,
|
|
2387
|
+
.focused_id = 4,
|
|
2388
|
+
.key = "enter",
|
|
2389
|
+
}, &small_entries));
|
|
2390
|
+
}
|
|
2391
|
+
|
|
2392
|
+
test "widget focus traversal skips disabled nodes and wraps" {
|
|
2393
|
+
const children = [_]Widget{
|
|
2394
|
+
.{
|
|
2395
|
+
.id = 2,
|
|
2396
|
+
.kind = .text,
|
|
2397
|
+
.frame = geometry.RectF.init(0, 0, 100, 20),
|
|
2398
|
+
.text = "Search",
|
|
2399
|
+
.semantics = .{ .focusable = true },
|
|
2400
|
+
},
|
|
2401
|
+
.{
|
|
2402
|
+
.id = 3,
|
|
2403
|
+
.kind = .button,
|
|
2404
|
+
.frame = geometry.RectF.init(0, 28, 100, 32),
|
|
2405
|
+
.text = "Disabled",
|
|
2406
|
+
.state = .{ .disabled = true },
|
|
2407
|
+
},
|
|
2408
|
+
.{
|
|
2409
|
+
.id = 4,
|
|
2410
|
+
.kind = .button,
|
|
2411
|
+
.frame = geometry.RectF.init(0, 68, 100, 32),
|
|
2412
|
+
.text = "Apply",
|
|
2413
|
+
},
|
|
2414
|
+
};
|
|
2415
|
+
const root = Widget{ .kind = .stack, .children = &children };
|
|
2416
|
+
|
|
2417
|
+
var nodes: [4]WidgetLayoutNode = undefined;
|
|
2418
|
+
const layout = try layoutWidgetTree(root, geometry.RectF.init(0, 0, 140, 120), &nodes);
|
|
2419
|
+
try std.testing.expectEqual(@as(ObjectId, 2), layout.focusTarget(null, .forward).?.id);
|
|
2420
|
+
try std.testing.expectEqual(@as(ObjectId, 4), layout.focusTarget(2, .forward).?.id);
|
|
2421
|
+
try std.testing.expectEqual(@as(ObjectId, 2), layout.focusTarget(4, .forward).?.id);
|
|
2422
|
+
try std.testing.expectEqual(@as(ObjectId, 4), layout.focusTarget(2, .backward).?.id);
|
|
2423
|
+
try std.testing.expectEqual(@as(ObjectId, 4), layout.focusTarget(null, .backward).?.id);
|
|
2424
|
+
}
|
|
2425
|
+
|
|
2426
|
+
test "widget focus target lookup validates focusable ids" {
|
|
2427
|
+
const children = [_]Widget{
|
|
2428
|
+
.{
|
|
2429
|
+
.id = 2,
|
|
2430
|
+
.kind = .text,
|
|
2431
|
+
.frame = geometry.RectF.init(0, 0, 100, 20),
|
|
2432
|
+
.text = "Title",
|
|
2433
|
+
},
|
|
2434
|
+
.{
|
|
2435
|
+
.id = 3,
|
|
2436
|
+
.kind = .button,
|
|
2437
|
+
.frame = geometry.RectF.init(0, 28, 100, 32),
|
|
2438
|
+
.text = "Run",
|
|
2439
|
+
},
|
|
2440
|
+
.{
|
|
2441
|
+
.id = 4,
|
|
2442
|
+
.kind = .button,
|
|
2443
|
+
.frame = geometry.RectF.init(0, 68, 100, 32),
|
|
2444
|
+
.text = "Disabled",
|
|
2445
|
+
.state = .{ .disabled = true },
|
|
2446
|
+
},
|
|
2447
|
+
};
|
|
2448
|
+
const root = Widget{ .kind = .stack, .children = &children };
|
|
2449
|
+
|
|
2450
|
+
var nodes: [4]WidgetLayoutNode = undefined;
|
|
2451
|
+
const layout = try layoutWidgetTree(root, geometry.RectF.init(0, 0, 140, 120), &nodes);
|
|
2452
|
+
try std.testing.expect(layout.focusTargetById(2) == null);
|
|
2453
|
+
try std.testing.expect(layout.focusTargetById(4) == null);
|
|
2454
|
+
try std.testing.expect(layout.focusTargetById(99) == null);
|
|
2455
|
+
|
|
2456
|
+
const target = layout.focusTargetById(3).?;
|
|
2457
|
+
try std.testing.expectEqual(@as(ObjectId, 3), target.id);
|
|
2458
|
+
try std.testing.expectEqual(WidgetKind.button, target.kind);
|
|
2459
|
+
}
|
|
2460
|
+
|
|
2461
|
+
fn doubledTextMeasure(context: ?*anyopaque, font_id: FontId, size: f32, text: []const u8) f32 {
|
|
2462
|
+
_ = context;
|
|
2463
|
+
_ = font_id;
|
|
2464
|
+
return size * 2 * @as(f32, @floatFromInt(text.len));
|
|
2465
|
+
}
|
|
2466
|
+
|
|
2467
|
+
const doubled_text_measure = support.TextMeasureProvider{ .measure_fn = doubledTextMeasure };
|
|
2468
|
+
|
|
2469
|
+
test "intrinsic text sizing defaults to the estimator and honors an injected provider" {
|
|
2470
|
+
const widget = Widget{ .id = 1, .kind = .text, .text = "Refresh dashboard" };
|
|
2471
|
+
const default_tokens = DesignTokens{};
|
|
2472
|
+
const default_size = intrinsicWidgetSize(widget, default_tokens);
|
|
2473
|
+
try std.testing.expectEqual(
|
|
2474
|
+
estimateTextWidthForFont(default_tokens.typography.font_id, widget.text, default_tokens.typography.body_size),
|
|
2475
|
+
default_size.width,
|
|
2476
|
+
);
|
|
2477
|
+
|
|
2478
|
+
const measured_tokens = DesignTokens{ .text_measure = &doubled_text_measure };
|
|
2479
|
+
const measured_size = intrinsicWidgetSize(widget, measured_tokens);
|
|
2480
|
+
try std.testing.expectEqual(
|
|
2481
|
+
default_tokens.typography.body_size * 2 * @as(f32, @floatFromInt(widget.text.len)),
|
|
2482
|
+
measured_size.width,
|
|
2483
|
+
);
|
|
2484
|
+
try std.testing.expect(measured_size.width != default_size.width);
|
|
2485
|
+
try std.testing.expectEqual(default_size.height, measured_size.height);
|
|
2486
|
+
}
|
|
2487
|
+
|
|
2488
|
+
test "text size rungs resolve the typography tokens and retheme with overrides" {
|
|
2489
|
+
const tokens = DesignTokens{};
|
|
2490
|
+
const heading = Widget{ .id = 1, .kind = .text, .text = "Usage" };
|
|
2491
|
+
const heading_sized = Widget{ .id = 1, .kind = .text, .text = "Usage", .size = .heading };
|
|
2492
|
+
const display_sized = Widget{ .id = 2, .kind = .text, .text = "42.7%", .size = .display };
|
|
2493
|
+
|
|
2494
|
+
// The rungs REPLACE the body base with the named token: intrinsic
|
|
2495
|
+
// height is the rung's 1.25 line height, width the rung-sized
|
|
2496
|
+
// measurement.
|
|
2497
|
+
const heading_size = intrinsicWidgetSize(heading_sized, tokens);
|
|
2498
|
+
const display_size = intrinsicWidgetSize(display_sized, tokens);
|
|
2499
|
+
try std.testing.expectEqual(tokens.typography.heading_size * 1.25, heading_size.height);
|
|
2500
|
+
try std.testing.expectEqual(tokens.typography.display_size * 1.25, display_size.height);
|
|
2501
|
+
try std.testing.expect(heading_size.width > intrinsicWidgetSize(heading, tokens).width);
|
|
2502
|
+
|
|
2503
|
+
// Themable like every typography token: an override moves the rung.
|
|
2504
|
+
const themed = DesignTokens{ .typography = (TypographyTokenOverrides{ .display_size = 36 }).apply(.{}) };
|
|
2505
|
+
try std.testing.expectEqual(@as(f32, 36 * 1.25), intrinsicWidgetSize(display_sized, themed).height);
|
|
2506
|
+
|
|
2507
|
+
// Like body/title, the rungs do not density-scale (density scales
|
|
2508
|
+
// chrome, never glyph sizes).
|
|
2509
|
+
const compact = DesignTokens{ .density = .compact };
|
|
2510
|
+
try std.testing.expectEqual(display_size.height, intrinsicWidgetSize(display_sized, compact).height);
|
|
2511
|
+
|
|
2512
|
+
// On a control the rungs are inert: the button stays at its default
|
|
2513
|
+
// control step (markup rejects this shape; Zig views get a Debug
|
|
2514
|
+
// warning).
|
|
2515
|
+
const button = Widget{ .id = 3, .kind = .button, .text = "Run" };
|
|
2516
|
+
const button_display = Widget{ .id = 3, .kind = .button, .text = "Run", .size = .display };
|
|
2517
|
+
try std.testing.expectEqualDeep(intrinsicWidgetSize(button, tokens), intrinsicWidgetSize(button_display, tokens));
|
|
2518
|
+
}
|
|
2519
|
+
|
|
2520
|
+
test "widget tree layout widths follow the injected text measure provider" {
|
|
2521
|
+
const button = Widget{ .id = 2, .kind = .button, .text = "Run" };
|
|
2522
|
+
const row_children = [_]Widget{button};
|
|
2523
|
+
const row = Widget{ .id = 1, .kind = .row, .children = &row_children };
|
|
2524
|
+
|
|
2525
|
+
var default_nodes: [2]WidgetLayoutNode = undefined;
|
|
2526
|
+
const default_layout = try layoutWidgetTreeWithTokens(row, geometry.RectF.init(0, 0, 400, 64), .{}, &default_nodes);
|
|
2527
|
+
|
|
2528
|
+
var measured_nodes: [2]WidgetLayoutNode = undefined;
|
|
2529
|
+
const measured_tokens = DesignTokens{ .text_measure = &doubled_text_measure };
|
|
2530
|
+
const measured_layout = try layoutWidgetTreeWithTokens(row, geometry.RectF.init(0, 0, 400, 64), measured_tokens, &measured_nodes);
|
|
2531
|
+
|
|
2532
|
+
try std.testing.expect(measured_layout.findById(2).?.frame.width > default_layout.findById(2).?.frame.width);
|
|
2533
|
+
}
|
|
2534
|
+
|
|
2535
|
+
// ------------------------------------------------------ definite sizes
|
|
2536
|
+
|
|
2537
|
+
test "definite width caps intrinsic content so siblings keep their share" {
|
|
2538
|
+
// A sidebar repro shape: a non-growing 360px pane whose single-line text
|
|
2539
|
+
// is far wider than the pane. With width as a min-only floor the pane
|
|
2540
|
+
// ballooned to its intrinsic text width and starved the growing
|
|
2541
|
+
// sibling; a definite width (min AND max) keeps the pane at 360.
|
|
2542
|
+
const long_text = "A long single-line status message that lays out much wider than the pane it sits in, pushing siblings to zero";
|
|
2543
|
+
const pane_children = [_]Widget{
|
|
2544
|
+
.{ .id = 3, .kind = .text, .text = long_text },
|
|
2545
|
+
};
|
|
2546
|
+
const definite = geometry.SizeF.init(360, 0);
|
|
2547
|
+
const row_children = [_]Widget{
|
|
2548
|
+
.{
|
|
2549
|
+
.id = 2,
|
|
2550
|
+
.kind = .column,
|
|
2551
|
+
.layout = .{ .min_size = definite, .max_size = definite },
|
|
2552
|
+
.children = &pane_children,
|
|
2553
|
+
},
|
|
2554
|
+
.{ .id = 4, .kind = .column, .layout = .{ .grow = 1 } },
|
|
2555
|
+
};
|
|
2556
|
+
const root = Widget{ .id = 1, .kind = .row, .children = &row_children };
|
|
2557
|
+
|
|
2558
|
+
var nodes: [8]WidgetLayoutNode = undefined;
|
|
2559
|
+
const layout = try layoutWidgetTree(root, geometry.RectF.init(0, 0, 800, 200), &nodes);
|
|
2560
|
+
try expectLayoutFrame(layout, 2, geometry.RectF.init(0, 0, 360, 200));
|
|
2561
|
+
try expectLayoutFrame(layout, 4, geometry.RectF.init(360, 0, 440, 200));
|
|
2562
|
+
// The text child stretches to the pane's definite width, not past it.
|
|
2563
|
+
try std.testing.expectEqual(@as(f32, 360), layout.findById(3).?.frame.width);
|
|
2564
|
+
}
|
|
2565
|
+
|
|
2566
|
+
test "min-only width keeps the classic floor behavior" {
|
|
2567
|
+
// The min channel alone (no max) still lets intrinsic content widen
|
|
2568
|
+
// the box - the pre-definite behavior existing Zig callers of
|
|
2569
|
+
// `min_size` rely on.
|
|
2570
|
+
const long_text = "A long single-line status message that lays out much wider than the pane it sits in, pushing siblings to zero";
|
|
2571
|
+
const pane_children = [_]Widget{
|
|
2572
|
+
.{ .id = 3, .kind = .text, .text = long_text },
|
|
2573
|
+
};
|
|
2574
|
+
const row_children = [_]Widget{
|
|
2575
|
+
.{
|
|
2576
|
+
.id = 2,
|
|
2577
|
+
.kind = .column,
|
|
2578
|
+
.layout = .{ .min_size = geometry.SizeF.init(360, 0) },
|
|
2579
|
+
.children = &pane_children,
|
|
2580
|
+
},
|
|
2581
|
+
.{ .id = 4, .kind = .column, .layout = .{ .grow = 1 } },
|
|
2582
|
+
};
|
|
2583
|
+
const root = Widget{ .id = 1, .kind = .row, .children = &row_children };
|
|
2584
|
+
|
|
2585
|
+
var nodes: [8]WidgetLayoutNode = undefined;
|
|
2586
|
+
const layout = try layoutWidgetTree(root, geometry.RectF.init(0, 0, 800, 200), &nodes);
|
|
2587
|
+
try std.testing.expect(layout.findById(2).?.frame.width > 360);
|
|
2588
|
+
}
|
|
2589
|
+
|
|
2590
|
+
test "definite width caps grow distribution" {
|
|
2591
|
+
const definite = geometry.SizeF.init(200, 0);
|
|
2592
|
+
const row_children = [_]Widget{
|
|
2593
|
+
.{ .id = 2, .kind = .column, .layout = .{ .grow = 1, .min_size = definite, .max_size = definite } },
|
|
2594
|
+
.{ .id = 3, .kind = .column, .layout = .{ .grow = 1 } },
|
|
2595
|
+
};
|
|
2596
|
+
const root = Widget{ .id = 1, .kind = .row, .children = &row_children };
|
|
2597
|
+
|
|
2598
|
+
var nodes: [4]WidgetLayoutNode = undefined;
|
|
2599
|
+
const layout = try layoutWidgetTree(root, geometry.RectF.init(0, 0, 800, 100), &nodes);
|
|
2600
|
+
try expectLayoutFrame(layout, 2, geometry.RectF.init(0, 0, 200, 100));
|
|
2601
|
+
try expectLayoutFrame(layout, 3, geometry.RectF.init(200, 0, 400, 100));
|
|
2602
|
+
}
|
|
2603
|
+
|
|
2604
|
+
test "definite height caps cross-axis stretch in a row" {
|
|
2605
|
+
const definite = geometry.SizeF.init(0, 40);
|
|
2606
|
+
const row_children = [_]Widget{
|
|
2607
|
+
.{ .id = 2, .kind = .column, .layout = .{ .grow = 1, .min_size = definite, .max_size = definite } },
|
|
2608
|
+
};
|
|
2609
|
+
const root = Widget{ .id = 1, .kind = .row, .children = &row_children };
|
|
2610
|
+
|
|
2611
|
+
var nodes: [4]WidgetLayoutNode = undefined;
|
|
2612
|
+
const layout = try layoutWidgetTree(root, geometry.RectF.init(0, 0, 300, 200), &nodes);
|
|
2613
|
+
try expectLayoutFrame(layout, 2, geometry.RectF.init(0, 0, 300, 40));
|
|
2614
|
+
}
|
|
2615
|
+
|
|
2616
|
+
test "definite size caps stack children instead of stretching them" {
|
|
2617
|
+
const definite = geometry.SizeF.init(120, 60);
|
|
2618
|
+
const stack_children = [_]Widget{
|
|
2619
|
+
.{ .id = 2, .kind = .panel, .layout = .{ .min_size = definite, .max_size = definite } },
|
|
2620
|
+
};
|
|
2621
|
+
const root = Widget{ .id = 1, .kind = .stack, .children = &stack_children };
|
|
2622
|
+
|
|
2623
|
+
var nodes: [4]WidgetLayoutNode = undefined;
|
|
2624
|
+
const layout = try layoutWidgetTree(root, geometry.RectF.init(0, 0, 500, 400), &nodes);
|
|
2625
|
+
try expectLayoutFrame(layout, 2, geometry.RectF.init(0, 0, 120, 60));
|
|
2626
|
+
}
|
|
2627
|
+
|
|
2628
|
+
// ------------------------------------------------- separator orientation
|
|
2629
|
+
|
|
2630
|
+
test "separator in a row is a thin vertical divider" {
|
|
2631
|
+
// A two-pane repro shape: a divider between two growing panes. The
|
|
2632
|
+
// separator's h-rule default length no longer applies in the row
|
|
2633
|
+
// axis, so it takes its stroke width (hairline) and the panes split
|
|
2634
|
+
// the rest.
|
|
2635
|
+
const row_children = [_]Widget{
|
|
2636
|
+
.{ .id = 2, .kind = .column, .layout = .{ .grow = 1 } },
|
|
2637
|
+
.{ .id = 3, .kind = .separator },
|
|
2638
|
+
.{ .id = 4, .kind = .column, .layout = .{ .grow = 1 } },
|
|
2639
|
+
};
|
|
2640
|
+
const root = Widget{ .id = 1, .kind = .row, .children = &row_children };
|
|
2641
|
+
|
|
2642
|
+
var nodes: [8]WidgetLayoutNode = undefined;
|
|
2643
|
+
const layout = try layoutWidgetTree(root, geometry.RectF.init(0, 0, 401, 120), &nodes);
|
|
2644
|
+
try expectLayoutFrame(layout, 2, geometry.RectF.init(0, 0, 200, 120));
|
|
2645
|
+
try expectLayoutFrame(layout, 3, geometry.RectF.init(200, 0, 1, 120));
|
|
2646
|
+
try expectLayoutFrame(layout, 4, geometry.RectF.init(201, 0, 200, 120));
|
|
2647
|
+
}
|
|
2648
|
+
|
|
2649
|
+
test "separator in a column keeps the horizontal rule behavior" {
|
|
2650
|
+
const column_children = [_]Widget{
|
|
2651
|
+
.{ .id = 2, .kind = .text, .text = "Above" },
|
|
2652
|
+
.{ .id = 3, .kind = .separator },
|
|
2653
|
+
.{ .id = 4, .kind = .text, .text = "Below" },
|
|
2654
|
+
};
|
|
2655
|
+
const root = Widget{ .id = 1, .kind = .column, .children = &column_children };
|
|
2656
|
+
|
|
2657
|
+
var nodes: [8]WidgetLayoutNode = undefined;
|
|
2658
|
+
const layout = try layoutWidgetTree(root, geometry.RectF.init(0, 0, 240, 200), &nodes);
|
|
2659
|
+
const separator = layout.findById(3).?.frame;
|
|
2660
|
+
try std.testing.expectEqual(@as(f32, 240), separator.width);
|
|
2661
|
+
try std.testing.expectEqual(@as(f32, 1), separator.height);
|
|
2662
|
+
}
|
|
2663
|
+
|
|
2664
|
+
test "row intrinsic width counts a separator as its stroke width" {
|
|
2665
|
+
const inner_children = [_]Widget{
|
|
2666
|
+
.{ .id = 3, .kind = .stack, .frame = geometry.RectF.init(0, 0, 50, 20) },
|
|
2667
|
+
.{ .id = 4, .kind = .separator },
|
|
2668
|
+
.{ .id = 5, .kind = .stack, .frame = geometry.RectF.init(0, 0, 50, 20) },
|
|
2669
|
+
};
|
|
2670
|
+
const outer_children = [_]Widget{
|
|
2671
|
+
.{ .id = 2, .kind = .row, .children = &inner_children },
|
|
2672
|
+
.{ .id = 6, .kind = .column, .layout = .{ .grow = 1 } },
|
|
2673
|
+
};
|
|
2674
|
+
const root = Widget{ .id = 1, .kind = .row, .children = &outer_children };
|
|
2675
|
+
|
|
2676
|
+
var nodes: [8]WidgetLayoutNode = undefined;
|
|
2677
|
+
const layout = try layoutWidgetTree(root, geometry.RectF.init(0, 0, 800, 100), &nodes);
|
|
2678
|
+
// 50 + 1 + 50: the separator contributes its stroke width, not the
|
|
2679
|
+
// 160px horizontal-rule default.
|
|
2680
|
+
try std.testing.expectEqual(@as(f32, 101), layout.findById(2).?.frame.width);
|
|
2681
|
+
}
|
|
2682
|
+
|
|
2683
|
+
// ------------------------------------------------ overflow diagnostics
|
|
2684
|
+
|
|
2685
|
+
test "axis layout overflow is reported past the float-noise epsilon" {
|
|
2686
|
+
const widget_layout = @import("widget_layout.zig");
|
|
2687
|
+
try std.testing.expect(widget_layout.axisLayoutOverflow(400, 400) == null);
|
|
2688
|
+
try std.testing.expect(widget_layout.axisLayoutOverflow(400, 400.25) == null);
|
|
2689
|
+
const overflow = widget_layout.axisLayoutOverflow(400, 446) orelse return error.TestUnexpectedResult;
|
|
2690
|
+
try std.testing.expectEqual(@as(f32, 46), overflow);
|
|
2691
|
+
}
|