@native-sdk/cli 0.0.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +176 -0
- package/README.md +50 -1
- package/app.zon +30 -0
- package/assets/icon.icns +0 -0
- package/assets/icon.ico +0 -0
- package/assets/icon.png +0 -0
- package/assets/icon.svg +15 -0
- package/assets/native-sdk.entitlements +10 -0
- package/assets/native-sdk.manifest +12 -0
- package/bin/native.js +156 -0
- package/build/app.zig +716 -0
- package/build.zig +2593 -0
- package/build.zig.zon +24 -0
- package/native-sdk.d.ts +615 -0
- package/package.json +45 -8
- package/skill-data/automation/SKILL.md +248 -0
- package/skill-data/core/SKILL.md +249 -0
- package/skill-data/core/references/app-model-runtime.md +141 -0
- package/skill-data/core/references/bridge-security-native-capabilities.md +230 -0
- package/skill-data/core/references/frontend-assets.md +124 -0
- package/skill-data/core/references/project-anatomy.md +108 -0
- package/skill-data/core/references/web-engines-packaging-debugging.md +199 -0
- package/skill-data/native-ui/SKILL.md +1080 -0
- package/skills/native-sdk/SKILL.md +33 -0
- package/src/app_runner/root.zig +740 -0
- package/src/assets/root.zig +20 -0
- package/src/automation/protocol.zig +285 -0
- package/src/automation/root.zig +13 -0
- package/src/automation/server.zig +506 -0
- package/src/automation/snapshot.zig +1202 -0
- package/src/automation/watcher.zig +165 -0
- package/src/bridge/root.zig +507 -0
- package/src/debug/root.zig +246 -0
- package/src/embed/app_exports.zig +11 -0
- package/src/embed/c_api.zig +793 -0
- package/src/embed/c_exports.zig +10 -0
- package/src/embed/chrome.zig +168 -0
- package/src/embed/conversions.zig +359 -0
- package/src/embed/host.zig +960 -0
- package/src/embed/root.zig +81 -0
- package/src/embed/tests.zig +2552 -0
- package/src/embed/types.zig +382 -0
- package/src/embed/ui_host.zig +289 -0
- package/src/extensions/root.zig +197 -0
- package/src/frontend/root.zig +48 -0
- package/src/js/root.zig +65 -0
- package/src/platform/android/NativeSdkActivity.java +1370 -0
- package/src/platform/android/android_host.c +696 -0
- package/src/platform/android/files.zig +9 -0
- package/src/platform/android/native_sdk_app.h +237 -0
- package/src/platform/ios/files.zig +8 -0
- package/src/platform/ios/native_sdk_app.h +289 -0
- package/src/platform/ios/uikit_host.m +2739 -0
- package/src/platform/linux/cef_host.cpp +599 -0
- package/src/platform/linux/gtk_host.c +5362 -0
- package/src/platform/linux/gtk_host.h +265 -0
- package/src/platform/linux/root.zig +1519 -0
- package/src/platform/macos/appkit_host.h +604 -0
- package/src/platform/macos/appkit_host.m +10392 -0
- package/src/platform/macos/automation_host.h +14 -0
- package/src/platform/macos/automation_host.m +12 -0
- package/src/platform/macos/cef_host.mm +3028 -0
- package/src/platform/macos/root.zig +2260 -0
- package/src/platform/null_platform.zig +2232 -0
- package/src/platform/null_platform_tests.zig +670 -0
- package/src/platform/policy_values.zig +14 -0
- package/src/platform/root.zig +181 -0
- package/src/platform/types.zig +2681 -0
- package/src/platform/windows/cef_host.cpp +3 -0
- package/src/platform/windows/root.zig +1521 -0
- package/src/platform/windows/webview2_host.cpp +6230 -0
- package/src/primitives/app_dirs/root.zig +440 -0
- package/src/primitives/app_manifest/root.zig +109 -0
- package/src/primitives/app_manifest/tests.zig +758 -0
- package/src/primitives/app_manifest/types.zig +587 -0
- package/src/primitives/app_manifest/validation.zig +828 -0
- package/src/primitives/assets/root.zig +520 -0
- package/src/primitives/canvas/a11y_audit.zig +390 -0
- package/src/primitives/canvas/a11y_audit_tests.zig +225 -0
- package/src/primitives/canvas/app_icon.zig +1590 -0
- package/src/primitives/canvas/chart.zig +392 -0
- package/src/primitives/canvas/chart_tests.zig +751 -0
- package/src/primitives/canvas/commands.zig +446 -0
- package/src/primitives/canvas/drawing.zig +309 -0
- package/src/primitives/canvas/equality.zig +316 -0
- package/src/primitives/canvas/events.zig +696 -0
- package/src/primitives/canvas/font_coverage.zig +118 -0
- package/src/primitives/canvas/font_ttf.zig +510 -0
- package/src/primitives/canvas/font_ttf_tests.zig +280 -0
- package/src/primitives/canvas/fonts/Geist-Regular.ttf +0 -0
- package/src/primitives/canvas/fonts/GeistMono-Regular.ttf +0 -0
- package/src/primitives/canvas/frame.zig +679 -0
- package/src/primitives/canvas/frame_metrics.zig +462 -0
- package/src/primitives/canvas/gpu.zig +639 -0
- package/src/primitives/canvas/hash.zig +112 -0
- package/src/primitives/canvas/icons/alert.svg +1 -0
- package/src/primitives/canvas/icons/archive.svg +1 -0
- package/src/primitives/canvas/icons/arrow-down.svg +1 -0
- package/src/primitives/canvas/icons/arrow-right.svg +1 -0
- package/src/primitives/canvas/icons/arrow-up.svg +1 -0
- package/src/primitives/canvas/icons/check-circle.svg +1 -0
- package/src/primitives/canvas/icons/check.svg +1 -0
- package/src/primitives/canvas/icons/chevron-down.svg +1 -0
- package/src/primitives/canvas/icons/chevron-left.svg +1 -0
- package/src/primitives/canvas/icons/chevron-right.svg +1 -0
- package/src/primitives/canvas/icons/chevron-up.svg +1 -0
- package/src/primitives/canvas/icons/circle-dot.svg +1 -0
- package/src/primitives/canvas/icons/clock.svg +1 -0
- package/src/primitives/canvas/icons/copy.svg +1 -0
- package/src/primitives/canvas/icons/download.svg +1 -0
- package/src/primitives/canvas/icons/edit.svg +1 -0
- package/src/primitives/canvas/icons/ellipsis.svg +1 -0
- package/src/primitives/canvas/icons/external-link.svg +1 -0
- package/src/primitives/canvas/icons/eye.svg +1 -0
- package/src/primitives/canvas/icons/file-text.svg +1 -0
- package/src/primitives/canvas/icons/folder-open.svg +1 -0
- package/src/primitives/canvas/icons/folder.svg +1 -0
- package/src/primitives/canvas/icons/git-branch.svg +1 -0
- package/src/primitives/canvas/icons/git-merge.svg +1 -0
- package/src/primitives/canvas/icons/git-pull-request.svg +1 -0
- package/src/primitives/canvas/icons/info.svg +1 -0
- package/src/primitives/canvas/icons/menu.svg +1 -0
- package/src/primitives/canvas/icons/missing.svg +1 -0
- package/src/primitives/canvas/icons/moon.svg +1 -0
- package/src/primitives/canvas/icons/music.svg +1 -0
- package/src/primitives/canvas/icons/panel-left.svg +1 -0
- package/src/primitives/canvas/icons/panel-right.svg +1 -0
- package/src/primitives/canvas/icons/pause.svg +1 -0
- package/src/primitives/canvas/icons/play.svg +1 -0
- package/src/primitives/canvas/icons/plus.svg +1 -0
- package/src/primitives/canvas/icons/refresh-cw.svg +1 -0
- package/src/primitives/canvas/icons/repeat.svg +1 -0
- package/src/primitives/canvas/icons/save.svg +1 -0
- package/src/primitives/canvas/icons/search.svg +1 -0
- package/src/primitives/canvas/icons/send.svg +1 -0
- package/src/primitives/canvas/icons/settings.svg +1 -0
- package/src/primitives/canvas/icons/shuffle.svg +1 -0
- package/src/primitives/canvas/icons/skip-back.svg +1 -0
- package/src/primitives/canvas/icons/skip-forward.svg +1 -0
- package/src/primitives/canvas/icons/sun.svg +1 -0
- package/src/primitives/canvas/icons/terminal.svg +1 -0
- package/src/primitives/canvas/icons/trash.svg +1 -0
- package/src/primitives/canvas/icons/volume.svg +1 -0
- package/src/primitives/canvas/icons/wrench.svg +1 -0
- package/src/primitives/canvas/icons/x-circle.svg +1 -0
- package/src/primitives/canvas/icons/x.svg +1 -0
- package/src/primitives/canvas/icons.zig +249 -0
- package/src/primitives/canvas/layout_audit.zig +744 -0
- package/src/primitives/canvas/layout_audit_tests.zig +426 -0
- package/src/primitives/canvas/markdown.zig +1031 -0
- package/src/primitives/canvas/markdown_hostile_tests.zig +471 -0
- package/src/primitives/canvas/markdown_tests.zig +538 -0
- package/src/primitives/canvas/plan_key_index.zig +120 -0
- package/src/primitives/canvas/png.zig +355 -0
- package/src/primitives/canvas/reference.zig +1457 -0
- package/src/primitives/canvas/reference_blur.zig +104 -0
- package/src/primitives/canvas/reference_memo.zig +322 -0
- package/src/primitives/canvas/reference_paths.zig +184 -0
- package/src/primitives/canvas/reference_tests.zig +1650 -0
- package/src/primitives/canvas/render.zig +747 -0
- package/src/primitives/canvas/render_effects.zig +255 -0
- package/src/primitives/canvas/render_fingerprints.zig +256 -0
- package/src/primitives/canvas/render_generic_resources.zig +376 -0
- package/src/primitives/canvas/render_images.zig +247 -0
- package/src/primitives/canvas/render_layers.zig +260 -0
- package/src/primitives/canvas/render_paths.zig +347 -0
- package/src/primitives/canvas/render_resources.zig +51 -0
- package/src/primitives/canvas/render_tests.zig +3186 -0
- package/src/primitives/canvas/root.zig +744 -0
- package/src/primitives/canvas/serialization.zig +1528 -0
- package/src/primitives/canvas/svg_icon.zig +636 -0
- package/src/primitives/canvas/svg_icon_tests.zig +312 -0
- package/src/primitives/canvas/test_support.zig +422 -0
- package/src/primitives/canvas/testdata/markdown_document.md +83 -0
- package/src/primitives/canvas/tests.zig +30 -0
- package/src/primitives/canvas/text.zig +82 -0
- package/src/primitives/canvas/text_atlas.zig +408 -0
- package/src/primitives/canvas/text_batch_tests.zig +431 -0
- package/src/primitives/canvas/text_interaction.zig +615 -0
- package/src/primitives/canvas/text_layout.zig +1069 -0
- package/src/primitives/canvas/text_layout_cache.zig +281 -0
- package/src/primitives/canvas/text_layout_hash.zig +113 -0
- package/src/primitives/canvas/text_layout_types.zig +128 -0
- package/src/primitives/canvas/text_measure_cache.zig +279 -0
- package/src/primitives/canvas/text_metrics.zig +309 -0
- package/src/primitives/canvas/text_metrics_tests.zig +262 -0
- package/src/primitives/canvas/text_span_tests.zig +608 -0
- package/src/primitives/canvas/text_spans.zig +1010 -0
- package/src/primitives/canvas/text_tests.zig +1949 -0
- package/src/primitives/canvas/themes/geist.zig +470 -0
- package/src/primitives/canvas/tokens.zig +1522 -0
- package/src/primitives/canvas/ui.zig +2686 -0
- package/src/primitives/canvas/ui_markup.zig +3791 -0
- package/src/primitives/canvas/ui_markup_binary.zig +522 -0
- package/src/primitives/canvas/ui_markup_binary_tests.zig +591 -0
- package/src/primitives/canvas/ui_markup_compiled.zig +2565 -0
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +1669 -0
- package/src/primitives/canvas/ui_markup_contract.zig +1620 -0
- package/src/primitives/canvas/ui_markup_contract_tests.zig +953 -0
- package/src/primitives/canvas/ui_markup_edit.zig +416 -0
- package/src/primitives/canvas/ui_markup_edit_tests.zig +341 -0
- package/src/primitives/canvas/ui_markup_expr.zig +1152 -0
- package/src/primitives/canvas/ui_markup_expr_tests.zig +779 -0
- package/src/primitives/canvas/ui_markup_huge_model_tests.zig +505 -0
- package/src/primitives/canvas/ui_markup_reflect.zig +127 -0
- package/src/primitives/canvas/ui_markup_tests.zig +1545 -0
- package/src/primitives/canvas/ui_markup_view.zig +2352 -0
- package/src/primitives/canvas/ui_markup_view_tests.zig +3709 -0
- package/src/primitives/canvas/ui_provenance.zig +96 -0
- package/src/primitives/canvas/ui_provenance_tests.zig +186 -0
- package/src/primitives/canvas/ui_schema.zig +825 -0
- package/src/primitives/canvas/ui_schema_tests.zig +128 -0
- package/src/primitives/canvas/ui_tests.zig +1432 -0
- package/src/primitives/canvas/vector.zig +919 -0
- package/src/primitives/canvas/vector_tests.zig +547 -0
- package/src/primitives/canvas/virtual_extent_tests.zig +317 -0
- package/src/primitives/canvas/virtual_extents.zig +540 -0
- package/src/primitives/canvas/widget_access.zig +208 -0
- package/src/primitives/canvas/widget_anchored_tests.zig +264 -0
- package/src/primitives/canvas/widget_builtin_tests.zig +3160 -0
- package/src/primitives/canvas/widget_invalidation.zig +748 -0
- package/src/primitives/canvas/widget_layout.zig +2055 -0
- package/src/primitives/canvas/widget_layout_tests.zig +2691 -0
- package/src/primitives/canvas/widget_metrics.zig +228 -0
- package/src/primitives/canvas/widget_render.zig +2534 -0
- package/src/primitives/canvas/widget_render_controls.zig +1563 -0
- package/src/primitives/canvas/widget_render_scroll.zig +136 -0
- package/src/primitives/canvas/widget_render_style.zig +626 -0
- package/src/primitives/canvas/widget_render_surfaces.zig +794 -0
- package/src/primitives/canvas/widget_routing.zig +475 -0
- package/src/primitives/canvas/widget_runtime.zig +307 -0
- package/src/primitives/canvas/widget_runtime_tests.zig +3015 -0
- package/src/primitives/canvas/widget_semantics.zig +480 -0
- package/src/primitives/canvas/widget_semantics_tests.zig +2129 -0
- package/src/primitives/canvas/widget_tests.zig +8 -0
- package/src/primitives/canvas/widget_text_input.zig +351 -0
- package/src/primitives/canvas/widget_text_select.zig +147 -0
- package/src/primitives/canvas/widget_tree.zig +232 -0
- package/src/primitives/canvas/widgets.zig +1319 -0
- package/src/primitives/diagnostics/root.zig +445 -0
- package/src/primitives/geometry/root.zig +889 -0
- package/src/primitives/json/root.zig +272 -0
- package/src/primitives/platform_info/root.zig +450 -0
- package/src/primitives/trace/root.zig +569 -0
- package/src/root.zig +165 -0
- package/src/runtime/api.zig +431 -0
- package/src/runtime/async_bridge.zig +49 -0
- package/src/runtime/automation_commands.zig +686 -0
- package/src/runtime/automation_liveness_tests.zig +140 -0
- package/src/runtime/automation_snapshot.zig +246 -0
- package/src/runtime/automation_widget_dispatch.zig +617 -0
- package/src/runtime/bridge_dispatch_tests.zig +202 -0
- package/src/runtime/bridge_payload.zig +194 -0
- package/src/runtime/bridge_permission_tests.zig +551 -0
- package/src/runtime/bridge_responses.zig +414 -0
- package/src/runtime/builtin_bridge.zig +554 -0
- package/src/runtime/canvas_budget_edge_tests.zig +415 -0
- package/src/runtime/canvas_font_tests.zig +410 -0
- package/src/runtime/canvas_fonts.zig +229 -0
- package/src/runtime/canvas_frame.zig +1734 -0
- package/src/runtime/canvas_frame_animation_tests.zig +609 -0
- package/src/runtime/canvas_frame_cache_tests.zig +333 -0
- package/src/runtime/canvas_frame_helpers.zig +414 -0
- package/src/runtime/canvas_frame_invalidation_tests.zig +544 -0
- package/src/runtime/canvas_frame_packet_tests.zig +1353 -0
- package/src/runtime/canvas_frame_patch_tests.zig +1051 -0
- package/src/runtime/canvas_frame_retained_tests.zig +753 -0
- package/src/runtime/canvas_frame_tests.zig +9 -0
- package/src/runtime/canvas_frame_text_layout_budget_tests.zig +149 -0
- package/src/runtime/canvas_image_tests.zig +362 -0
- package/src/runtime/canvas_images.zig +224 -0
- package/src/runtime/canvas_limits.zig +317 -0
- package/src/runtime/canvas_screenshot_tests.zig +289 -0
- package/src/runtime/canvas_widget_accessibility_tests.zig +1494 -0
- package/src/runtime/canvas_widget_anchored_tests.zig +678 -0
- package/src/runtime/canvas_widget_chart_tests.zig +249 -0
- package/src/runtime/canvas_widget_clipboard_tests.zig +399 -0
- package/src/runtime/canvas_widget_context_menu.zig +318 -0
- package/src/runtime/canvas_widget_context_menu_tests.zig +462 -0
- package/src/runtime/canvas_widget_control_tests.zig +2164 -0
- package/src/runtime/canvas_widget_disclosure_tests.zig +440 -0
- package/src/runtime/canvas_widget_display.zig +677 -0
- package/src/runtime/canvas_widget_event_tests.zig +1779 -0
- package/src/runtime/canvas_widget_events.zig +1098 -0
- package/src/runtime/canvas_widget_floating_tests.zig +695 -0
- package/src/runtime/canvas_widget_layout_tests.zig +26 -0
- package/src/runtime/canvas_widget_runtime.zig +1335 -0
- package/src/runtime/canvas_widget_scroll_driver_tests.zig +582 -0
- package/src/runtime/canvas_widget_scroll_drivers.zig +202 -0
- package/src/runtime/canvas_widget_scroll_tests.zig +1549 -0
- package/src/runtime/canvas_widget_semantics_tests.zig +810 -0
- package/src/runtime/canvas_widget_split_tree_tests.zig +1031 -0
- package/src/runtime/canvas_widget_state.zig +798 -0
- package/src/runtime/canvas_widget_text_tests.zig +2104 -0
- package/src/runtime/canvas_widget_window_drag_tests.zig +284 -0
- package/src/runtime/clock.zig +231 -0
- package/src/runtime/core.zig +927 -0
- package/src/runtime/effects.zig +4197 -0
- package/src/runtime/effects_audio_tests.zig +690 -0
- package/src/runtime/effects_clipboard_tests.zig +317 -0
- package/src/runtime/effects_fetch_tests.zig +1031 -0
- package/src/runtime/effects_file_tests.zig +407 -0
- package/src/runtime/effects_tests.zig +1251 -0
- package/src/runtime/flow.zig +1175 -0
- package/src/runtime/frame_profile.zig +221 -0
- package/src/runtime/gpu_surface_events.zig +639 -0
- package/src/runtime/launch_timing.zig +59 -0
- package/src/runtime/markdown_app_tests.zig +224 -0
- package/src/runtime/native_command_event_tests.zig +431 -0
- package/src/runtime/platform_bridge_tests.zig +8 -0
- package/src/runtime/platform_config_tests.zig +392 -0
- package/src/runtime/root.zig +150 -0
- package/src/runtime/runtime_event_tests.zig +1079 -0
- package/src/runtime/session_journal.zig +1522 -0
- package/src/runtime/session_record.zig +332 -0
- package/src/runtime/session_replay.zig +274 -0
- package/src/runtime/session_state.zig +30 -0
- package/src/runtime/session_tests.zig +399 -0
- package/src/runtime/shell_layout.zig +472 -0
- package/src/runtime/shell_layout_tests.zig +1246 -0
- package/src/runtime/shell_view_tests.zig +604 -0
- package/src/runtime/state.zig +110 -0
- package/src/runtime/system_services.zig +392 -0
- package/src/runtime/test_support.zig +79 -0
- package/src/runtime/tests.zig +30 -0
- package/src/runtime/ui_app.zig +3290 -0
- package/src/runtime/ui_app_huge_model_tests.zig +351 -0
- package/src/runtime/ui_app_provenance.zig +370 -0
- package/src/runtime/ui_app_tests.zig +3254 -0
- package/src/runtime/ui_app_virtual_variable_tests.zig +485 -0
- package/src/runtime/ui_app_window_tests.zig +442 -0
- package/src/runtime/validation.zig +206 -0
- package/src/runtime/view.zig +908 -0
- package/src/runtime/view_canvas.zig +850 -0
- package/src/runtime/view_widget_control.zig +433 -0
- package/src/runtime/view_widget_scroll.zig +360 -0
- package/src/runtime/view_widget_text.zig +275 -0
- package/src/runtime/view_widget_tree.zig +843 -0
- package/src/runtime/webview_view_bridge_tests.zig +664 -0
- package/src/runtime/widget_bridge.zig +231 -0
- package/src/runtime/window_command_bridge_tests.zig +403 -0
- package/src/runtime/window_storage.zig +255 -0
- package/src/runtime/window_view_runtime.zig +727 -0
- package/src/runtime/window_views.zig +334 -0
- package/src/security/root.zig +118 -0
- package/src/tooling/android.zig +1172 -0
- package/src/tooling/assets.zig +128 -0
- package/src/tooling/buildgraph.zig +379 -0
- package/src/tooling/cef.zig +671 -0
- package/src/tooling/codesign.zig +172 -0
- package/src/tooling/components/identity_tests.zig +185 -0
- package/src/tooling/components/stepper.zig +113 -0
- package/src/tooling/components/timeline.native +27 -0
- package/src/tooling/components/timeline_item.zig +131 -0
- package/src/tooling/default_icon.icns +0 -0
- package/src/tooling/default_icon.png +0 -0
- package/src/tooling/dev.zig +172 -0
- package/src/tooling/doctor.zig +349 -0
- package/src/tooling/eject_components.zig +170 -0
- package/src/tooling/embedlib.zig +290 -0
- package/src/tooling/ios.zig +528 -0
- package/src/tooling/manifest.zig +1939 -0
- package/src/tooling/package.zig +2388 -0
- package/src/tooling/process_tree.zig +114 -0
- package/src/tooling/raw_manifest.zig +193 -0
- package/src/tooling/root.zig +22 -0
- package/src/tooling/templates.zig +3191 -0
- package/src/tooling/toolchain.zig +371 -0
- package/src/tooling/verbs.zig +204 -0
- package/src/tooling/web_engine.zig +135 -0
- package/src/tooling/xcodeproj.zig +462 -0
- package/src/window_state/root.zig +507 -0
- package/index.js +0 -2
|
@@ -0,0 +1,3015 @@
|
|
|
1
|
+
const support = @import("test_support.zig");
|
|
2
|
+
const widget_render_style = @import("widget_render_style.zig");
|
|
3
|
+
const std = support.std;
|
|
4
|
+
const geometry = support.geometry;
|
|
5
|
+
const canvas = support.canvas;
|
|
6
|
+
const drawing_model = support.drawing_model;
|
|
7
|
+
const text_model = support.text_model;
|
|
8
|
+
const render_model = support.render_model;
|
|
9
|
+
const event_model = support.event_model;
|
|
10
|
+
const equality_model = support.equality_model;
|
|
11
|
+
const widget_runtime = support.widget_runtime;
|
|
12
|
+
const Error = support.Error;
|
|
13
|
+
const ObjectId = support.ObjectId;
|
|
14
|
+
const ImageId = support.ImageId;
|
|
15
|
+
const FontId = support.FontId;
|
|
16
|
+
const default_sans_font_id = support.default_sans_font_id;
|
|
17
|
+
const default_mono_font_id = support.default_mono_font_id;
|
|
18
|
+
const default_sans_font_family = support.default_sans_font_family;
|
|
19
|
+
const default_mono_font_family = support.default_mono_font_family;
|
|
20
|
+
const default_glyph_atlas_cache_retention_frames = support.default_glyph_atlas_cache_retention_frames;
|
|
21
|
+
const default_text_layout_cache_retention_frames = support.default_text_layout_cache_retention_frames;
|
|
22
|
+
const Color = support.Color;
|
|
23
|
+
const Affine = support.Affine;
|
|
24
|
+
const Radius = support.Radius;
|
|
25
|
+
const GradientStop = support.GradientStop;
|
|
26
|
+
const LinearGradient = support.LinearGradient;
|
|
27
|
+
const Fill = support.Fill;
|
|
28
|
+
const Stroke = support.Stroke;
|
|
29
|
+
const Clip = support.Clip;
|
|
30
|
+
const FillRect = support.FillRect;
|
|
31
|
+
const StrokeRect = support.StrokeRect;
|
|
32
|
+
const FillRoundedRect = support.FillRoundedRect;
|
|
33
|
+
const Line = support.Line;
|
|
34
|
+
const PathVerb = support.PathVerb;
|
|
35
|
+
const PathElement = support.PathElement;
|
|
36
|
+
const FillPath = support.FillPath;
|
|
37
|
+
const StrokePath = support.StrokePath;
|
|
38
|
+
const ImageFit = support.ImageFit;
|
|
39
|
+
const ImageSampling = support.ImageSampling;
|
|
40
|
+
const DrawImage = support.DrawImage;
|
|
41
|
+
const Shadow = support.Shadow;
|
|
42
|
+
const Blur = support.Blur;
|
|
43
|
+
const Glyph = support.Glyph;
|
|
44
|
+
const GlyphAtlasKey = support.GlyphAtlasKey;
|
|
45
|
+
const GlyphAtlasEntry = support.GlyphAtlasEntry;
|
|
46
|
+
const GlyphAtlasPlan = support.GlyphAtlasPlan;
|
|
47
|
+
const GlyphAtlasPlanner = support.GlyphAtlasPlanner;
|
|
48
|
+
const GlyphAtlasCacheEntry = support.GlyphAtlasCacheEntry;
|
|
49
|
+
const GlyphAtlasCacheActionKind = support.GlyphAtlasCacheActionKind;
|
|
50
|
+
const GlyphAtlasCacheAction = support.GlyphAtlasCacheAction;
|
|
51
|
+
const GlyphAtlasCachePlan = support.GlyphAtlasCachePlan;
|
|
52
|
+
const GlyphAtlasCachePlanner = support.GlyphAtlasCachePlanner;
|
|
53
|
+
const DrawText = support.DrawText;
|
|
54
|
+
const TextWrap = support.TextWrap;
|
|
55
|
+
const TextAlign = support.TextAlign;
|
|
56
|
+
const TextLayoutOptions = support.TextLayoutOptions;
|
|
57
|
+
const TextLine = support.TextLine;
|
|
58
|
+
const TextLayout = support.TextLayout;
|
|
59
|
+
const TextLayoutKey = support.TextLayoutKey;
|
|
60
|
+
const TextLayoutPlan = support.TextLayoutPlan;
|
|
61
|
+
const TextLayoutPlanSet = support.TextLayoutPlanSet;
|
|
62
|
+
const TextLayoutPlanner = support.TextLayoutPlanner;
|
|
63
|
+
const TextLayoutCacheEntry = support.TextLayoutCacheEntry;
|
|
64
|
+
const TextLayoutCacheActionKind = support.TextLayoutCacheActionKind;
|
|
65
|
+
const TextLayoutCacheAction = support.TextLayoutCacheAction;
|
|
66
|
+
const TextLayoutCachePlan = support.TextLayoutCachePlan;
|
|
67
|
+
const TextLayoutCachePlanner = support.TextLayoutCachePlanner;
|
|
68
|
+
const TextRange = support.TextRange;
|
|
69
|
+
const TextSelectionRect = support.TextSelectionRect;
|
|
70
|
+
const TextSelection = support.TextSelection;
|
|
71
|
+
const TextCaretDirection = support.TextCaretDirection;
|
|
72
|
+
const TextCaretMove = support.TextCaretMove;
|
|
73
|
+
const TextCompositionUpdate = support.TextCompositionUpdate;
|
|
74
|
+
const TextInputEvent = support.TextInputEvent;
|
|
75
|
+
const TextEditState = support.TextEditState;
|
|
76
|
+
const CanvasCommand = support.CanvasCommand;
|
|
77
|
+
const CommandRef = support.CommandRef;
|
|
78
|
+
const DiffKind = support.DiffKind;
|
|
79
|
+
const DiffChange = support.DiffChange;
|
|
80
|
+
const Builder = support.Builder;
|
|
81
|
+
const max_render_state_stack = support.max_render_state_stack;
|
|
82
|
+
const RenderState = support.RenderState;
|
|
83
|
+
const RenderCommand = support.RenderCommand;
|
|
84
|
+
const CanvasRenderOverride = support.CanvasRenderOverride;
|
|
85
|
+
const CanvasRenderAnimation = support.CanvasRenderAnimation;
|
|
86
|
+
const applyRenderOverrides = support.applyRenderOverrides;
|
|
87
|
+
const renderOverrideDirtyBounds = support.renderOverrideDirtyBounds;
|
|
88
|
+
const RenderPlan = support.RenderPlan;
|
|
89
|
+
const RenderPlanner = support.RenderPlanner;
|
|
90
|
+
const RenderPipelineKind = support.RenderPipelineKind;
|
|
91
|
+
const RenderBatch = support.RenderBatch;
|
|
92
|
+
const RenderBatchPlanner = support.RenderBatchPlanner;
|
|
93
|
+
const RenderBatchPlan = support.RenderBatchPlan;
|
|
94
|
+
const RenderPipelineCacheEntry = support.RenderPipelineCacheEntry;
|
|
95
|
+
const RenderPipelineCacheActionKind = support.RenderPipelineCacheActionKind;
|
|
96
|
+
const RenderPipelineCacheAction = support.RenderPipelineCacheAction;
|
|
97
|
+
const RenderPipelineCachePlanner = support.RenderPipelineCachePlanner;
|
|
98
|
+
const RenderPipelineCachePlan = support.RenderPipelineCachePlan;
|
|
99
|
+
const RenderPathGeometryKind = support.RenderPathGeometryKind;
|
|
100
|
+
const RenderPathGeometry = support.RenderPathGeometry;
|
|
101
|
+
const RenderPathGeometryPlan = support.RenderPathGeometryPlan;
|
|
102
|
+
const RenderPathGeometryPlanner = support.RenderPathGeometryPlanner;
|
|
103
|
+
const RenderPathGeometryKey = support.RenderPathGeometryKey;
|
|
104
|
+
const RenderPathGeometryCacheEntry = support.RenderPathGeometryCacheEntry;
|
|
105
|
+
const RenderPathGeometryCacheActionKind = support.RenderPathGeometryCacheActionKind;
|
|
106
|
+
const RenderPathGeometryCacheAction = support.RenderPathGeometryCacheAction;
|
|
107
|
+
const RenderPathGeometryCachePlan = support.RenderPathGeometryCachePlan;
|
|
108
|
+
const RenderPathGeometryCachePlanner = support.RenderPathGeometryCachePlanner;
|
|
109
|
+
const RenderImage = support.RenderImage;
|
|
110
|
+
const RenderImagePlan = support.RenderImagePlan;
|
|
111
|
+
const RenderImagePlanner = support.RenderImagePlanner;
|
|
112
|
+
const RenderImageKey = support.RenderImageKey;
|
|
113
|
+
const RenderImageCacheEntry = support.RenderImageCacheEntry;
|
|
114
|
+
const RenderImageCacheActionKind = support.RenderImageCacheActionKind;
|
|
115
|
+
const RenderImageCacheAction = support.RenderImageCacheAction;
|
|
116
|
+
const RenderImageCachePlan = support.RenderImageCachePlan;
|
|
117
|
+
const RenderImageCachePlanner = support.RenderImageCachePlanner;
|
|
118
|
+
const RenderResourceKind = support.RenderResourceKind;
|
|
119
|
+
const RenderResource = support.RenderResource;
|
|
120
|
+
const RenderResourcePlan = support.RenderResourcePlan;
|
|
121
|
+
const RenderResourcePlanner = support.RenderResourcePlanner;
|
|
122
|
+
const RenderResourceKey = support.RenderResourceKey;
|
|
123
|
+
const RenderResourceCacheEntry = support.RenderResourceCacheEntry;
|
|
124
|
+
const RenderResourceCacheActionKind = support.RenderResourceCacheActionKind;
|
|
125
|
+
const RenderResourceCacheAction = support.RenderResourceCacheAction;
|
|
126
|
+
const RenderResourceCachePlan = support.RenderResourceCachePlan;
|
|
127
|
+
const RenderResourceCachePlanner = support.RenderResourceCachePlanner;
|
|
128
|
+
const RenderLayer = support.RenderLayer;
|
|
129
|
+
const RenderLayerPlan = support.RenderLayerPlan;
|
|
130
|
+
const RenderLayerPlanner = support.RenderLayerPlanner;
|
|
131
|
+
const RenderLayerKey = support.RenderLayerKey;
|
|
132
|
+
const RenderLayerCacheEntry = support.RenderLayerCacheEntry;
|
|
133
|
+
const RenderLayerCacheActionKind = support.RenderLayerCacheActionKind;
|
|
134
|
+
const RenderLayerCacheAction = support.RenderLayerCacheAction;
|
|
135
|
+
const RenderLayerCachePlan = support.RenderLayerCachePlan;
|
|
136
|
+
const RenderLayerCachePlanner = support.RenderLayerCachePlanner;
|
|
137
|
+
const VisualEffectKind = support.VisualEffectKind;
|
|
138
|
+
const VisualEffect = support.VisualEffect;
|
|
139
|
+
const VisualEffectPlan = support.VisualEffectPlan;
|
|
140
|
+
const VisualEffectPlanner = support.VisualEffectPlanner;
|
|
141
|
+
const VisualEffectKey = support.VisualEffectKey;
|
|
142
|
+
const VisualEffectCacheEntry = support.VisualEffectCacheEntry;
|
|
143
|
+
const VisualEffectCacheActionKind = support.VisualEffectCacheActionKind;
|
|
144
|
+
const VisualEffectCacheAction = support.VisualEffectCacheAction;
|
|
145
|
+
const VisualEffectCachePlan = support.VisualEffectCachePlan;
|
|
146
|
+
const VisualEffectCachePlanner = support.VisualEffectCachePlanner;
|
|
147
|
+
const CanvasFrameOptions = support.CanvasFrameOptions;
|
|
148
|
+
const CanvasFrameStorage = support.CanvasFrameStorage;
|
|
149
|
+
const CanvasFrameBudget = support.CanvasFrameBudget;
|
|
150
|
+
const CanvasFrameBudgetStatus = support.CanvasFrameBudgetStatus;
|
|
151
|
+
const CanvasFrameDiagnostics = support.CanvasFrameDiagnostics;
|
|
152
|
+
const CanvasFrameProfileRisk = support.CanvasFrameProfileRisk;
|
|
153
|
+
const CanvasFrameProfile = support.CanvasFrameProfile;
|
|
154
|
+
const CanvasRenderPass = support.CanvasRenderPass;
|
|
155
|
+
const CanvasFrame = support.CanvasFrame;
|
|
156
|
+
const buildCanvasFrame = support.buildCanvasFrame;
|
|
157
|
+
const CanvasRenderPassLoadAction = support.CanvasRenderPassLoadAction;
|
|
158
|
+
const RenderEncoderBeginPass = support.RenderEncoderBeginPass;
|
|
159
|
+
const RenderEncoderCommand = support.RenderEncoderCommand;
|
|
160
|
+
const RenderEncoderPlan = support.RenderEncoderPlan;
|
|
161
|
+
const RenderEncoderPlanner = support.RenderEncoderPlanner;
|
|
162
|
+
const CanvasGpuCommandKind = support.CanvasGpuCommandKind;
|
|
163
|
+
const CanvasGpuRoundedRect = support.CanvasGpuRoundedRect;
|
|
164
|
+
const CanvasGpuStrokeRect = support.CanvasGpuStrokeRect;
|
|
165
|
+
const CanvasGpuLine = support.CanvasGpuLine;
|
|
166
|
+
const CanvasGpuShape = support.CanvasGpuShape;
|
|
167
|
+
const CanvasGpuPaint = support.CanvasGpuPaint;
|
|
168
|
+
const CanvasGpuImage = support.CanvasGpuImage;
|
|
169
|
+
const CanvasGpuText = support.CanvasGpuText;
|
|
170
|
+
const CanvasGpuShadow = support.CanvasGpuShadow;
|
|
171
|
+
const CanvasGpuBlur = support.CanvasGpuBlur;
|
|
172
|
+
const CanvasGpuEffect = support.CanvasGpuEffect;
|
|
173
|
+
const CanvasGpuCommand = support.CanvasGpuCommand;
|
|
174
|
+
const CanvasGpuPacket = support.CanvasGpuPacket;
|
|
175
|
+
const CanvasGpuPacketSummary = support.CanvasGpuPacketSummary;
|
|
176
|
+
const CanvasGpuPacketPlanner = support.CanvasGpuPacketPlanner;
|
|
177
|
+
const ReferenceImage = support.ReferenceImage;
|
|
178
|
+
const ReferenceRenderSurface = support.ReferenceRenderSurface;
|
|
179
|
+
const Density = support.Density;
|
|
180
|
+
const Easing = support.Easing;
|
|
181
|
+
const ColorScheme = support.ColorScheme;
|
|
182
|
+
const ColorContrast = support.ColorContrast;
|
|
183
|
+
const ThemeOptions = support.ThemeOptions;
|
|
184
|
+
const ColorTokens = support.ColorTokens;
|
|
185
|
+
const FontFamily = support.FontFamily;
|
|
186
|
+
const TypographyTokens = support.TypographyTokens;
|
|
187
|
+
const SpacingTokens = support.SpacingTokens;
|
|
188
|
+
const RadiusTokens = support.RadiusTokens;
|
|
189
|
+
const StrokeTokens = support.StrokeTokens;
|
|
190
|
+
const ShadowToken = support.ShadowToken;
|
|
191
|
+
const ShadowTokens = support.ShadowTokens;
|
|
192
|
+
const BlurTokens = support.BlurTokens;
|
|
193
|
+
const MotionDuration = support.MotionDuration;
|
|
194
|
+
const MotionAnimationOptions = support.MotionAnimationOptions;
|
|
195
|
+
const MotionTokens = support.MotionTokens;
|
|
196
|
+
const SpringToken = support.SpringToken;
|
|
197
|
+
const BlurTokenRef = support.BlurTokenRef;
|
|
198
|
+
const ScrollPhysics = support.ScrollPhysics;
|
|
199
|
+
const ScrollState = support.ScrollState;
|
|
200
|
+
const VirtualListOptions = support.VirtualListOptions;
|
|
201
|
+
const VirtualListRange = support.VirtualListRange;
|
|
202
|
+
const virtualListRange = support.virtualListRange;
|
|
203
|
+
const LayerTokens = support.LayerTokens;
|
|
204
|
+
const PixelSnapTokens = support.PixelSnapTokens;
|
|
205
|
+
const ControlVisualTokens = support.ControlVisualTokens;
|
|
206
|
+
const ControlTokens = support.ControlTokens;
|
|
207
|
+
const ColorTokenOverrides = support.ColorTokenOverrides;
|
|
208
|
+
const TypographyTokenOverrides = support.TypographyTokenOverrides;
|
|
209
|
+
const SpacingTokenOverrides = support.SpacingTokenOverrides;
|
|
210
|
+
const RadiusTokenOverrides = support.RadiusTokenOverrides;
|
|
211
|
+
const StrokeTokenOverrides = support.StrokeTokenOverrides;
|
|
212
|
+
const ShadowTokenOverrides = support.ShadowTokenOverrides;
|
|
213
|
+
const ShadowTokensOverrides = support.ShadowTokensOverrides;
|
|
214
|
+
const BlurTokenOverrides = support.BlurTokenOverrides;
|
|
215
|
+
const SpringTokenOverrides = support.SpringTokenOverrides;
|
|
216
|
+
const MotionTokenOverrides = support.MotionTokenOverrides;
|
|
217
|
+
const ScrollPhysicsOverrides = support.ScrollPhysicsOverrides;
|
|
218
|
+
const LayerTokenOverrides = support.LayerTokenOverrides;
|
|
219
|
+
const PixelSnapTokenOverrides = support.PixelSnapTokenOverrides;
|
|
220
|
+
const ControlVisualTokenOverrides = support.ControlVisualTokenOverrides;
|
|
221
|
+
const ControlTokenOverrides = support.ControlTokenOverrides;
|
|
222
|
+
const DesignTokenOverrides = support.DesignTokenOverrides;
|
|
223
|
+
const DesignTokens = support.DesignTokens;
|
|
224
|
+
const WidgetKind = support.WidgetKind;
|
|
225
|
+
const WidgetCursor = support.WidgetCursor;
|
|
226
|
+
const WidgetState = support.WidgetState;
|
|
227
|
+
const WidgetRenderState = support.WidgetRenderState;
|
|
228
|
+
const WidgetMainAlignment = support.WidgetMainAlignment;
|
|
229
|
+
const WidgetCrossAlignment = support.WidgetCrossAlignment;
|
|
230
|
+
const WidgetLayoutStyle = support.WidgetLayoutStyle;
|
|
231
|
+
const WidgetStyle = support.WidgetStyle;
|
|
232
|
+
const WidgetVariant = support.WidgetVariant;
|
|
233
|
+
const WidgetSize = support.WidgetSize;
|
|
234
|
+
const WidgetRole = support.WidgetRole;
|
|
235
|
+
const BuiltinComponentStyle = support.BuiltinComponentStyle;
|
|
236
|
+
const BuiltinComponentKind = support.BuiltinComponentKind;
|
|
237
|
+
const builtin_component_kinds = support.builtin_component_kinds;
|
|
238
|
+
const builtin_component_names = support.builtin_component_names;
|
|
239
|
+
const BuiltinComponentDescriptor = support.BuiltinComponentDescriptor;
|
|
240
|
+
const builtinComponentCount = support.builtinComponentCount;
|
|
241
|
+
const builtinComponentName = support.builtinComponentName;
|
|
242
|
+
const builtinComponentDescriptor = support.builtinComponentDescriptor;
|
|
243
|
+
const WidgetActions = support.WidgetActions;
|
|
244
|
+
const WidgetSemantics = support.WidgetSemantics;
|
|
245
|
+
const Widget = support.Widget;
|
|
246
|
+
const BuiltinComponentOptions = support.BuiltinComponentOptions;
|
|
247
|
+
const WidgetCommandPart = support.WidgetCommandPart;
|
|
248
|
+
const BuiltinSurfacePlacementOptions = support.BuiltinSurfacePlacementOptions;
|
|
249
|
+
const BuiltinSurfaceBackdropOptions = support.BuiltinSurfaceBackdropOptions;
|
|
250
|
+
const BuiltinStatusBarOptions = support.BuiltinStatusBarOptions;
|
|
251
|
+
const BuiltinSurfaceEnterAnimationOptions = support.BuiltinSurfaceEnterAnimationOptions;
|
|
252
|
+
const builtinComponentWidget = support.builtinComponentWidget;
|
|
253
|
+
const widgetCommandPartId = support.widgetCommandPartId;
|
|
254
|
+
const builtinSurfaceBackdropWidget = support.builtinSurfaceBackdropWidget;
|
|
255
|
+
const builtinStatusBarWidget = support.builtinStatusBarWidget;
|
|
256
|
+
const builtinSurfaceFrame = support.builtinSurfaceFrame;
|
|
257
|
+
const appendBuiltinSurfaceEnterAnimations = support.appendBuiltinSurfaceEnterAnimations;
|
|
258
|
+
const builtinSurfaceEnterOffset = support.builtinSurfaceEnterOffset;
|
|
259
|
+
const max_widget_depth = support.max_widget_depth;
|
|
260
|
+
const max_widget_text_range_rects = support.max_widget_text_range_rects;
|
|
261
|
+
const WidgetLayoutNode = support.WidgetLayoutNode;
|
|
262
|
+
const WidgetHit = support.WidgetHit;
|
|
263
|
+
const WidgetPointerPhase = support.WidgetPointerPhase;
|
|
264
|
+
const WidgetPointerEvent = support.WidgetPointerEvent;
|
|
265
|
+
const WidgetKeyboardPhase = support.WidgetKeyboardPhase;
|
|
266
|
+
const WidgetKeyboardModifiers = support.WidgetKeyboardModifiers;
|
|
267
|
+
const WidgetKeyboardEvent = support.WidgetKeyboardEvent;
|
|
268
|
+
const WidgetControlIntentKind = support.WidgetControlIntentKind;
|
|
269
|
+
const WidgetControlIntent = support.WidgetControlIntent;
|
|
270
|
+
const WidgetSemanticAction = support.WidgetSemanticAction;
|
|
271
|
+
const WidgetFileDropEvent = support.WidgetFileDropEvent;
|
|
272
|
+
const WidgetDragEvent = support.WidgetDragEvent;
|
|
273
|
+
const WidgetEventPhase = support.WidgetEventPhase;
|
|
274
|
+
const WidgetEventRouteEntry = support.WidgetEventRouteEntry;
|
|
275
|
+
const WidgetEventRoute = support.WidgetEventRoute;
|
|
276
|
+
const WidgetKeyboardRoute = support.WidgetKeyboardRoute;
|
|
277
|
+
const WidgetFocusDirection = support.WidgetFocusDirection;
|
|
278
|
+
const WidgetFocusTarget = support.WidgetFocusTarget;
|
|
279
|
+
const WidgetScrollMetrics = support.WidgetScrollMetrics;
|
|
280
|
+
const WidgetListMetrics = support.WidgetListMetrics;
|
|
281
|
+
const WidgetSemanticsNode = support.WidgetSemanticsNode;
|
|
282
|
+
const WidgetInvalidationKind = support.WidgetInvalidationKind;
|
|
283
|
+
const WidgetInvalidation = support.WidgetInvalidation;
|
|
284
|
+
const widgetKeyboardControlIntent = support.widgetKeyboardControlIntent;
|
|
285
|
+
const widgetSemanticControlIntent = support.widgetSemanticControlIntent;
|
|
286
|
+
const widgetSemanticControlIntentWithActions = support.widgetSemanticControlIntentWithActions;
|
|
287
|
+
const isWidgetActivationKey = support.isWidgetActivationKey;
|
|
288
|
+
const widgetSliderKeyboardValue = support.widgetSliderKeyboardValue;
|
|
289
|
+
const widgetScrollKeyboardIntent = support.widgetScrollKeyboardIntent;
|
|
290
|
+
const widgetScrollKeyboardDelta = support.widgetScrollKeyboardDelta;
|
|
291
|
+
const WidgetLayoutTree = support.WidgetLayoutTree;
|
|
292
|
+
const DisplayList = support.DisplayList;
|
|
293
|
+
const emitWidgetTree = support.emitWidgetTree;
|
|
294
|
+
const layoutWidgetTree = support.layoutWidgetTree;
|
|
295
|
+
const layoutWidgetTreeWithTokens = support.layoutWidgetTreeWithTokens;
|
|
296
|
+
const layoutTextRun = support.layoutTextRun;
|
|
297
|
+
const layoutTextRunPlan = support.layoutTextRunPlan;
|
|
298
|
+
const layoutTextCaretRect = support.layoutTextCaretRect;
|
|
299
|
+
const textCaretRectForLayout = support.textCaretRectForLayout;
|
|
300
|
+
const layoutTextSelectionRects = support.layoutTextSelectionRects;
|
|
301
|
+
const textSelectionRectsForLayout = support.textSelectionRectsForLayout;
|
|
302
|
+
const layoutTextOffsetForPoint = support.layoutTextOffsetForPoint;
|
|
303
|
+
const textOffsetForLayoutPoint = support.textOffsetForLayoutPoint;
|
|
304
|
+
const applyTextInputEvent = support.applyTextInputEvent;
|
|
305
|
+
const sampleCanvasRenderAnimations = support.sampleCanvasRenderAnimations;
|
|
306
|
+
const emitWidgetLayout = support.emitWidgetLayout;
|
|
307
|
+
const toggleWidgetKnobCommandId = support.toggleWidgetKnobCommandId;
|
|
308
|
+
const toggleWidgetKnobTravel = support.toggleWidgetKnobTravel;
|
|
309
|
+
const textSelectionForWidgetPoint = support.textSelectionForWidgetPoint;
|
|
310
|
+
const textOffsetForWidgetPoint = support.textOffsetForWidgetPoint;
|
|
311
|
+
const textInputViewportForWidget = support.textInputViewportForWidget;
|
|
312
|
+
const textInputContentExtentForWidget = support.textInputContentExtentForWidget;
|
|
313
|
+
const textInputMaxScrollOffsetForWidget = support.textInputMaxScrollOffsetForWidget;
|
|
314
|
+
const clampedTextInputScrollOffsetForWidget = support.clampedTextInputScrollOffsetForWidget;
|
|
315
|
+
const intrinsicWidgetSize = support.intrinsicWidgetSize;
|
|
316
|
+
const cursorForWidgetHit = support.cursorForWidgetHit;
|
|
317
|
+
const cursorForWidgetTarget = support.cursorForWidgetTarget;
|
|
318
|
+
const WidgetTextGeometry = support.WidgetTextGeometry;
|
|
319
|
+
const textGeometryForWidget = support.textGeometryForWidget;
|
|
320
|
+
const virtualWidgetScrollContentExtent = support.virtualWidgetScrollContentExtent;
|
|
321
|
+
const virtualWidgetScrollContentExtentWithTokens = support.virtualWidgetScrollContentExtentWithTokens;
|
|
322
|
+
const writeCanvasGpuPacketJson = support.writeCanvasGpuPacketJson;
|
|
323
|
+
const strokeBounds = support.strokeBounds;
|
|
324
|
+
const shadowBounds = support.shadowBounds;
|
|
325
|
+
const semanticActions = support.semanticActions;
|
|
326
|
+
const defaultSemanticActions = support.defaultSemanticActions;
|
|
327
|
+
const defaultFocusable = support.defaultFocusable;
|
|
328
|
+
const textLineBounds = support.textLineBounds;
|
|
329
|
+
const textBounds = support.textBounds;
|
|
330
|
+
const estimateTextWidth = support.estimateTextWidth;
|
|
331
|
+
const estimateTextWidthForFont = support.estimateTextWidthForFont;
|
|
332
|
+
const estimateTextAdvanceForBytes = support.estimateTextAdvanceForBytes;
|
|
333
|
+
const estimatedGlyphAdvance = support.estimatedGlyphAdvance;
|
|
334
|
+
const snapTextSelection = support.snapTextSelection;
|
|
335
|
+
const snapTextRange = support.snapTextRange;
|
|
336
|
+
const nextTextOffset = support.nextTextOffset;
|
|
337
|
+
const nextTextLineEnd = support.nextTextLineEnd;
|
|
338
|
+
const isTextBreakByte = support.isTextBreakByte;
|
|
339
|
+
const textLineRange = support.textLineRange;
|
|
340
|
+
const textLineCaretX = support.textLineCaretX;
|
|
341
|
+
const motionProgress = support.motionProgress;
|
|
342
|
+
const renderImageFingerprint = support.renderImageFingerprint;
|
|
343
|
+
const renderImageFingerprintForResource = support.renderImageFingerprintForResource;
|
|
344
|
+
const commandsEqual = support.commandsEqual;
|
|
345
|
+
const rectsEqual = support.rectsEqual;
|
|
346
|
+
const optionalRectsEqual = support.optionalRectsEqual;
|
|
347
|
+
const sizesEqual = support.sizesEqual;
|
|
348
|
+
const insetsEqual = support.insetsEqual;
|
|
349
|
+
const optionalColorsEqual = support.optionalColorsEqual;
|
|
350
|
+
const radiiEqual = support.radiiEqual;
|
|
351
|
+
const affinesEqual = support.affinesEqual;
|
|
352
|
+
const optionalF32Equal = support.optionalF32Equal;
|
|
353
|
+
const optionalTextSelectionsEqual = support.optionalTextSelectionsEqual;
|
|
354
|
+
const optionalTextRangesEqual = support.optionalTextRangesEqual;
|
|
355
|
+
const widgetPartId = support.widgetPartId;
|
|
356
|
+
const colorWithAlpha = support.colorWithAlpha;
|
|
357
|
+
const widgetControlHeight = support.widgetControlHeight;
|
|
358
|
+
const textSelectionFillColor = support.textSelectionFillColor;
|
|
359
|
+
const transparentColor = support.transparentColor;
|
|
360
|
+
const expectRect = support.expectRect;
|
|
361
|
+
const expectRectApprox = support.expectRectApprox;
|
|
362
|
+
const expectPixelRgba8 = support.expectPixelRgba8;
|
|
363
|
+
const expectVisiblePixel = support.expectVisiblePixel;
|
|
364
|
+
const referenceSurfaceSignature = support.referenceSurfaceSignature;
|
|
365
|
+
const expectLayoutFrame = support.expectLayoutFrame;
|
|
366
|
+
const expectRouteEntry = support.expectRouteEntry;
|
|
367
|
+
const expectFillColor = support.expectFillColor;
|
|
368
|
+
const expectGpuPaintColor = support.expectGpuPaintColor;
|
|
369
|
+
|
|
370
|
+
test "widget layout reports fixed buffer errors" {
|
|
371
|
+
const children = [_]Widget{
|
|
372
|
+
.{ .id = 2, .kind = .text, .text = "One" },
|
|
373
|
+
.{ .id = 3, .kind = .text, .text = "Two" },
|
|
374
|
+
};
|
|
375
|
+
const root = Widget{ .id = 1, .kind = .stack, .children = &children };
|
|
376
|
+
|
|
377
|
+
var small_nodes: [2]WidgetLayoutNode = undefined;
|
|
378
|
+
try std.testing.expectError(error.WidgetLayoutListFull, layoutWidgetTree(root, geometry.RectF.init(0, 0, 100, 100), &small_nodes));
|
|
379
|
+
|
|
380
|
+
var nodes: [4]WidgetLayoutNode = undefined;
|
|
381
|
+
const layout = try layoutWidgetTree(root, geometry.RectF.init(0, 0, 100, 100), &nodes);
|
|
382
|
+
var small_semantics: [1]WidgetSemanticsNode = undefined;
|
|
383
|
+
try std.testing.expectError(error.WidgetSemanticsListFull, layout.collectSemantics(&small_semantics));
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
test "widget layout diff tracks added removed and layout changes by id" {
|
|
387
|
+
const previous_children = [_]Widget{
|
|
388
|
+
.{
|
|
389
|
+
.id = 2,
|
|
390
|
+
.kind = .button,
|
|
391
|
+
.frame = geometry.RectF.init(10, 10, 100, 30),
|
|
392
|
+
.text = "Run",
|
|
393
|
+
},
|
|
394
|
+
.{
|
|
395
|
+
.id = 3,
|
|
396
|
+
.kind = .progress,
|
|
397
|
+
.frame = geometry.RectF.init(10, 50, 100, 8),
|
|
398
|
+
.value = 0.4,
|
|
399
|
+
},
|
|
400
|
+
};
|
|
401
|
+
const next_children = [_]Widget{
|
|
402
|
+
.{
|
|
403
|
+
.id = 2,
|
|
404
|
+
.kind = .button,
|
|
405
|
+
.frame = geometry.RectF.init(20, 10, 100, 30),
|
|
406
|
+
.text = "Run",
|
|
407
|
+
.state = .{ .focused = true },
|
|
408
|
+
},
|
|
409
|
+
.{
|
|
410
|
+
.id = 4,
|
|
411
|
+
.kind = .text,
|
|
412
|
+
.frame = geometry.RectF.init(10, 50, 100, 20),
|
|
413
|
+
.text = "Done",
|
|
414
|
+
},
|
|
415
|
+
};
|
|
416
|
+
|
|
417
|
+
var previous_nodes: [4]WidgetLayoutNode = undefined;
|
|
418
|
+
var next_nodes: [4]WidgetLayoutNode = undefined;
|
|
419
|
+
const previous = try layoutWidgetTree(.{ .id = 1, .kind = .stack, .children = &previous_children }, geometry.RectF.init(0, 0, 180, 100), &previous_nodes);
|
|
420
|
+
const next = try layoutWidgetTree(.{ .id = 1, .kind = .stack, .children = &next_children }, geometry.RectF.init(0, 0, 180, 100), &next_nodes);
|
|
421
|
+
|
|
422
|
+
var invalidations_buffer: [4]WidgetInvalidation = undefined;
|
|
423
|
+
const invalidations = try WidgetLayoutTree.diff(previous, next, &invalidations_buffer);
|
|
424
|
+
try std.testing.expectEqual(@as(usize, 3), invalidations.len);
|
|
425
|
+
|
|
426
|
+
try std.testing.expectEqual(WidgetInvalidationKind.changed, invalidations[0].kind);
|
|
427
|
+
try std.testing.expectEqual(@as(ObjectId, 2), invalidations[0].id);
|
|
428
|
+
try std.testing.expect(invalidations[0].layout_dirty);
|
|
429
|
+
try std.testing.expect(invalidations[0].paint_dirty);
|
|
430
|
+
try std.testing.expect(invalidations[0].semantics_dirty);
|
|
431
|
+
// The button is flat (no shadow halo), so the damage is the union
|
|
432
|
+
// of the old and new frames plus their chrome-stroke outsets: half
|
|
433
|
+
// of the resting 1px border around the old frame, half of the 2px
|
|
434
|
+
// focus-weight stroke around the new (focused) frame.
|
|
435
|
+
try expectRect(geometry.RectF.init(9.5, 9, 111.5, 32), invalidations[0].dirty_bounds);
|
|
436
|
+
|
|
437
|
+
try std.testing.expectEqual(WidgetInvalidationKind.removed, invalidations[1].kind);
|
|
438
|
+
try std.testing.expectEqual(@as(ObjectId, 3), invalidations[1].id);
|
|
439
|
+
try expectRect(geometry.RectF.init(10, 50, 100, 8), invalidations[1].dirty_bounds);
|
|
440
|
+
|
|
441
|
+
try std.testing.expectEqual(WidgetInvalidationKind.added, invalidations[2].kind);
|
|
442
|
+
try std.testing.expectEqual(@as(ObjectId, 4), invalidations[2].id);
|
|
443
|
+
try expectRect(geometry.RectF.init(10, 50, 100, 20), invalidations[2].dirty_bounds);
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
test "widget layout diff includes paint overdraw in dirty bounds" {
|
|
447
|
+
const panel_child = [_]Widget{.{
|
|
448
|
+
.id = 2,
|
|
449
|
+
.kind = .panel,
|
|
450
|
+
.frame = geometry.RectF.init(10, 10, 100, 40),
|
|
451
|
+
}};
|
|
452
|
+
const hidden_panel_child = [_]Widget{.{
|
|
453
|
+
.id = 2,
|
|
454
|
+
.kind = .panel,
|
|
455
|
+
.frame = geometry.RectF.init(10, 10, 100, 40),
|
|
456
|
+
.semantics = .{ .hidden = true },
|
|
457
|
+
}};
|
|
458
|
+
const overflow_panel_children = [_]Widget{.{
|
|
459
|
+
.id = 6,
|
|
460
|
+
.kind = .text,
|
|
461
|
+
.frame = geometry.RectF.init(100, 10, 80, 20),
|
|
462
|
+
.text = "Overflow",
|
|
463
|
+
}};
|
|
464
|
+
const visible_overflow_panel_child = [_]Widget{.{
|
|
465
|
+
.id = 5,
|
|
466
|
+
.kind = .panel,
|
|
467
|
+
.frame = geometry.RectF.init(10, 10, 40, 20),
|
|
468
|
+
.children = &overflow_panel_children,
|
|
469
|
+
}};
|
|
470
|
+
const hidden_overflow_panel_child = [_]Widget{.{
|
|
471
|
+
.id = 5,
|
|
472
|
+
.kind = .panel,
|
|
473
|
+
.frame = geometry.RectF.init(10, 10, 40, 20),
|
|
474
|
+
.semantics = .{ .hidden = true },
|
|
475
|
+
.children = &overflow_panel_children,
|
|
476
|
+
}};
|
|
477
|
+
const unfocused_child = [_]Widget{.{
|
|
478
|
+
.id = 3,
|
|
479
|
+
.kind = .button,
|
|
480
|
+
.frame = geometry.RectF.init(10, 70, 100, 30),
|
|
481
|
+
.text = "Focus",
|
|
482
|
+
}};
|
|
483
|
+
const focused_child = [_]Widget{.{
|
|
484
|
+
.id = 3,
|
|
485
|
+
.kind = .button,
|
|
486
|
+
.frame = geometry.RectF.init(10, 70, 100, 30),
|
|
487
|
+
.text = "Focus",
|
|
488
|
+
.state = .{ .focused = true },
|
|
489
|
+
}};
|
|
490
|
+
|
|
491
|
+
var previous_panel_nodes: [2]WidgetLayoutNode = undefined;
|
|
492
|
+
var next_panel_nodes: [1]WidgetLayoutNode = undefined;
|
|
493
|
+
var hidden_panel_nodes: [2]WidgetLayoutNode = undefined;
|
|
494
|
+
var visible_overflow_panel_nodes: [3]WidgetLayoutNode = undefined;
|
|
495
|
+
var hidden_overflow_panel_nodes: [3]WidgetLayoutNode = undefined;
|
|
496
|
+
const previous_panel = try layoutWidgetTree(.{ .kind = .stack, .children = &panel_child }, geometry.RectF.init(0, 0, 160, 120), &previous_panel_nodes);
|
|
497
|
+
const next_panel = try layoutWidgetTree(.{ .kind = .stack, .children = &.{} }, geometry.RectF.init(0, 0, 160, 120), &next_panel_nodes);
|
|
498
|
+
const hidden_panel = try layoutWidgetTree(.{ .kind = .stack, .children = &hidden_panel_child }, geometry.RectF.init(0, 0, 160, 120), &hidden_panel_nodes);
|
|
499
|
+
const visible_overflow_panel = try layoutWidgetTree(.{ .kind = .stack, .children = &visible_overflow_panel_child }, geometry.RectF.init(0, 0, 220, 120), &visible_overflow_panel_nodes);
|
|
500
|
+
const hidden_overflow_panel = try layoutWidgetTree(.{ .kind = .stack, .children = &hidden_overflow_panel_child }, geometry.RectF.init(0, 0, 220, 120), &hidden_overflow_panel_nodes);
|
|
501
|
+
|
|
502
|
+
var invalidations_buffer: [2]WidgetInvalidation = undefined;
|
|
503
|
+
const panel_invalidations = try WidgetLayoutTree.diff(previous_panel, next_panel, &invalidations_buffer);
|
|
504
|
+
try std.testing.expectEqual(@as(usize, 1), panel_invalidations.len);
|
|
505
|
+
try std.testing.expectEqual(WidgetInvalidationKind.removed, panel_invalidations[0].kind);
|
|
506
|
+
try std.testing.expectEqual(@as(ObjectId, 2), panel_invalidations[0].id);
|
|
507
|
+
try expectRect(geometry.RectF.init(-2, 0, 124, 64), panel_invalidations[0].dirty_bounds);
|
|
508
|
+
|
|
509
|
+
const hidden_panel_invalidations = try WidgetLayoutTree.diff(previous_panel, hidden_panel, &invalidations_buffer);
|
|
510
|
+
try std.testing.expectEqual(@as(usize, 1), hidden_panel_invalidations.len);
|
|
511
|
+
try std.testing.expectEqual(WidgetInvalidationKind.changed, hidden_panel_invalidations[0].kind);
|
|
512
|
+
try std.testing.expectEqual(@as(ObjectId, 2), hidden_panel_invalidations[0].id);
|
|
513
|
+
try std.testing.expect(!hidden_panel_invalidations[0].layout_dirty);
|
|
514
|
+
try std.testing.expect(hidden_panel_invalidations[0].paint_dirty);
|
|
515
|
+
try std.testing.expect(hidden_panel_invalidations[0].semantics_dirty);
|
|
516
|
+
try expectRect(geometry.RectF.init(-2, 0, 124, 64), hidden_panel_invalidations[0].dirty_bounds);
|
|
517
|
+
|
|
518
|
+
const hidden_overflow_panel_invalidations = try WidgetLayoutTree.diff(visible_overflow_panel, hidden_overflow_panel, &invalidations_buffer);
|
|
519
|
+
try std.testing.expectEqual(@as(usize, 1), hidden_overflow_panel_invalidations.len);
|
|
520
|
+
try std.testing.expectEqual(WidgetInvalidationKind.changed, hidden_overflow_panel_invalidations[0].kind);
|
|
521
|
+
try std.testing.expectEqual(@as(ObjectId, 5), hidden_overflow_panel_invalidations[0].id);
|
|
522
|
+
try std.testing.expect(hidden_overflow_panel_invalidations[0].paint_dirty);
|
|
523
|
+
try expectRect(geometry.RectF.init(-2, 0, 192, 44), hidden_overflow_panel_invalidations[0].dirty_bounds);
|
|
524
|
+
|
|
525
|
+
var unfocused_nodes: [2]WidgetLayoutNode = undefined;
|
|
526
|
+
var focused_nodes: [2]WidgetLayoutNode = undefined;
|
|
527
|
+
const unfocused = try layoutWidgetTree(.{ .kind = .stack, .children = &unfocused_child }, geometry.RectF.init(0, 0, 160, 120), &unfocused_nodes);
|
|
528
|
+
const focused = try layoutWidgetTree(.{ .kind = .stack, .children = &focused_child }, geometry.RectF.init(0, 0, 160, 120), &focused_nodes);
|
|
529
|
+
|
|
530
|
+
const focus_invalidations = try WidgetLayoutTree.diff(unfocused, focused, &invalidations_buffer);
|
|
531
|
+
try std.testing.expectEqual(@as(usize, 1), focus_invalidations.len);
|
|
532
|
+
try std.testing.expectEqual(WidgetInvalidationKind.changed, focus_invalidations[0].kind);
|
|
533
|
+
try std.testing.expectEqual(@as(ObjectId, 3), focus_invalidations[0].id);
|
|
534
|
+
// The focus ring strokes 2px outside the control, so its dirty
|
|
535
|
+
// bounds inflate by the offset plus half the 2px focus stroke.
|
|
536
|
+
try expectRect(geometry.RectF.init(7, 67, 106, 36), focus_invalidations[0].dirty_bounds);
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
test "widget render state dirty bounds tracks changed runtime states" {
|
|
540
|
+
const children = [_]Widget{
|
|
541
|
+
.{
|
|
542
|
+
.id = 2,
|
|
543
|
+
.kind = .button,
|
|
544
|
+
.frame = geometry.RectF.init(10, 12, 96, 32),
|
|
545
|
+
.text = "Run",
|
|
546
|
+
},
|
|
547
|
+
.{
|
|
548
|
+
.id = 3,
|
|
549
|
+
.kind = .button,
|
|
550
|
+
.frame = geometry.RectF.init(10, 56, 96, 32),
|
|
551
|
+
.text = "Stop",
|
|
552
|
+
},
|
|
553
|
+
.{
|
|
554
|
+
.id = 4,
|
|
555
|
+
.kind = .text,
|
|
556
|
+
.frame = geometry.RectF.init(10, 100, 96, 20),
|
|
557
|
+
.text = "Label",
|
|
558
|
+
},
|
|
559
|
+
};
|
|
560
|
+
var nodes: [4]WidgetLayoutNode = undefined;
|
|
561
|
+
const layout = try layoutWidgetTree(.{ .kind = .stack, .children = &children }, geometry.RectF.init(0, 0, 160, 140), &nodes);
|
|
562
|
+
|
|
563
|
+
try expectRect(
|
|
564
|
+
geometry.RectF.init(7, 9, 102, 82),
|
|
565
|
+
layout.renderStateDirtyBounds(
|
|
566
|
+
.{ .focused_id = 2, .focus_visible_id = 2, .hovered_id = 2, .pressed_id = 2 },
|
|
567
|
+
.{ .focused_id = 3, .focus_visible_id = 3, .hovered_id = 3 },
|
|
568
|
+
),
|
|
569
|
+
);
|
|
570
|
+
try std.testing.expect(layout.renderStateDirtyBounds(.{ .focused_id = 2 }, .{ .focused_id = 2 }) == null);
|
|
571
|
+
try std.testing.expect(layout.renderStateDirtyBounds(.{ .focused_id = 99 }, .{ .focused_id = 100 }) == null);
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
test "widget render state dirty bounds uses custom focus stroke tokens" {
|
|
575
|
+
const children = [_]Widget{.{
|
|
576
|
+
.id = 2,
|
|
577
|
+
.kind = .button,
|
|
578
|
+
.frame = geometry.RectF.init(10, 12, 96, 32),
|
|
579
|
+
.text = "Run",
|
|
580
|
+
}};
|
|
581
|
+
const tokens = DesignTokens{
|
|
582
|
+
.stroke = .{ .focus = 6 },
|
|
583
|
+
};
|
|
584
|
+
var nodes: [2]WidgetLayoutNode = undefined;
|
|
585
|
+
const layout = try layoutWidgetTree(.{ .kind = .stack, .children = &children }, geometry.RectF.init(0, 0, 160, 80), &nodes);
|
|
586
|
+
|
|
587
|
+
try expectRect(
|
|
588
|
+
geometry.RectF.init(5, 7, 106, 42),
|
|
589
|
+
layout.renderStateDirtyBoundsWithTokens(.{}, .{ .focused_id = 2, .focus_visible_id = 2 }, tokens),
|
|
590
|
+
);
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
test "widget render state dirty bounds clips to scroll ancestors" {
|
|
594
|
+
const children = [_]Widget{.{
|
|
595
|
+
.id = 2,
|
|
596
|
+
.kind = .button,
|
|
597
|
+
.frame = geometry.RectF.init(0, 50, 0, 32),
|
|
598
|
+
.text = "Tail",
|
|
599
|
+
}};
|
|
600
|
+
var nodes: [2]WidgetLayoutNode = undefined;
|
|
601
|
+
const layout = try layoutWidgetTree(
|
|
602
|
+
.{ .id = 1, .kind = .scroll_view, .children = &children },
|
|
603
|
+
geometry.RectF.init(0, 0, 120, 60),
|
|
604
|
+
&nodes,
|
|
605
|
+
);
|
|
606
|
+
|
|
607
|
+
try expectRect(
|
|
608
|
+
geometry.RectF.init(0, 50, 120, 10),
|
|
609
|
+
layout.renderStateDirtyBounds(.{}, .{ .pressed_id = 2 }),
|
|
610
|
+
);
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
test "widget layout diff separates paint and semantics dirtiness" {
|
|
614
|
+
const previous_child = [_]Widget{.{
|
|
615
|
+
.id = 2,
|
|
616
|
+
.kind = .button,
|
|
617
|
+
.frame = geometry.RectF.init(10, 10, 100, 30),
|
|
618
|
+
.text = "Run",
|
|
619
|
+
}};
|
|
620
|
+
const pressed_child = [_]Widget{.{
|
|
621
|
+
.id = 2,
|
|
622
|
+
.kind = .button,
|
|
623
|
+
.frame = geometry.RectF.init(10, 10, 100, 30),
|
|
624
|
+
.text = "Run",
|
|
625
|
+
.state = .{ .pressed = true },
|
|
626
|
+
}};
|
|
627
|
+
const semantic_child = [_]Widget{.{
|
|
628
|
+
.id = 2,
|
|
629
|
+
.kind = .button,
|
|
630
|
+
.frame = geometry.RectF.init(10, 10, 100, 30),
|
|
631
|
+
.text = "Run",
|
|
632
|
+
.semantics = .{ .label = "Run report" },
|
|
633
|
+
}};
|
|
634
|
+
const command_child = [_]Widget{.{
|
|
635
|
+
.id = 2,
|
|
636
|
+
.kind = .button,
|
|
637
|
+
.frame = geometry.RectF.init(10, 10, 100, 30),
|
|
638
|
+
.text = "Run",
|
|
639
|
+
.command = "report.run",
|
|
640
|
+
}};
|
|
641
|
+
const action_previous_child = [_]Widget{.{
|
|
642
|
+
.id = 2,
|
|
643
|
+
.kind = .text,
|
|
644
|
+
.frame = geometry.RectF.init(10, 10, 100, 30),
|
|
645
|
+
.text = "Report",
|
|
646
|
+
}};
|
|
647
|
+
const action_child = [_]Widget{.{
|
|
648
|
+
.id = 2,
|
|
649
|
+
.kind = .text,
|
|
650
|
+
.frame = geometry.RectF.init(10, 10, 100, 30),
|
|
651
|
+
.text = "Report",
|
|
652
|
+
.semantics = .{ .actions = .{ .focus = true, .press = true } },
|
|
653
|
+
}};
|
|
654
|
+
const image_previous_child = [_]Widget{.{
|
|
655
|
+
.id = 3,
|
|
656
|
+
.kind = .image,
|
|
657
|
+
.frame = geometry.RectF.init(8, 12, 80, 48),
|
|
658
|
+
.image_id = 11,
|
|
659
|
+
}};
|
|
660
|
+
const image_next_child = [_]Widget{.{
|
|
661
|
+
.id = 3,
|
|
662
|
+
.kind = .image,
|
|
663
|
+
.frame = geometry.RectF.init(8, 12, 80, 48),
|
|
664
|
+
.image_id = 12,
|
|
665
|
+
.image_src = geometry.RectF.init(0, 0, 640, 360),
|
|
666
|
+
.image_fit = .contain,
|
|
667
|
+
.image_sampling = .nearest,
|
|
668
|
+
.image_opacity = 0.5,
|
|
669
|
+
}};
|
|
670
|
+
|
|
671
|
+
var previous_nodes: [2]WidgetLayoutNode = undefined;
|
|
672
|
+
var pressed_nodes: [2]WidgetLayoutNode = undefined;
|
|
673
|
+
var semantic_nodes: [2]WidgetLayoutNode = undefined;
|
|
674
|
+
var command_nodes: [2]WidgetLayoutNode = undefined;
|
|
675
|
+
var action_previous_nodes: [2]WidgetLayoutNode = undefined;
|
|
676
|
+
var action_nodes: [2]WidgetLayoutNode = undefined;
|
|
677
|
+
var image_previous_nodes: [2]WidgetLayoutNode = undefined;
|
|
678
|
+
var image_next_nodes: [2]WidgetLayoutNode = undefined;
|
|
679
|
+
const previous = try layoutWidgetTree(.{ .kind = .stack, .children = &previous_child }, geometry.RectF.init(0, 0, 140, 80), &previous_nodes);
|
|
680
|
+
const pressed = try layoutWidgetTree(.{ .kind = .stack, .children = &pressed_child }, geometry.RectF.init(0, 0, 140, 80), &pressed_nodes);
|
|
681
|
+
const semantic = try layoutWidgetTree(.{ .kind = .stack, .children = &semantic_child }, geometry.RectF.init(0, 0, 140, 80), &semantic_nodes);
|
|
682
|
+
const command = try layoutWidgetTree(.{ .kind = .stack, .children = &command_child }, geometry.RectF.init(0, 0, 140, 80), &command_nodes);
|
|
683
|
+
const action_previous = try layoutWidgetTree(.{ .kind = .stack, .children = &action_previous_child }, geometry.RectF.init(0, 0, 140, 80), &action_previous_nodes);
|
|
684
|
+
const action = try layoutWidgetTree(.{ .kind = .stack, .children = &action_child }, geometry.RectF.init(0, 0, 140, 80), &action_nodes);
|
|
685
|
+
const image_previous = try layoutWidgetTree(.{ .kind = .stack, .children = &image_previous_child }, geometry.RectF.init(0, 0, 140, 80), &image_previous_nodes);
|
|
686
|
+
const image_next = try layoutWidgetTree(.{ .kind = .stack, .children = &image_next_child }, geometry.RectF.init(0, 0, 140, 80), &image_next_nodes);
|
|
687
|
+
|
|
688
|
+
var invalidations_buffer: [2]WidgetInvalidation = undefined;
|
|
689
|
+
const pressed_invalidations = try WidgetLayoutTree.diff(previous, pressed, &invalidations_buffer);
|
|
690
|
+
try std.testing.expectEqual(@as(usize, 1), pressed_invalidations.len);
|
|
691
|
+
try std.testing.expect(!pressed_invalidations[0].layout_dirty);
|
|
692
|
+
try std.testing.expect(pressed_invalidations[0].paint_dirty);
|
|
693
|
+
try std.testing.expect(pressed_invalidations[0].semantics_dirty);
|
|
694
|
+
try expectRect(geometry.RectF.init(10, 10, 100, 30), pressed_invalidations[0].dirty_bounds);
|
|
695
|
+
|
|
696
|
+
const semantic_invalidations = try WidgetLayoutTree.diff(previous, semantic, &invalidations_buffer);
|
|
697
|
+
try std.testing.expectEqual(@as(usize, 1), semantic_invalidations.len);
|
|
698
|
+
try std.testing.expect(!semantic_invalidations[0].layout_dirty);
|
|
699
|
+
try std.testing.expect(!semantic_invalidations[0].paint_dirty);
|
|
700
|
+
try std.testing.expect(semantic_invalidations[0].semantics_dirty);
|
|
701
|
+
try std.testing.expect(semantic_invalidations[0].dirty_bounds == null);
|
|
702
|
+
|
|
703
|
+
const command_invalidations = try WidgetLayoutTree.diff(previous, command, &invalidations_buffer);
|
|
704
|
+
try std.testing.expectEqual(@as(usize, 1), command_invalidations.len);
|
|
705
|
+
try std.testing.expect(!command_invalidations[0].layout_dirty);
|
|
706
|
+
try std.testing.expect(!command_invalidations[0].paint_dirty);
|
|
707
|
+
try std.testing.expect(command_invalidations[0].semantics_dirty);
|
|
708
|
+
try std.testing.expect(command_invalidations[0].dirty_bounds == null);
|
|
709
|
+
|
|
710
|
+
const action_invalidations = try WidgetLayoutTree.diff(action_previous, action, &invalidations_buffer);
|
|
711
|
+
try std.testing.expectEqual(@as(usize, 1), action_invalidations.len);
|
|
712
|
+
try std.testing.expect(!action_invalidations[0].layout_dirty);
|
|
713
|
+
try std.testing.expect(!action_invalidations[0].paint_dirty);
|
|
714
|
+
try std.testing.expect(action_invalidations[0].semantics_dirty);
|
|
715
|
+
|
|
716
|
+
const image_invalidations = try WidgetLayoutTree.diff(image_previous, image_next, &invalidations_buffer);
|
|
717
|
+
try std.testing.expectEqual(@as(usize, 1), image_invalidations.len);
|
|
718
|
+
try std.testing.expect(!image_invalidations[0].layout_dirty);
|
|
719
|
+
try std.testing.expect(image_invalidations[0].paint_dirty);
|
|
720
|
+
try std.testing.expect(image_invalidations[0].semantics_dirty);
|
|
721
|
+
try expectRect(geometry.RectF.init(8, 12, 80, 48), image_invalidations[0].dirty_bounds);
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
test "widget layout diff marks style changes as paint dirty" {
|
|
725
|
+
const previous_child = [_]Widget{.{
|
|
726
|
+
.id = 2,
|
|
727
|
+
.kind = .button,
|
|
728
|
+
.frame = geometry.RectF.init(10, 10, 100, 30),
|
|
729
|
+
.text = "Run",
|
|
730
|
+
}};
|
|
731
|
+
const styled_child = [_]Widget{.{
|
|
732
|
+
.id = 2,
|
|
733
|
+
.kind = .button,
|
|
734
|
+
.frame = geometry.RectF.init(10, 10, 100, 30),
|
|
735
|
+
.text = "Run",
|
|
736
|
+
.style = .{
|
|
737
|
+
.background = Color.rgb8(12, 18, 24),
|
|
738
|
+
.foreground = Color.rgb8(235, 241, 247),
|
|
739
|
+
.border = Color.rgb8(54, 64, 74),
|
|
740
|
+
.radius = 5,
|
|
741
|
+
.stroke_width = 2,
|
|
742
|
+
},
|
|
743
|
+
}};
|
|
744
|
+
|
|
745
|
+
var previous_nodes: [2]WidgetLayoutNode = undefined;
|
|
746
|
+
var styled_nodes: [2]WidgetLayoutNode = undefined;
|
|
747
|
+
const previous = try layoutWidgetTree(.{ .kind = .stack, .children = &previous_child }, geometry.RectF.init(0, 0, 140, 80), &previous_nodes);
|
|
748
|
+
const styled = try layoutWidgetTree(.{ .kind = .stack, .children = &styled_child }, geometry.RectF.init(0, 0, 140, 80), &styled_nodes);
|
|
749
|
+
|
|
750
|
+
var invalidations_buffer: [1]WidgetInvalidation = undefined;
|
|
751
|
+
const invalidations = try WidgetLayoutTree.diff(previous, styled, &invalidations_buffer);
|
|
752
|
+
try std.testing.expectEqual(@as(usize, 1), invalidations.len);
|
|
753
|
+
try std.testing.expect(!invalidations[0].layout_dirty);
|
|
754
|
+
try std.testing.expect(invalidations[0].paint_dirty);
|
|
755
|
+
try std.testing.expect(!invalidations[0].semantics_dirty);
|
|
756
|
+
try expectRect(geometry.RectF.init(9, 9, 102, 32), invalidations[0].dirty_bounds);
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
test "widget layout diff marks variant changes as paint dirty" {
|
|
760
|
+
const previous_child = [_]Widget{.{
|
|
761
|
+
.id = 2,
|
|
762
|
+
.kind = .button,
|
|
763
|
+
.frame = geometry.RectF.init(10, 10, 100, 30),
|
|
764
|
+
.text = "Run",
|
|
765
|
+
}};
|
|
766
|
+
const variant_child = [_]Widget{.{
|
|
767
|
+
.id = 2,
|
|
768
|
+
.kind = .button,
|
|
769
|
+
.frame = geometry.RectF.init(10, 10, 100, 30),
|
|
770
|
+
.text = "Run",
|
|
771
|
+
.variant = .primary,
|
|
772
|
+
}};
|
|
773
|
+
|
|
774
|
+
var previous_nodes: [2]WidgetLayoutNode = undefined;
|
|
775
|
+
var variant_nodes: [2]WidgetLayoutNode = undefined;
|
|
776
|
+
const previous = try layoutWidgetTree(.{ .kind = .stack, .children = &previous_child }, geometry.RectF.init(0, 0, 140, 80), &previous_nodes);
|
|
777
|
+
const variant = try layoutWidgetTree(.{ .kind = .stack, .children = &variant_child }, geometry.RectF.init(0, 0, 140, 80), &variant_nodes);
|
|
778
|
+
|
|
779
|
+
var invalidations_buffer: [1]WidgetInvalidation = undefined;
|
|
780
|
+
const invalidations = try WidgetLayoutTree.diff(previous, variant, &invalidations_buffer);
|
|
781
|
+
try std.testing.expectEqual(@as(usize, 1), invalidations.len);
|
|
782
|
+
try std.testing.expect(!invalidations[0].layout_dirty);
|
|
783
|
+
try std.testing.expect(invalidations[0].paint_dirty);
|
|
784
|
+
try std.testing.expect(!invalidations[0].semantics_dirty);
|
|
785
|
+
try expectRect(geometry.RectF.init(10, 10, 100, 30), invalidations[0].dirty_bounds);
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
test "widget layout diff marks size changes as paint dirty" {
|
|
789
|
+
const previous_child = [_]Widget{.{
|
|
790
|
+
.id = 2,
|
|
791
|
+
.kind = .button,
|
|
792
|
+
.frame = geometry.RectF.init(10, 10, 100, 30),
|
|
793
|
+
.text = "Run",
|
|
794
|
+
}};
|
|
795
|
+
const sized_child = [_]Widget{.{
|
|
796
|
+
.id = 2,
|
|
797
|
+
.kind = .button,
|
|
798
|
+
.frame = geometry.RectF.init(10, 10, 100, 30),
|
|
799
|
+
.text = "Run",
|
|
800
|
+
.size = .lg,
|
|
801
|
+
}};
|
|
802
|
+
|
|
803
|
+
var previous_nodes: [2]WidgetLayoutNode = undefined;
|
|
804
|
+
var sized_nodes: [2]WidgetLayoutNode = undefined;
|
|
805
|
+
const previous = try layoutWidgetTree(.{ .kind = .stack, .children = &previous_child }, geometry.RectF.init(0, 0, 140, 80), &previous_nodes);
|
|
806
|
+
const sized = try layoutWidgetTree(.{ .kind = .stack, .children = &sized_child }, geometry.RectF.init(0, 0, 140, 80), &sized_nodes);
|
|
807
|
+
|
|
808
|
+
var invalidations_buffer: [1]WidgetInvalidation = undefined;
|
|
809
|
+
const invalidations = try WidgetLayoutTree.diff(previous, sized, &invalidations_buffer);
|
|
810
|
+
try std.testing.expectEqual(@as(usize, 1), invalidations.len);
|
|
811
|
+
try std.testing.expect(!invalidations[0].layout_dirty);
|
|
812
|
+
try std.testing.expect(invalidations[0].paint_dirty);
|
|
813
|
+
try std.testing.expect(!invalidations[0].semantics_dirty);
|
|
814
|
+
try expectRect(geometry.RectF.init(10, 10, 100, 30), invalidations[0].dirty_bounds);
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
test "widget layout diff marks grid column changes as layout dirty" {
|
|
818
|
+
const children = [_]Widget{
|
|
819
|
+
.{ .id = 2, .kind = .text, .text = "One" },
|
|
820
|
+
.{ .id = 3, .kind = .text, .text = "Two" },
|
|
821
|
+
};
|
|
822
|
+
const previous_grid = Widget{ .id = 1, .kind = .grid, .layout = .{ .columns = 2, .gap = 8 }, .children = &children };
|
|
823
|
+
const next_grid = Widget{ .id = 1, .kind = .grid, .layout = .{ .columns = 1, .gap = 8 }, .children = &children };
|
|
824
|
+
|
|
825
|
+
var previous_nodes: [3]WidgetLayoutNode = undefined;
|
|
826
|
+
var next_nodes: [3]WidgetLayoutNode = undefined;
|
|
827
|
+
const previous = try layoutWidgetTree(previous_grid, geometry.RectF.init(0, 0, 208, 88), &previous_nodes);
|
|
828
|
+
const next = try layoutWidgetTree(next_grid, geometry.RectF.init(0, 0, 208, 88), &next_nodes);
|
|
829
|
+
|
|
830
|
+
var invalidations_buffer: [3]WidgetInvalidation = undefined;
|
|
831
|
+
const invalidations = try WidgetLayoutTree.diff(previous, next, &invalidations_buffer);
|
|
832
|
+
try std.testing.expectEqual(@as(usize, 3), invalidations.len);
|
|
833
|
+
try std.testing.expectEqual(@as(ObjectId, 1), invalidations[0].id);
|
|
834
|
+
try std.testing.expect(invalidations[0].layout_dirty);
|
|
835
|
+
try std.testing.expect(invalidations[0].paint_dirty);
|
|
836
|
+
try std.testing.expect(invalidations[0].semantics_dirty);
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
test "widget layout diff marks list spacing changes as layout dirty" {
|
|
840
|
+
const children = [_]Widget{
|
|
841
|
+
.{ .id = 2, .kind = .list_item, .frame = geometry.RectF.init(0, 0, 0, 32), .text = "One" },
|
|
842
|
+
.{ .id = 3, .kind = .list_item, .frame = geometry.RectF.init(0, 0, 0, 32), .text = "Two" },
|
|
843
|
+
};
|
|
844
|
+
const previous_list = Widget{ .id = 1, .kind = .list, .layout = .{ .gap = 4 }, .children = &children };
|
|
845
|
+
const next_list = Widget{ .id = 1, .kind = .list, .layout = .{ .gap = 8 }, .children = &children };
|
|
846
|
+
|
|
847
|
+
var previous_nodes: [3]WidgetLayoutNode = undefined;
|
|
848
|
+
var next_nodes: [3]WidgetLayoutNode = undefined;
|
|
849
|
+
const previous = try layoutWidgetTree(previous_list, geometry.RectF.init(0, 0, 120, 80), &previous_nodes);
|
|
850
|
+
const next = try layoutWidgetTree(next_list, geometry.RectF.init(0, 0, 120, 80), &next_nodes);
|
|
851
|
+
|
|
852
|
+
var invalidations_buffer: [3]WidgetInvalidation = undefined;
|
|
853
|
+
const invalidations = try WidgetLayoutTree.diff(previous, next, &invalidations_buffer);
|
|
854
|
+
try std.testing.expectEqual(@as(usize, 2), invalidations.len);
|
|
855
|
+
try std.testing.expectEqual(@as(ObjectId, 1), invalidations[0].id);
|
|
856
|
+
try std.testing.expect(invalidations[0].layout_dirty);
|
|
857
|
+
try std.testing.expectEqual(@as(ObjectId, 3), invalidations[1].id);
|
|
858
|
+
try std.testing.expect(invalidations[1].layout_dirty);
|
|
859
|
+
try std.testing.expect(invalidations[1].paint_dirty);
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
test "widget layout diff marks axis alignment changes as layout dirty" {
|
|
863
|
+
const children = [_]Widget{
|
|
864
|
+
.{ .id = 2, .kind = .text, .frame = geometry.RectF.init(0, 0, 40, 12), .text = "A" },
|
|
865
|
+
.{ .id = 3, .kind = .text, .frame = geometry.RectF.init(0, 0, 20, 16), .text = "B" },
|
|
866
|
+
};
|
|
867
|
+
const previous_row = Widget{
|
|
868
|
+
.id = 1,
|
|
869
|
+
.kind = .row,
|
|
870
|
+
.layout = .{ .gap = 4 },
|
|
871
|
+
.children = &children,
|
|
872
|
+
};
|
|
873
|
+
const next_row = Widget{
|
|
874
|
+
.id = 1,
|
|
875
|
+
.kind = .row,
|
|
876
|
+
.layout = .{
|
|
877
|
+
.gap = 4,
|
|
878
|
+
.main_alignment = .end,
|
|
879
|
+
.cross_alignment = .center,
|
|
880
|
+
},
|
|
881
|
+
.children = &children,
|
|
882
|
+
};
|
|
883
|
+
|
|
884
|
+
var previous_nodes: [3]WidgetLayoutNode = undefined;
|
|
885
|
+
var next_nodes: [3]WidgetLayoutNode = undefined;
|
|
886
|
+
const previous = try layoutWidgetTree(previous_row, geometry.RectF.init(0, 0, 120, 40), &previous_nodes);
|
|
887
|
+
const next = try layoutWidgetTree(next_row, geometry.RectF.init(0, 0, 120, 40), &next_nodes);
|
|
888
|
+
|
|
889
|
+
var invalidations_buffer: [3]WidgetInvalidation = undefined;
|
|
890
|
+
const invalidations = try WidgetLayoutTree.diff(previous, next, &invalidations_buffer);
|
|
891
|
+
try std.testing.expectEqual(@as(usize, 3), invalidations.len);
|
|
892
|
+
try std.testing.expectEqual(@as(ObjectId, 1), invalidations[0].id);
|
|
893
|
+
try std.testing.expect(invalidations[0].layout_dirty);
|
|
894
|
+
try std.testing.expectEqual(@as(ObjectId, 2), invalidations[1].id);
|
|
895
|
+
try std.testing.expect(invalidations[1].layout_dirty);
|
|
896
|
+
try std.testing.expectEqual(@as(ObjectId, 3), invalidations[2].id);
|
|
897
|
+
try std.testing.expect(invalidations[2].layout_dirty);
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
test "widget layout diff marks text alignment changes as paint dirty" {
|
|
901
|
+
const previous_text = Widget{
|
|
902
|
+
.id = 1,
|
|
903
|
+
.kind = .text,
|
|
904
|
+
.frame = geometry.RectF.init(10, 12, 120, 24),
|
|
905
|
+
.text = "Status",
|
|
906
|
+
};
|
|
907
|
+
const next_text = Widget{
|
|
908
|
+
.id = 1,
|
|
909
|
+
.kind = .text,
|
|
910
|
+
.frame = geometry.RectF.init(10, 12, 120, 24),
|
|
911
|
+
.text = "Status",
|
|
912
|
+
.text_alignment = .end,
|
|
913
|
+
};
|
|
914
|
+
|
|
915
|
+
var previous_nodes: [1]WidgetLayoutNode = undefined;
|
|
916
|
+
var next_nodes: [1]WidgetLayoutNode = undefined;
|
|
917
|
+
const previous = try layoutWidgetTree(previous_text, previous_text.frame, &previous_nodes);
|
|
918
|
+
const next = try layoutWidgetTree(next_text, next_text.frame, &next_nodes);
|
|
919
|
+
|
|
920
|
+
var invalidations_buffer: [1]WidgetInvalidation = undefined;
|
|
921
|
+
const invalidations = try WidgetLayoutTree.diff(previous, next, &invalidations_buffer);
|
|
922
|
+
try std.testing.expectEqual(@as(usize, 1), invalidations.len);
|
|
923
|
+
try std.testing.expect(!invalidations[0].layout_dirty);
|
|
924
|
+
try std.testing.expect(invalidations[0].paint_dirty);
|
|
925
|
+
try std.testing.expect(!invalidations[0].semantics_dirty);
|
|
926
|
+
try expectRect(geometry.RectF.init(10, 12, 120, 24), invalidations[0].dirty_bounds);
|
|
927
|
+
}
|
|
928
|
+
|
|
929
|
+
test "widget layout diff marks opacity changes as subtree paint dirty" {
|
|
930
|
+
const children = [_]Widget{.{
|
|
931
|
+
.id = 2,
|
|
932
|
+
.kind = .text,
|
|
933
|
+
.frame = geometry.RectF.init(20, 0, 30, 10),
|
|
934
|
+
.text = "Fade",
|
|
935
|
+
}};
|
|
936
|
+
const previous_stack = Widget{
|
|
937
|
+
.id = 1,
|
|
938
|
+
.kind = .stack,
|
|
939
|
+
.children = &children,
|
|
940
|
+
};
|
|
941
|
+
const next_stack = Widget{
|
|
942
|
+
.id = 1,
|
|
943
|
+
.kind = .stack,
|
|
944
|
+
.opacity = 0.5,
|
|
945
|
+
.children = &children,
|
|
946
|
+
};
|
|
947
|
+
|
|
948
|
+
var previous_nodes: [2]WidgetLayoutNode = undefined;
|
|
949
|
+
var next_nodes: [2]WidgetLayoutNode = undefined;
|
|
950
|
+
const previous = try layoutWidgetTree(previous_stack, geometry.RectF.init(0, 0, 10, 10), &previous_nodes);
|
|
951
|
+
const next = try layoutWidgetTree(next_stack, geometry.RectF.init(0, 0, 10, 10), &next_nodes);
|
|
952
|
+
|
|
953
|
+
var invalidations_buffer: [2]WidgetInvalidation = undefined;
|
|
954
|
+
const invalidations = try WidgetLayoutTree.diff(previous, next, &invalidations_buffer);
|
|
955
|
+
try std.testing.expectEqual(@as(usize, 1), invalidations.len);
|
|
956
|
+
try std.testing.expectEqual(@as(ObjectId, 1), invalidations[0].id);
|
|
957
|
+
try std.testing.expect(!invalidations[0].layout_dirty);
|
|
958
|
+
try std.testing.expect(invalidations[0].paint_dirty);
|
|
959
|
+
try std.testing.expect(!invalidations[0].semantics_dirty);
|
|
960
|
+
try expectRect(geometry.RectF.init(0, 0, 50, 10), invalidations[0].dirty_bounds);
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
test "widget layout diff marks transform changes as subtree paint dirty" {
|
|
964
|
+
const children = [_]Widget{.{
|
|
965
|
+
.id = 2,
|
|
966
|
+
.kind = .text,
|
|
967
|
+
.frame = geometry.RectF.init(20, 0, 30, 10),
|
|
968
|
+
.text = "Move",
|
|
969
|
+
}};
|
|
970
|
+
const previous_stack = Widget{
|
|
971
|
+
.id = 1,
|
|
972
|
+
.kind = .stack,
|
|
973
|
+
.children = &children,
|
|
974
|
+
};
|
|
975
|
+
const next_stack = Widget{
|
|
976
|
+
.id = 1,
|
|
977
|
+
.kind = .stack,
|
|
978
|
+
.transform = Affine.translate(10, 0),
|
|
979
|
+
.children = &children,
|
|
980
|
+
};
|
|
981
|
+
|
|
982
|
+
var previous_nodes: [2]WidgetLayoutNode = undefined;
|
|
983
|
+
var next_nodes: [2]WidgetLayoutNode = undefined;
|
|
984
|
+
const previous = try layoutWidgetTree(previous_stack, geometry.RectF.init(0, 0, 10, 10), &previous_nodes);
|
|
985
|
+
const next = try layoutWidgetTree(next_stack, geometry.RectF.init(0, 0, 10, 10), &next_nodes);
|
|
986
|
+
|
|
987
|
+
var invalidations_buffer: [2]WidgetInvalidation = undefined;
|
|
988
|
+
const invalidations = try WidgetLayoutTree.diff(previous, next, &invalidations_buffer);
|
|
989
|
+
try std.testing.expectEqual(@as(usize, 1), invalidations.len);
|
|
990
|
+
try std.testing.expectEqual(@as(ObjectId, 1), invalidations[0].id);
|
|
991
|
+
try std.testing.expect(!invalidations[0].layout_dirty);
|
|
992
|
+
try std.testing.expect(invalidations[0].paint_dirty);
|
|
993
|
+
try std.testing.expect(!invalidations[0].semantics_dirty);
|
|
994
|
+
try expectRect(geometry.RectF.init(0, 0, 60, 10), invalidations[0].dirty_bounds);
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
test "widget layout diff marks backdrop blur changes as paint dirty" {
|
|
998
|
+
const previous_stack = Widget{
|
|
999
|
+
.id = 1,
|
|
1000
|
+
.kind = .stack,
|
|
1001
|
+
};
|
|
1002
|
+
const next_stack = Widget{
|
|
1003
|
+
.id = 1,
|
|
1004
|
+
.kind = .stack,
|
|
1005
|
+
.backdrop_blur = 6,
|
|
1006
|
+
};
|
|
1007
|
+
|
|
1008
|
+
var previous_nodes: [1]WidgetLayoutNode = undefined;
|
|
1009
|
+
var next_nodes: [1]WidgetLayoutNode = undefined;
|
|
1010
|
+
const previous = try layoutWidgetTree(previous_stack, geometry.RectF.init(10, 12, 80, 40), &previous_nodes);
|
|
1011
|
+
const next = try layoutWidgetTree(next_stack, geometry.RectF.init(10, 12, 80, 40), &next_nodes);
|
|
1012
|
+
|
|
1013
|
+
var invalidations_buffer: [1]WidgetInvalidation = undefined;
|
|
1014
|
+
const invalidations = try WidgetLayoutTree.diff(previous, next, &invalidations_buffer);
|
|
1015
|
+
try std.testing.expectEqual(@as(usize, 1), invalidations.len);
|
|
1016
|
+
try std.testing.expectEqual(@as(ObjectId, 1), invalidations[0].id);
|
|
1017
|
+
try std.testing.expect(!invalidations[0].layout_dirty);
|
|
1018
|
+
try std.testing.expect(invalidations[0].paint_dirty);
|
|
1019
|
+
try std.testing.expect(!invalidations[0].semantics_dirty);
|
|
1020
|
+
try expectRect(geometry.RectF.init(4, 6, 92, 52), invalidations[0].dirty_bounds);
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
test "widget layout diff marks backdrop blur token changes as paint dirty" {
|
|
1024
|
+
const previous_stack = Widget{
|
|
1025
|
+
.id = 1,
|
|
1026
|
+
.kind = .stack,
|
|
1027
|
+
};
|
|
1028
|
+
const next_stack = Widget{
|
|
1029
|
+
.id = 1,
|
|
1030
|
+
.kind = .stack,
|
|
1031
|
+
.backdrop_blur_token = .sm,
|
|
1032
|
+
};
|
|
1033
|
+
|
|
1034
|
+
var previous_nodes: [1]WidgetLayoutNode = undefined;
|
|
1035
|
+
var next_nodes: [1]WidgetLayoutNode = undefined;
|
|
1036
|
+
const previous = try layoutWidgetTree(previous_stack, geometry.RectF.init(10, 12, 80, 40), &previous_nodes);
|
|
1037
|
+
const next = try layoutWidgetTree(next_stack, geometry.RectF.init(10, 12, 80, 40), &next_nodes);
|
|
1038
|
+
|
|
1039
|
+
var invalidations_buffer: [1]WidgetInvalidation = undefined;
|
|
1040
|
+
const invalidations = try WidgetLayoutTree.diff(previous, next, &invalidations_buffer);
|
|
1041
|
+
try std.testing.expectEqual(@as(usize, 1), invalidations.len);
|
|
1042
|
+
try std.testing.expectEqual(@as(ObjectId, 1), invalidations[0].id);
|
|
1043
|
+
try std.testing.expect(!invalidations[0].layout_dirty);
|
|
1044
|
+
try std.testing.expect(invalidations[0].paint_dirty);
|
|
1045
|
+
try std.testing.expect(!invalidations[0].semantics_dirty);
|
|
1046
|
+
try expectRect(geometry.RectF.init(2, 4, 96, 56), invalidations[0].dirty_bounds);
|
|
1047
|
+
}
|
|
1048
|
+
|
|
1049
|
+
test "widget layout diff uses custom blur tokens for paint dirty bounds" {
|
|
1050
|
+
const previous_stack = Widget{
|
|
1051
|
+
.id = 1,
|
|
1052
|
+
.kind = .stack,
|
|
1053
|
+
};
|
|
1054
|
+
const next_stack = Widget{
|
|
1055
|
+
.id = 1,
|
|
1056
|
+
.kind = .stack,
|
|
1057
|
+
.backdrop_blur_token = .md,
|
|
1058
|
+
};
|
|
1059
|
+
const tokens = DesignTokens{
|
|
1060
|
+
.blur = .{
|
|
1061
|
+
.sm = 8,
|
|
1062
|
+
.md = 24,
|
|
1063
|
+
},
|
|
1064
|
+
};
|
|
1065
|
+
|
|
1066
|
+
var previous_nodes: [1]WidgetLayoutNode = undefined;
|
|
1067
|
+
var next_nodes: [1]WidgetLayoutNode = undefined;
|
|
1068
|
+
const previous = try layoutWidgetTree(previous_stack, geometry.RectF.init(10, 12, 80, 40), &previous_nodes);
|
|
1069
|
+
const next = try layoutWidgetTree(next_stack, geometry.RectF.init(10, 12, 80, 40), &next_nodes);
|
|
1070
|
+
|
|
1071
|
+
var invalidations_buffer: [1]WidgetInvalidation = undefined;
|
|
1072
|
+
const invalidations = try WidgetLayoutTree.diffWithTokens(previous, next, tokens, &invalidations_buffer);
|
|
1073
|
+
try std.testing.expectEqual(@as(usize, 1), invalidations.len);
|
|
1074
|
+
try std.testing.expect(invalidations[0].paint_dirty);
|
|
1075
|
+
try expectRect(geometry.RectF.init(-14, -12, 128, 88), invalidations[0].dirty_bounds);
|
|
1076
|
+
}
|
|
1077
|
+
|
|
1078
|
+
test "widget layout diff clips paint dirtiness to clip content ancestors" {
|
|
1079
|
+
const previous_children = [_]Widget{.{
|
|
1080
|
+
.id = 2,
|
|
1081
|
+
.kind = .text,
|
|
1082
|
+
.frame = geometry.RectF.init(40, 0, 40, 20),
|
|
1083
|
+
.text = "One",
|
|
1084
|
+
}};
|
|
1085
|
+
const next_children = [_]Widget{.{
|
|
1086
|
+
.id = 2,
|
|
1087
|
+
.kind = .text,
|
|
1088
|
+
.frame = geometry.RectF.init(40, 0, 40, 20),
|
|
1089
|
+
.text = "Two",
|
|
1090
|
+
}};
|
|
1091
|
+
const previous_stack = Widget{
|
|
1092
|
+
.id = 1,
|
|
1093
|
+
.kind = .stack,
|
|
1094
|
+
.layout = .{ .clip_content = true },
|
|
1095
|
+
.children = &previous_children,
|
|
1096
|
+
};
|
|
1097
|
+
const next_stack = Widget{
|
|
1098
|
+
.id = 1,
|
|
1099
|
+
.kind = .stack,
|
|
1100
|
+
.layout = .{ .clip_content = true },
|
|
1101
|
+
.children = &next_children,
|
|
1102
|
+
};
|
|
1103
|
+
|
|
1104
|
+
var previous_nodes: [2]WidgetLayoutNode = undefined;
|
|
1105
|
+
var next_nodes: [2]WidgetLayoutNode = undefined;
|
|
1106
|
+
const previous = try layoutWidgetTree(previous_stack, geometry.RectF.init(0, 0, 50, 20), &previous_nodes);
|
|
1107
|
+
const next = try layoutWidgetTree(next_stack, geometry.RectF.init(0, 0, 50, 20), &next_nodes);
|
|
1108
|
+
|
|
1109
|
+
var invalidations_buffer: [2]WidgetInvalidation = undefined;
|
|
1110
|
+
const invalidations = try WidgetLayoutTree.diff(previous, next, &invalidations_buffer);
|
|
1111
|
+
try std.testing.expectEqual(@as(usize, 1), invalidations.len);
|
|
1112
|
+
try std.testing.expectEqual(@as(ObjectId, 2), invalidations[0].id);
|
|
1113
|
+
try std.testing.expect(invalidations[0].paint_dirty);
|
|
1114
|
+
try expectRect(geometry.RectF.init(40, 0, 10, 20), invalidations[0].dirty_bounds);
|
|
1115
|
+
}
|
|
1116
|
+
|
|
1117
|
+
test "widget layout diff marks scroll offset changes as child layout dirty" {
|
|
1118
|
+
const children = [_]Widget{
|
|
1119
|
+
.{ .id = 2, .kind = .button, .frame = geometry.RectF.init(0, 0, 0, 32), .text = "One" },
|
|
1120
|
+
};
|
|
1121
|
+
const previous_scroll = Widget{ .id = 1, .kind = .scroll_view, .value = 0, .children = &children };
|
|
1122
|
+
const next_scroll = Widget{ .id = 1, .kind = .scroll_view, .value = 12, .children = &children };
|
|
1123
|
+
|
|
1124
|
+
var previous_nodes: [2]WidgetLayoutNode = undefined;
|
|
1125
|
+
var next_nodes: [2]WidgetLayoutNode = undefined;
|
|
1126
|
+
const previous = try layoutWidgetTree(previous_scroll, geometry.RectF.init(0, 0, 120, 60), &previous_nodes);
|
|
1127
|
+
const next = try layoutWidgetTree(next_scroll, geometry.RectF.init(0, 0, 120, 60), &next_nodes);
|
|
1128
|
+
|
|
1129
|
+
var invalidations_buffer: [2]WidgetInvalidation = undefined;
|
|
1130
|
+
const invalidations = try WidgetLayoutTree.diff(previous, next, &invalidations_buffer);
|
|
1131
|
+
try std.testing.expectEqual(@as(usize, 2), invalidations.len);
|
|
1132
|
+
try std.testing.expectEqual(@as(ObjectId, 1), invalidations[0].id);
|
|
1133
|
+
try std.testing.expect(invalidations[0].paint_dirty);
|
|
1134
|
+
try std.testing.expectEqual(@as(ObjectId, 2), invalidations[1].id);
|
|
1135
|
+
try std.testing.expect(invalidations[1].layout_dirty);
|
|
1136
|
+
try std.testing.expect(invalidations[1].paint_dirty);
|
|
1137
|
+
}
|
|
1138
|
+
|
|
1139
|
+
test "widget layout diff clips paint dirtiness to scroll ancestors" {
|
|
1140
|
+
const previous_children = [_]Widget{.{
|
|
1141
|
+
.id = 2,
|
|
1142
|
+
.kind = .button,
|
|
1143
|
+
.frame = geometry.RectF.init(0, 50, 0, 32),
|
|
1144
|
+
.text = "Tail",
|
|
1145
|
+
}};
|
|
1146
|
+
const pressed_children = [_]Widget{.{
|
|
1147
|
+
.id = 2,
|
|
1148
|
+
.kind = .button,
|
|
1149
|
+
.frame = geometry.RectF.init(0, 50, 0, 32),
|
|
1150
|
+
.text = "Tail",
|
|
1151
|
+
.state = .{ .pressed = true },
|
|
1152
|
+
}};
|
|
1153
|
+
const previous_scroll = Widget{ .id = 1, .kind = .scroll_view, .children = &previous_children };
|
|
1154
|
+
const pressed_scroll = Widget{ .id = 1, .kind = .scroll_view, .children = &pressed_children };
|
|
1155
|
+
|
|
1156
|
+
var previous_nodes: [2]WidgetLayoutNode = undefined;
|
|
1157
|
+
var pressed_nodes: [2]WidgetLayoutNode = undefined;
|
|
1158
|
+
const previous = try layoutWidgetTree(previous_scroll, geometry.RectF.init(0, 0, 120, 60), &previous_nodes);
|
|
1159
|
+
const pressed = try layoutWidgetTree(pressed_scroll, geometry.RectF.init(0, 0, 120, 60), &pressed_nodes);
|
|
1160
|
+
|
|
1161
|
+
var invalidations_buffer: [2]WidgetInvalidation = undefined;
|
|
1162
|
+
const invalidations = try WidgetLayoutTree.diff(previous, pressed, &invalidations_buffer);
|
|
1163
|
+
try std.testing.expectEqual(@as(usize, 1), invalidations.len);
|
|
1164
|
+
try std.testing.expectEqual(WidgetInvalidationKind.changed, invalidations[0].kind);
|
|
1165
|
+
try std.testing.expectEqual(@as(ObjectId, 2), invalidations[0].id);
|
|
1166
|
+
try std.testing.expect(!invalidations[0].layout_dirty);
|
|
1167
|
+
try std.testing.expect(invalidations[0].paint_dirty);
|
|
1168
|
+
try expectRect(geometry.RectF.init(0, 50, 120, 10), invalidations[0].dirty_bounds);
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1171
|
+
test "widget layout diff reports duplicate ids and output overflow" {
|
|
1172
|
+
const duplicate_children = [_]Widget{
|
|
1173
|
+
.{ .id = 2, .kind = .text, .text = "One" },
|
|
1174
|
+
.{ .id = 2, .kind = .text, .text = "Two" },
|
|
1175
|
+
};
|
|
1176
|
+
const changed_children = [_]Widget{.{
|
|
1177
|
+
.id = 3,
|
|
1178
|
+
.kind = .text,
|
|
1179
|
+
.text = "Changed",
|
|
1180
|
+
}};
|
|
1181
|
+
|
|
1182
|
+
var duplicate_nodes: [3]WidgetLayoutNode = undefined;
|
|
1183
|
+
var previous_nodes: [2]WidgetLayoutNode = undefined;
|
|
1184
|
+
var next_nodes: [2]WidgetLayoutNode = undefined;
|
|
1185
|
+
const duplicate = try layoutWidgetTree(.{ .kind = .stack, .children = &duplicate_children }, geometry.RectF.init(0, 0, 100, 100), &duplicate_nodes);
|
|
1186
|
+
const previous = try layoutWidgetTree(.{ .kind = .stack, .children = &.{.{ .id = 3, .kind = .text, .text = "Old" }} }, geometry.RectF.init(0, 0, 100, 100), &previous_nodes);
|
|
1187
|
+
const next = try layoutWidgetTree(.{ .kind = .stack, .children = &changed_children }, geometry.RectF.init(0, 0, 100, 100), &next_nodes);
|
|
1188
|
+
|
|
1189
|
+
var invalidations_buffer: [1]WidgetInvalidation = undefined;
|
|
1190
|
+
try std.testing.expectError(error.DuplicateWidgetId, WidgetLayoutTree.diff(duplicate, next, &invalidations_buffer));
|
|
1191
|
+
|
|
1192
|
+
var empty_invalidations: [0]WidgetInvalidation = .{};
|
|
1193
|
+
try std.testing.expectError(error.WidgetInvalidationListFull, WidgetLayoutTree.diff(previous, next, &empty_invalidations));
|
|
1194
|
+
}
|
|
1195
|
+
|
|
1196
|
+
test "widget tree emits panel button text and progress commands" {
|
|
1197
|
+
const tokens: DesignTokens = .{};
|
|
1198
|
+
const children = [_]Widget{
|
|
1199
|
+
.{
|
|
1200
|
+
.id = 2,
|
|
1201
|
+
.kind = .button,
|
|
1202
|
+
.frame = geometry.RectF.init(16, 16, 120, 36),
|
|
1203
|
+
.text = "Launch",
|
|
1204
|
+
},
|
|
1205
|
+
.{
|
|
1206
|
+
.id = 3,
|
|
1207
|
+
.kind = .text,
|
|
1208
|
+
.frame = geometry.RectF.init(16, 64, 200, 20),
|
|
1209
|
+
.text = "Frames stay retained",
|
|
1210
|
+
},
|
|
1211
|
+
.{
|
|
1212
|
+
.id = 4,
|
|
1213
|
+
.kind = .progress,
|
|
1214
|
+
.frame = geometry.RectF.init(16, 96, 160, 8),
|
|
1215
|
+
.value = 0.25,
|
|
1216
|
+
},
|
|
1217
|
+
};
|
|
1218
|
+
const root = Widget{
|
|
1219
|
+
.id = 1,
|
|
1220
|
+
.kind = .panel,
|
|
1221
|
+
.frame = geometry.RectF.init(0, 0, 240, 128),
|
|
1222
|
+
.children = &children,
|
|
1223
|
+
};
|
|
1224
|
+
|
|
1225
|
+
var commands: [12]CanvasCommand = undefined;
|
|
1226
|
+
var builder = Builder.init(&commands);
|
|
1227
|
+
try emitWidgetTree(&builder, root, tokens);
|
|
1228
|
+
|
|
1229
|
+
const display_list = builder.displayList();
|
|
1230
|
+
// Panel shadow/fill/border, then the button's fill/border/label —
|
|
1231
|
+
// buttons are FLAT (no shadow command of their own; only elevated
|
|
1232
|
+
// surfaces cast).
|
|
1233
|
+
try std.testing.expectEqual(@as(usize, 9), display_list.commandCount());
|
|
1234
|
+
try std.testing.expectEqual(@as(?ObjectId, widgetPartId(1, 1)), display_list.commands[0].objectId());
|
|
1235
|
+
try std.testing.expect(display_list.commands[0] == .shadow);
|
|
1236
|
+
try std.testing.expectEqual(@as(?ObjectId, widgetPartId(1, 2)), display_list.commands[1].objectId());
|
|
1237
|
+
try std.testing.expect(display_list.commands[1] == .fill_rounded_rect);
|
|
1238
|
+
try std.testing.expectEqual(@as(?ObjectId, widgetPartId(2, 1)), display_list.commands[3].objectId());
|
|
1239
|
+
try std.testing.expect(display_list.commands[3] == .fill_rounded_rect);
|
|
1240
|
+
|
|
1241
|
+
switch (display_list.commands[5]) {
|
|
1242
|
+
.draw_text => |text| {
|
|
1243
|
+
try std.testing.expectEqual(@as(ObjectId, widgetPartId(2, 4)), text.id);
|
|
1244
|
+
try std.testing.expectEqualStrings("Launch", text.text);
|
|
1245
|
+
},
|
|
1246
|
+
else => return error.TestUnexpectedResult,
|
|
1247
|
+
}
|
|
1248
|
+
switch (display_list.commands[6]) {
|
|
1249
|
+
.draw_text => |text| {
|
|
1250
|
+
try std.testing.expectEqual(@as(ObjectId, widgetPartId(3, 1)), text.id);
|
|
1251
|
+
try std.testing.expectEqualStrings("Frames stay retained", text.text);
|
|
1252
|
+
},
|
|
1253
|
+
else => return error.TestUnexpectedResult,
|
|
1254
|
+
}
|
|
1255
|
+
switch (display_list.commands[8]) {
|
|
1256
|
+
.fill_rounded_rect => |fill| {
|
|
1257
|
+
try std.testing.expectEqual(@as(ObjectId, widgetPartId(4, 2)), fill.id);
|
|
1258
|
+
try expectRect(geometry.RectF.init(16, 96, 40, 8), fill.rect);
|
|
1259
|
+
try expectFillColor(tokens.colors.accent, fill.fill);
|
|
1260
|
+
},
|
|
1261
|
+
else => return error.TestUnexpectedResult,
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
|
|
1265
|
+
test "widget tree emits backdrop blur before widget content" {
|
|
1266
|
+
const children = [_]Widget{.{
|
|
1267
|
+
.id = 2,
|
|
1268
|
+
.kind = .text,
|
|
1269
|
+
.frame = geometry.RectF.init(18, 24, 100, 18),
|
|
1270
|
+
.text = "Glass",
|
|
1271
|
+
}};
|
|
1272
|
+
const root = Widget{
|
|
1273
|
+
.id = 1,
|
|
1274
|
+
.kind = .stack,
|
|
1275
|
+
.frame = geometry.RectF.init(10, 12, 140, 72),
|
|
1276
|
+
.backdrop_blur = 8,
|
|
1277
|
+
.children = &children,
|
|
1278
|
+
};
|
|
1279
|
+
|
|
1280
|
+
var commands: [2]CanvasCommand = undefined;
|
|
1281
|
+
var builder = Builder.init(&commands);
|
|
1282
|
+
try emitWidgetTree(&builder, root, .{});
|
|
1283
|
+
|
|
1284
|
+
const display_list = builder.displayList();
|
|
1285
|
+
try std.testing.expectEqual(@as(usize, 2), display_list.commandCount());
|
|
1286
|
+
switch (display_list.commands[0]) {
|
|
1287
|
+
.blur => |blur| {
|
|
1288
|
+
try std.testing.expectEqual(@as(ObjectId, widgetPartId(1, 12)), blur.id);
|
|
1289
|
+
try expectRect(geometry.RectF.init(10, 12, 140, 72), blur.rect);
|
|
1290
|
+
try std.testing.expectEqual(@as(f32, 8), blur.radius);
|
|
1291
|
+
},
|
|
1292
|
+
else => return error.TestUnexpectedResult,
|
|
1293
|
+
}
|
|
1294
|
+
switch (display_list.commands[1]) {
|
|
1295
|
+
.draw_text => |text| {
|
|
1296
|
+
try std.testing.expectEqual(@as(ObjectId, widgetPartId(2, 1)), text.id);
|
|
1297
|
+
try std.testing.expectEqualStrings("Glass", text.text);
|
|
1298
|
+
},
|
|
1299
|
+
else => return error.TestUnexpectedResult,
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1302
|
+
|
|
1303
|
+
test "widget tree resolves backdrop blur tokens from design tokens" {
|
|
1304
|
+
const children = [_]Widget{.{
|
|
1305
|
+
.id = 2,
|
|
1306
|
+
.kind = .text,
|
|
1307
|
+
.frame = geometry.RectF.init(18, 24, 100, 18),
|
|
1308
|
+
.text = "Glass",
|
|
1309
|
+
}};
|
|
1310
|
+
const root = Widget{
|
|
1311
|
+
.id = 1,
|
|
1312
|
+
.kind = .stack,
|
|
1313
|
+
.frame = geometry.RectF.init(10, 12, 140, 72),
|
|
1314
|
+
.backdrop_blur_token = .md,
|
|
1315
|
+
.children = &children,
|
|
1316
|
+
};
|
|
1317
|
+
const tokens = DesignTokens{
|
|
1318
|
+
.blur = .{
|
|
1319
|
+
.sm = 6,
|
|
1320
|
+
.md = 18,
|
|
1321
|
+
},
|
|
1322
|
+
};
|
|
1323
|
+
|
|
1324
|
+
var commands: [2]CanvasCommand = undefined;
|
|
1325
|
+
var builder = Builder.init(&commands);
|
|
1326
|
+
try emitWidgetTree(&builder, root, tokens);
|
|
1327
|
+
|
|
1328
|
+
const display_list = builder.displayList();
|
|
1329
|
+
try std.testing.expectEqual(@as(usize, 2), display_list.commandCount());
|
|
1330
|
+
switch (display_list.commands[0]) {
|
|
1331
|
+
.blur => |blur| {
|
|
1332
|
+
try std.testing.expectEqual(@as(ObjectId, widgetPartId(1, 12)), blur.id);
|
|
1333
|
+
try expectRect(geometry.RectF.init(10, 12, 140, 72), blur.rect);
|
|
1334
|
+
try std.testing.expectEqual(@as(f32, 18), blur.radius);
|
|
1335
|
+
},
|
|
1336
|
+
else => return error.TestUnexpectedResult,
|
|
1337
|
+
}
|
|
1338
|
+
}
|
|
1339
|
+
|
|
1340
|
+
test "widget display list skips hidden subtrees" {
|
|
1341
|
+
const hidden_button = Widget{
|
|
1342
|
+
.id = 2,
|
|
1343
|
+
.kind = .button,
|
|
1344
|
+
.frame = geometry.RectF.init(10, 10, 100, 32),
|
|
1345
|
+
.text = "Hidden",
|
|
1346
|
+
.semantics = .{ .hidden = true },
|
|
1347
|
+
};
|
|
1348
|
+
var hidden_commands: [4]CanvasCommand = undefined;
|
|
1349
|
+
var hidden_builder = Builder.init(&hidden_commands);
|
|
1350
|
+
try emitWidgetTree(&hidden_builder, hidden_button, .{});
|
|
1351
|
+
try std.testing.expectEqual(@as(usize, 0), hidden_builder.displayList().commandCount());
|
|
1352
|
+
|
|
1353
|
+
const hidden_scroll_children = [_]Widget{.{
|
|
1354
|
+
.id = 4,
|
|
1355
|
+
.kind = .button,
|
|
1356
|
+
.frame = geometry.RectF.init(0, 0, 0, 32),
|
|
1357
|
+
.text = "Nested",
|
|
1358
|
+
}};
|
|
1359
|
+
const children = [_]Widget{
|
|
1360
|
+
.{
|
|
1361
|
+
.id = 2,
|
|
1362
|
+
.kind = .button,
|
|
1363
|
+
.frame = geometry.RectF.init(16, 16, 120, 36),
|
|
1364
|
+
.text = "Visible",
|
|
1365
|
+
},
|
|
1366
|
+
.{
|
|
1367
|
+
.id = 3,
|
|
1368
|
+
.kind = .scroll_view,
|
|
1369
|
+
.frame = geometry.RectF.init(16, 64, 160, 48),
|
|
1370
|
+
.semantics = .{ .hidden = true },
|
|
1371
|
+
.children = &hidden_scroll_children,
|
|
1372
|
+
},
|
|
1373
|
+
.{
|
|
1374
|
+
.id = 5,
|
|
1375
|
+
.kind = .text,
|
|
1376
|
+
.frame = geometry.RectF.init(16, 124, 120, 20),
|
|
1377
|
+
.text = "Visible text",
|
|
1378
|
+
},
|
|
1379
|
+
};
|
|
1380
|
+
const root = Widget{
|
|
1381
|
+
.id = 1,
|
|
1382
|
+
.kind = .panel,
|
|
1383
|
+
.frame = geometry.RectF.init(0, 0, 220, 160),
|
|
1384
|
+
.children = &children,
|
|
1385
|
+
};
|
|
1386
|
+
|
|
1387
|
+
var nodes: [5]WidgetLayoutNode = undefined;
|
|
1388
|
+
const layout = try layoutWidgetTree(root, root.frame, &nodes);
|
|
1389
|
+
|
|
1390
|
+
var commands: [16]CanvasCommand = undefined;
|
|
1391
|
+
var builder = Builder.init(&commands);
|
|
1392
|
+
try layout.emitDisplayList(&builder, .{});
|
|
1393
|
+
|
|
1394
|
+
const display_list = builder.displayList();
|
|
1395
|
+
var saw_visible_button = false;
|
|
1396
|
+
var saw_visible_text = false;
|
|
1397
|
+
for (display_list.commands) |command| {
|
|
1398
|
+
if (command.objectId()) |id| {
|
|
1399
|
+
if (id == widgetPartId(2, 1)) saw_visible_button = true;
|
|
1400
|
+
if (id == widgetPartId(5, 1)) saw_visible_text = true;
|
|
1401
|
+
if ((id > widgetPartId(3, 0) and id < widgetPartId(4, 0)) or
|
|
1402
|
+
(id > widgetPartId(4, 0) and id < widgetPartId(5, 0)))
|
|
1403
|
+
{
|
|
1404
|
+
return error.TestUnexpectedResult;
|
|
1405
|
+
}
|
|
1406
|
+
}
|
|
1407
|
+
}
|
|
1408
|
+
try std.testing.expect(saw_visible_button);
|
|
1409
|
+
try std.testing.expect(saw_visible_text);
|
|
1410
|
+
}
|
|
1411
|
+
|
|
1412
|
+
test "widget display list renders through reference surface" {
|
|
1413
|
+
const tokens: DesignTokens = .{};
|
|
1414
|
+
const children = [_]Widget{
|
|
1415
|
+
.{
|
|
1416
|
+
.id = 2,
|
|
1417
|
+
.kind = .button,
|
|
1418
|
+
.frame = geometry.RectF.init(16, 16, 120, 36),
|
|
1419
|
+
.text = "Launch",
|
|
1420
|
+
},
|
|
1421
|
+
.{
|
|
1422
|
+
.id = 3,
|
|
1423
|
+
.kind = .text,
|
|
1424
|
+
.frame = geometry.RectF.init(16, 64, 200, 20),
|
|
1425
|
+
.text = "Frames stay retained",
|
|
1426
|
+
},
|
|
1427
|
+
.{
|
|
1428
|
+
.id = 4,
|
|
1429
|
+
.kind = .progress,
|
|
1430
|
+
.frame = geometry.RectF.init(16, 96, 160, 8),
|
|
1431
|
+
.value = 0.25,
|
|
1432
|
+
},
|
|
1433
|
+
};
|
|
1434
|
+
const root = Widget{
|
|
1435
|
+
.id = 1,
|
|
1436
|
+
.kind = .panel,
|
|
1437
|
+
.frame = geometry.RectF.init(0, 0, 240, 128),
|
|
1438
|
+
.children = &children,
|
|
1439
|
+
};
|
|
1440
|
+
|
|
1441
|
+
var layout_nodes: [4]WidgetLayoutNode = undefined;
|
|
1442
|
+
const layout = try layoutWidgetTree(root, root.frame, &layout_nodes);
|
|
1443
|
+
|
|
1444
|
+
var commands: [12]CanvasCommand = undefined;
|
|
1445
|
+
var builder = Builder.init(&commands);
|
|
1446
|
+
try layout.emitDisplayList(&builder, tokens);
|
|
1447
|
+
|
|
1448
|
+
var render_commands: [12]RenderCommand = undefined;
|
|
1449
|
+
var render_batches: [12]RenderBatch = undefined;
|
|
1450
|
+
var resources: [8]RenderResource = undefined;
|
|
1451
|
+
var resource_cache_entries: [8]RenderResourceCacheEntry = undefined;
|
|
1452
|
+
var resource_cache_actions: [8]RenderResourceCacheAction = undefined;
|
|
1453
|
+
var glyphs: [64]GlyphAtlasEntry = undefined;
|
|
1454
|
+
var glyph_cache_entries: [64]GlyphAtlasCacheEntry = undefined;
|
|
1455
|
+
var glyph_cache_actions: [64]GlyphAtlasCacheAction = undefined;
|
|
1456
|
+
var changes: [0]DiffChange = .{};
|
|
1457
|
+
const frame = try builder.displayList().framePlan(null, .{
|
|
1458
|
+
.surface_size = geometry.SizeF.init(240, 128),
|
|
1459
|
+
}, .{
|
|
1460
|
+
.render_commands = &render_commands,
|
|
1461
|
+
.render_batches = &render_batches,
|
|
1462
|
+
.resources = &resources,
|
|
1463
|
+
.resource_cache_entries = &resource_cache_entries,
|
|
1464
|
+
.resource_cache_actions = &resource_cache_actions,
|
|
1465
|
+
.glyph_atlas_entries = &glyphs,
|
|
1466
|
+
.glyph_atlas_cache_entries = &glyph_cache_entries,
|
|
1467
|
+
.glyph_atlas_cache_actions = &glyph_cache_actions,
|
|
1468
|
+
.changes = &changes,
|
|
1469
|
+
});
|
|
1470
|
+
|
|
1471
|
+
try std.testing.expect(frame.requiresRender());
|
|
1472
|
+
try std.testing.expectEqual(CanvasRenderPassLoadAction.clear, frame.renderPass().loadAction());
|
|
1473
|
+
// Panel shadow/fill/border + flat button fill/border/label + text +
|
|
1474
|
+
// progress track/fill: buttons cast no shadow of their own.
|
|
1475
|
+
try std.testing.expectEqual(@as(usize, 9), frame.renderPass().commandCount());
|
|
1476
|
+
|
|
1477
|
+
var pixels: [240 * 128 * 4]u8 = undefined;
|
|
1478
|
+
const surface = try ReferenceRenderSurface.init(240, 128, &pixels);
|
|
1479
|
+
try surface.renderPass(frame.renderPass(), Color.rgb8(0, 0, 0));
|
|
1480
|
+
|
|
1481
|
+
try expectPixelRgba8(.{ 255, 255, 255, 255 }, surface, 220, 20);
|
|
1482
|
+
// The progress fill is the monochrome near-black primary of the
|
|
1483
|
+
// house register.
|
|
1484
|
+
try expectPixelRgba8(.{ 23, 23, 23, 255 }, surface, 20, 100);
|
|
1485
|
+
}
|
|
1486
|
+
|
|
1487
|
+
test "widget emitter applies button state tokens" {
|
|
1488
|
+
const tokens = DesignTokens{
|
|
1489
|
+
.colors = .{
|
|
1490
|
+
.accent = Color.rgb8(10, 20, 30),
|
|
1491
|
+
.accent_text = Color.rgb8(240, 241, 242),
|
|
1492
|
+
.focus_ring = Color.rgb8(1, 2, 3),
|
|
1493
|
+
},
|
|
1494
|
+
.stroke = .{ .focus = 3 },
|
|
1495
|
+
};
|
|
1496
|
+
const button = Widget{
|
|
1497
|
+
.id = 7,
|
|
1498
|
+
.kind = .button,
|
|
1499
|
+
.frame = geometry.RectF.init(0, 0, 140, 40),
|
|
1500
|
+
.text = "Pressed",
|
|
1501
|
+
.state = .{ .pressed = true, .focused = true },
|
|
1502
|
+
};
|
|
1503
|
+
|
|
1504
|
+
var commands: [5]CanvasCommand = undefined;
|
|
1505
|
+
var builder = Builder.init(&commands);
|
|
1506
|
+
try emitWidgetTree(&builder, button, tokens);
|
|
1507
|
+
|
|
1508
|
+
// Fill + border + focus ring + label — flat, no shadow command.
|
|
1509
|
+
const display_list = builder.displayList();
|
|
1510
|
+
try std.testing.expectEqual(@as(usize, 4), display_list.commandCount());
|
|
1511
|
+
switch (display_list.commands[0]) {
|
|
1512
|
+
.fill_rounded_rect => |fill| try expectFillColor(tokens.colors.accent, fill.fill),
|
|
1513
|
+
else => return error.TestUnexpectedResult,
|
|
1514
|
+
}
|
|
1515
|
+
switch (display_list.commands[2]) {
|
|
1516
|
+
.stroke_rect => |stroke| {
|
|
1517
|
+
try std.testing.expectEqual(@as(ObjectId, widgetPartId(7, 3)), stroke.id);
|
|
1518
|
+
try std.testing.expectEqual(@as(f32, 3), stroke.stroke.width);
|
|
1519
|
+
try expectFillColor(tokens.colors.focus_ring, stroke.stroke.fill);
|
|
1520
|
+
},
|
|
1521
|
+
else => return error.TestUnexpectedResult,
|
|
1522
|
+
}
|
|
1523
|
+
switch (display_list.commands[3]) {
|
|
1524
|
+
.draw_text => |text| try std.testing.expectEqualDeep(tokens.colors.accent_text, text.color),
|
|
1525
|
+
else => return error.TestUnexpectedResult,
|
|
1526
|
+
}
|
|
1527
|
+
}
|
|
1528
|
+
|
|
1529
|
+
test "widget emitter applies button variants" {
|
|
1530
|
+
const tokens = DesignTokens{
|
|
1531
|
+
.colors = .{
|
|
1532
|
+
.surface = Color.rgb8(250, 250, 250),
|
|
1533
|
+
.surface_subtle = Color.rgb8(242, 244, 246),
|
|
1534
|
+
.border = Color.rgb8(200, 205, 210),
|
|
1535
|
+
.text = Color.rgb8(20, 24, 28),
|
|
1536
|
+
.accent = Color.rgb8(30, 80, 210),
|
|
1537
|
+
.accent_text = Color.rgb8(255, 255, 255),
|
|
1538
|
+
.destructive = Color.rgb8(210, 40, 40),
|
|
1539
|
+
.destructive_text = Color.rgb8(255, 255, 255),
|
|
1540
|
+
},
|
|
1541
|
+
};
|
|
1542
|
+
|
|
1543
|
+
var commands: [18]CanvasCommand = undefined;
|
|
1544
|
+
var builder = Builder.init(&commands);
|
|
1545
|
+
try emitWidgetTree(&builder, .{ .id = 20, .kind = .button, .frame = geometry.RectF.init(0, 0, 120, 32), .text = "Primary", .variant = .primary }, tokens);
|
|
1546
|
+
try emitWidgetTree(&builder, .{ .id = 21, .kind = .button, .frame = geometry.RectF.init(0, 40, 120, 32), .text = "Secondary", .variant = .secondary }, tokens);
|
|
1547
|
+
try emitWidgetTree(&builder, .{ .id = 22, .kind = .button, .frame = geometry.RectF.init(0, 80, 120, 32), .text = "Outline", .variant = .outline }, tokens);
|
|
1548
|
+
try emitWidgetTree(&builder, .{ .id = 23, .kind = .button, .frame = geometry.RectF.init(0, 120, 120, 32), .text = "Ghost", .variant = .ghost }, tokens);
|
|
1549
|
+
try emitWidgetTree(&builder, .{ .id = 24, .kind = .button, .frame = geometry.RectF.init(0, 160, 120, 32), .text = "Delete", .variant = .destructive }, tokens);
|
|
1550
|
+
|
|
1551
|
+
// Every variant is FLAT (no shadow command): 5 x (fill + border +
|
|
1552
|
+
// label). Destructive is the quiet red chip — the destructive hue
|
|
1553
|
+
// as a 10% wash under destructive-red text, borderless.
|
|
1554
|
+
const display_list = builder.displayList();
|
|
1555
|
+
try std.testing.expectEqual(@as(usize, 15), display_list.commandCount());
|
|
1556
|
+
switch (display_list.commands[0]) {
|
|
1557
|
+
.fill_rounded_rect => |fill| try expectFillColor(tokens.colors.accent, fill.fill),
|
|
1558
|
+
else => return error.TestUnexpectedResult,
|
|
1559
|
+
}
|
|
1560
|
+
switch (display_list.commands[1]) {
|
|
1561
|
+
.stroke_rect => |stroke| try expectFillColor(tokens.colors.accent, stroke.stroke.fill),
|
|
1562
|
+
else => return error.TestUnexpectedResult,
|
|
1563
|
+
}
|
|
1564
|
+
switch (display_list.commands[3]) {
|
|
1565
|
+
.fill_rounded_rect => |fill| try expectFillColor(tokens.colors.surface_subtle, fill.fill),
|
|
1566
|
+
else => return error.TestUnexpectedResult,
|
|
1567
|
+
}
|
|
1568
|
+
switch (display_list.commands[6]) {
|
|
1569
|
+
.fill_rounded_rect => |fill| try expectFillColor(transparentColor(), fill.fill),
|
|
1570
|
+
else => return error.TestUnexpectedResult,
|
|
1571
|
+
}
|
|
1572
|
+
switch (display_list.commands[9]) {
|
|
1573
|
+
.fill_rounded_rect => |fill| try expectFillColor(transparentColor(), fill.fill),
|
|
1574
|
+
else => return error.TestUnexpectedResult,
|
|
1575
|
+
}
|
|
1576
|
+
switch (display_list.commands[10]) {
|
|
1577
|
+
.stroke_rect => |stroke| try std.testing.expectEqual(@as(f32, 0), stroke.stroke.width),
|
|
1578
|
+
else => return error.TestUnexpectedResult,
|
|
1579
|
+
}
|
|
1580
|
+
switch (display_list.commands[12]) {
|
|
1581
|
+
.fill_rounded_rect => |fill| try expectFillColor(colorWithAlpha(tokens.colors.destructive, 0.10), fill.fill),
|
|
1582
|
+
else => return error.TestUnexpectedResult,
|
|
1583
|
+
}
|
|
1584
|
+
switch (display_list.commands[13]) {
|
|
1585
|
+
.stroke_rect => |stroke| try std.testing.expectEqual(@as(f32, 0), stroke.stroke.width),
|
|
1586
|
+
else => return error.TestUnexpectedResult,
|
|
1587
|
+
}
|
|
1588
|
+
switch (display_list.commands[14]) {
|
|
1589
|
+
.draw_text => |text| try std.testing.expectEqualDeep(tokens.colors.destructive, text.color),
|
|
1590
|
+
else => return error.TestUnexpectedResult,
|
|
1591
|
+
}
|
|
1592
|
+
}
|
|
1593
|
+
|
|
1594
|
+
test "widget emitter applies button variant control tokens" {
|
|
1595
|
+
const tokens = DesignTokens{
|
|
1596
|
+
.controls = .{
|
|
1597
|
+
.button_primary = .{
|
|
1598
|
+
.background = Color.rgb8(12, 44, 88),
|
|
1599
|
+
.hover_background = Color.rgb8(14, 54, 108),
|
|
1600
|
+
.active_background = Color.rgb8(8, 32, 72),
|
|
1601
|
+
.foreground = Color.rgb8(244, 248, 255),
|
|
1602
|
+
.border = Color.rgb8(20, 70, 120),
|
|
1603
|
+
},
|
|
1604
|
+
.button_secondary = .{
|
|
1605
|
+
.background = Color.rgb8(230, 235, 240),
|
|
1606
|
+
.hover_background = Color.rgb8(210, 220, 230),
|
|
1607
|
+
.active_background = Color.rgb8(190, 205, 220),
|
|
1608
|
+
.foreground = Color.rgb8(10, 20, 30),
|
|
1609
|
+
.border = Color.rgb8(120, 140, 160),
|
|
1610
|
+
},
|
|
1611
|
+
},
|
|
1612
|
+
};
|
|
1613
|
+
|
|
1614
|
+
var commands: [12]CanvasCommand = undefined;
|
|
1615
|
+
var builder = Builder.init(&commands);
|
|
1616
|
+
try emitWidgetTree(&builder, .{ .id = 30, .kind = .button, .frame = geometry.RectF.init(0, 0, 120, 32), .text = "Primary", .variant = .primary, .state = .{ .hovered = true } }, tokens);
|
|
1617
|
+
try emitWidgetTree(&builder, .{ .id = 31, .kind = .button, .frame = geometry.RectF.init(0, 40, 120, 32), .text = "Secondary", .variant = .secondary, .state = .{ .pressed = true } }, tokens);
|
|
1618
|
+
try emitWidgetTree(&builder, .{ .id = 32, .kind = .button, .frame = geometry.RectF.init(0, 80, 120, 32), .text = "Local", .variant = .primary, .style = .{ .accent = Color.rgb8(1, 2, 3), .accent_foreground = Color.rgb8(4, 5, 6), .border = Color.rgb8(7, 8, 9) } }, tokens);
|
|
1619
|
+
|
|
1620
|
+
// Buttons are flat (no shadow command): 3 x (fill + border + label).
|
|
1621
|
+
const display_list = builder.displayList();
|
|
1622
|
+
try std.testing.expectEqual(@as(usize, 9), display_list.commandCount());
|
|
1623
|
+
switch (display_list.commands[0]) {
|
|
1624
|
+
.fill_rounded_rect => |fill| try expectFillColor(Color.rgb8(14, 54, 108), fill.fill),
|
|
1625
|
+
else => return error.TestUnexpectedResult,
|
|
1626
|
+
}
|
|
1627
|
+
switch (display_list.commands[1]) {
|
|
1628
|
+
.stroke_rect => |stroke| try expectFillColor(Color.rgb8(20, 70, 120), stroke.stroke.fill),
|
|
1629
|
+
else => return error.TestUnexpectedResult,
|
|
1630
|
+
}
|
|
1631
|
+
switch (display_list.commands[2]) {
|
|
1632
|
+
.draw_text => |text| try std.testing.expectEqualDeep(Color.rgb8(244, 248, 255), text.color),
|
|
1633
|
+
else => return error.TestUnexpectedResult,
|
|
1634
|
+
}
|
|
1635
|
+
switch (display_list.commands[3]) {
|
|
1636
|
+
.fill_rounded_rect => |fill| try expectFillColor(Color.rgb8(190, 205, 220), fill.fill),
|
|
1637
|
+
else => return error.TestUnexpectedResult,
|
|
1638
|
+
}
|
|
1639
|
+
switch (display_list.commands[5]) {
|
|
1640
|
+
.draw_text => |text| try std.testing.expectEqualDeep(Color.rgb8(10, 20, 30), text.color),
|
|
1641
|
+
else => return error.TestUnexpectedResult,
|
|
1642
|
+
}
|
|
1643
|
+
switch (display_list.commands[6]) {
|
|
1644
|
+
.fill_rounded_rect => |fill| try expectFillColor(Color.rgb8(1, 2, 3), fill.fill),
|
|
1645
|
+
else => return error.TestUnexpectedResult,
|
|
1646
|
+
}
|
|
1647
|
+
switch (display_list.commands[7]) {
|
|
1648
|
+
.stroke_rect => |stroke| try expectFillColor(Color.rgb8(7, 8, 9), stroke.stroke.fill),
|
|
1649
|
+
else => return error.TestUnexpectedResult,
|
|
1650
|
+
}
|
|
1651
|
+
switch (display_list.commands[8]) {
|
|
1652
|
+
.draw_text => |text| try std.testing.expectEqualDeep(Color.rgb8(4, 5, 6), text.color),
|
|
1653
|
+
else => return error.TestUnexpectedResult,
|
|
1654
|
+
}
|
|
1655
|
+
}
|
|
1656
|
+
|
|
1657
|
+
test "widget emitter applies input and list control tokens" {
|
|
1658
|
+
const tokens = DesignTokens{
|
|
1659
|
+
.controls = .{
|
|
1660
|
+
.input = .{
|
|
1661
|
+
.background = Color.rgb8(20, 24, 28),
|
|
1662
|
+
.foreground = Color.rgb8(238, 242, 246),
|
|
1663
|
+
.border = Color.rgb8(80, 90, 100),
|
|
1664
|
+
},
|
|
1665
|
+
.search_field = .{
|
|
1666
|
+
.background = Color.rgb8(24, 28, 32),
|
|
1667
|
+
.foreground = Color.rgb8(210, 220, 230),
|
|
1668
|
+
.border = Color.rgb8(90, 100, 110),
|
|
1669
|
+
},
|
|
1670
|
+
.textarea = .{
|
|
1671
|
+
.background = Color.rgb8(28, 32, 36),
|
|
1672
|
+
.foreground = Color.rgb8(236, 240, 244),
|
|
1673
|
+
.border = Color.rgb8(96, 106, 116),
|
|
1674
|
+
},
|
|
1675
|
+
.list_item = .{
|
|
1676
|
+
.hover_background = Color.rgb8(40, 48, 56),
|
|
1677
|
+
.active_background = Color.rgb8(52, 62, 72),
|
|
1678
|
+
.foreground = Color.rgb8(244, 248, 252),
|
|
1679
|
+
},
|
|
1680
|
+
},
|
|
1681
|
+
};
|
|
1682
|
+
|
|
1683
|
+
var commands: [24]CanvasCommand = undefined;
|
|
1684
|
+
var builder = Builder.init(&commands);
|
|
1685
|
+
try emitWidgetTree(&builder, .{ .id = 50, .kind = .input, .frame = geometry.RectF.init(0, 0, 160, 34), .text = "Input" }, tokens);
|
|
1686
|
+
try emitWidgetTree(&builder, .{ .id = 51, .kind = .search_field, .frame = geometry.RectF.init(0, 44, 180, 34), .semantics = .{ .label = "Search" } }, tokens);
|
|
1687
|
+
try emitWidgetTree(&builder, .{ .id = 52, .kind = .textarea, .frame = geometry.RectF.init(0, 88, 180, 72), .text = "Message" }, tokens);
|
|
1688
|
+
try emitWidgetTree(&builder, .{ .id = 53, .kind = .list_item, .frame = geometry.RectF.init(0, 168, 180, 30), .text = "Inbox", .state = .{ .selected = true } }, tokens);
|
|
1689
|
+
|
|
1690
|
+
const display_list = builder.displayList();
|
|
1691
|
+
// The search field's magnifier is now the vector `search` icon:
|
|
1692
|
+
// transform in, circle + handle stroke paths, inverse transform out.
|
|
1693
|
+
try std.testing.expectEqual(@as(usize, 17), display_list.commandCount());
|
|
1694
|
+
switch (display_list.commands[0]) {
|
|
1695
|
+
.fill_rounded_rect => |fill| try expectFillColor(Color.rgb8(20, 24, 28), fill.fill),
|
|
1696
|
+
else => return error.TestUnexpectedResult,
|
|
1697
|
+
}
|
|
1698
|
+
switch (display_list.commands[1]) {
|
|
1699
|
+
.stroke_rect => |stroke| try expectFillColor(Color.rgb8(80, 90, 100), stroke.stroke.fill),
|
|
1700
|
+
else => return error.TestUnexpectedResult,
|
|
1701
|
+
}
|
|
1702
|
+
switch (display_list.commands[2]) {
|
|
1703
|
+
.draw_text => |text| try std.testing.expectEqualDeep(Color.rgb8(238, 242, 246), text.color),
|
|
1704
|
+
else => return error.TestUnexpectedResult,
|
|
1705
|
+
}
|
|
1706
|
+
switch (display_list.commands[3]) {
|
|
1707
|
+
.fill_rounded_rect => |fill| try expectFillColor(Color.rgb8(24, 28, 32), fill.fill),
|
|
1708
|
+
else => return error.TestUnexpectedResult,
|
|
1709
|
+
}
|
|
1710
|
+
switch (display_list.commands[4]) {
|
|
1711
|
+
.stroke_rect => |stroke| try expectFillColor(Color.rgb8(90, 100, 110), stroke.stroke.fill),
|
|
1712
|
+
else => return error.TestUnexpectedResult,
|
|
1713
|
+
}
|
|
1714
|
+
switch (display_list.commands[6]) {
|
|
1715
|
+
.stroke_path => |stroke| try expectFillColor(Color.rgb8(210, 220, 230), stroke.stroke.fill),
|
|
1716
|
+
else => return error.TestUnexpectedResult,
|
|
1717
|
+
}
|
|
1718
|
+
switch (display_list.commands[9]) {
|
|
1719
|
+
.draw_text => |text| {
|
|
1720
|
+
try std.testing.expectEqualStrings("Search", text.text);
|
|
1721
|
+
try std.testing.expectEqualDeep(Color.rgb8(210, 220, 230), text.color);
|
|
1722
|
+
},
|
|
1723
|
+
else => return error.TestUnexpectedResult,
|
|
1724
|
+
}
|
|
1725
|
+
switch (display_list.commands[10]) {
|
|
1726
|
+
.fill_rounded_rect => |fill| try expectFillColor(Color.rgb8(28, 32, 36), fill.fill),
|
|
1727
|
+
else => return error.TestUnexpectedResult,
|
|
1728
|
+
}
|
|
1729
|
+
switch (display_list.commands[11]) {
|
|
1730
|
+
.stroke_rect => |stroke| try expectFillColor(Color.rgb8(96, 106, 116), stroke.stroke.fill),
|
|
1731
|
+
else => return error.TestUnexpectedResult,
|
|
1732
|
+
}
|
|
1733
|
+
switch (display_list.commands[12]) {
|
|
1734
|
+
.push_clip => {},
|
|
1735
|
+
else => return error.TestUnexpectedResult,
|
|
1736
|
+
}
|
|
1737
|
+
switch (display_list.commands[13]) {
|
|
1738
|
+
.draw_text => |text| try std.testing.expectEqualDeep(Color.rgb8(236, 240, 244), text.color),
|
|
1739
|
+
else => return error.TestUnexpectedResult,
|
|
1740
|
+
}
|
|
1741
|
+
try std.testing.expectEqual(CanvasCommand.pop_clip, display_list.commands[14]);
|
|
1742
|
+
switch (display_list.commands[15]) {
|
|
1743
|
+
.fill_rounded_rect => |fill| try expectFillColor(Color.rgb8(52, 62, 72), fill.fill),
|
|
1744
|
+
else => return error.TestUnexpectedResult,
|
|
1745
|
+
}
|
|
1746
|
+
switch (display_list.commands[16]) {
|
|
1747
|
+
.draw_text => |text| try std.testing.expectEqualDeep(Color.rgb8(244, 248, 252), text.color),
|
|
1748
|
+
else => return error.TestUnexpectedResult,
|
|
1749
|
+
}
|
|
1750
|
+
}
|
|
1751
|
+
|
|
1752
|
+
test "widget emitter applies data cell control tokens" {
|
|
1753
|
+
const tokens = DesignTokens{
|
|
1754
|
+
.controls = .{
|
|
1755
|
+
.list_item = .{
|
|
1756
|
+
.active_background = Color.rgb8(12, 18, 24),
|
|
1757
|
+
.foreground = Color.rgb8(200, 210, 220),
|
|
1758
|
+
.border = Color.rgb8(40, 50, 60),
|
|
1759
|
+
},
|
|
1760
|
+
.data_cell = .{
|
|
1761
|
+
.active_background = Color.rgb8(32, 42, 52),
|
|
1762
|
+
.foreground = Color.rgb8(236, 242, 248),
|
|
1763
|
+
.border = Color.rgb8(70, 82, 94),
|
|
1764
|
+
.stroke_width = 1.5,
|
|
1765
|
+
},
|
|
1766
|
+
},
|
|
1767
|
+
};
|
|
1768
|
+
|
|
1769
|
+
var commands: [4]CanvasCommand = undefined;
|
|
1770
|
+
var builder = Builder.init(&commands);
|
|
1771
|
+
try emitWidgetTree(&builder, .{
|
|
1772
|
+
.id = 54,
|
|
1773
|
+
.kind = .data_cell,
|
|
1774
|
+
.frame = geometry.RectF.init(0, 0, 180, 30),
|
|
1775
|
+
.text = "Revenue",
|
|
1776
|
+
.state = .{ .selected = true },
|
|
1777
|
+
}, tokens);
|
|
1778
|
+
|
|
1779
|
+
const display_list = builder.displayList();
|
|
1780
|
+
try std.testing.expectEqual(@as(usize, 3), display_list.commandCount());
|
|
1781
|
+
switch (display_list.commands[0]) {
|
|
1782
|
+
.fill_rect => |fill| try expectFillColor(Color.rgb8(32, 42, 52), fill.fill),
|
|
1783
|
+
else => return error.TestUnexpectedResult,
|
|
1784
|
+
}
|
|
1785
|
+
switch (display_list.commands[1]) {
|
|
1786
|
+
.stroke_rect => |stroke| {
|
|
1787
|
+
try expectFillColor(Color.rgb8(70, 82, 94), stroke.stroke.fill);
|
|
1788
|
+
try std.testing.expectEqual(@as(f32, 1.5), stroke.stroke.width);
|
|
1789
|
+
},
|
|
1790
|
+
else => return error.TestUnexpectedResult,
|
|
1791
|
+
}
|
|
1792
|
+
switch (display_list.commands[2]) {
|
|
1793
|
+
.draw_text => |text| {
|
|
1794
|
+
try std.testing.expectEqualStrings("Revenue", text.text);
|
|
1795
|
+
try std.testing.expectEqualDeep(Color.rgb8(236, 242, 248), text.color);
|
|
1796
|
+
},
|
|
1797
|
+
else => return error.TestUnexpectedResult,
|
|
1798
|
+
}
|
|
1799
|
+
}
|
|
1800
|
+
|
|
1801
|
+
test "widget emitter applies menu item control tokens" {
|
|
1802
|
+
const tokens = DesignTokens{
|
|
1803
|
+
.controls = .{
|
|
1804
|
+
.list_item = .{
|
|
1805
|
+
.active_background = Color.rgb8(12, 18, 24),
|
|
1806
|
+
.foreground = Color.rgb8(200, 210, 220),
|
|
1807
|
+
.radius = 2,
|
|
1808
|
+
},
|
|
1809
|
+
.menu_item = .{
|
|
1810
|
+
.active_background = Color.rgb8(36, 44, 52),
|
|
1811
|
+
.foreground = Color.rgb8(240, 246, 252),
|
|
1812
|
+
.radius = 5,
|
|
1813
|
+
},
|
|
1814
|
+
},
|
|
1815
|
+
};
|
|
1816
|
+
|
|
1817
|
+
// A PRESSED row takes the menu-item active background (attention
|
|
1818
|
+
// states drive the wash; commit does not — see below).
|
|
1819
|
+
var commands: [3]CanvasCommand = undefined;
|
|
1820
|
+
var builder = Builder.init(&commands);
|
|
1821
|
+
try emitWidgetTree(&builder, .{
|
|
1822
|
+
.id = 55,
|
|
1823
|
+
.kind = .menu_item,
|
|
1824
|
+
.frame = geometry.RectF.init(0, 0, 180, 30),
|
|
1825
|
+
.text = "Copy token",
|
|
1826
|
+
.state = .{ .pressed = true },
|
|
1827
|
+
}, tokens);
|
|
1828
|
+
|
|
1829
|
+
const display_list = builder.displayList();
|
|
1830
|
+
try std.testing.expectEqual(@as(usize, 2), display_list.commandCount());
|
|
1831
|
+
switch (display_list.commands[0]) {
|
|
1832
|
+
.fill_rounded_rect => |fill| {
|
|
1833
|
+
try std.testing.expectEqualDeep(Radius.all(5), fill.radius);
|
|
1834
|
+
try expectFillColor(Color.rgb8(36, 44, 52), fill.fill);
|
|
1835
|
+
},
|
|
1836
|
+
else => return error.TestUnexpectedResult,
|
|
1837
|
+
}
|
|
1838
|
+
switch (display_list.commands[1]) {
|
|
1839
|
+
.draw_text => |text| {
|
|
1840
|
+
try std.testing.expectEqualStrings("Copy token", text.text);
|
|
1841
|
+
try std.testing.expectEqualDeep(Color.rgb8(240, 246, 252), text.color);
|
|
1842
|
+
},
|
|
1843
|
+
else => return error.TestUnexpectedResult,
|
|
1844
|
+
}
|
|
1845
|
+
|
|
1846
|
+
// A COMMITTED row wears no wash at all: its marker is the trailing
|
|
1847
|
+
// checkmark, tinted with the same menu-item foreground token.
|
|
1848
|
+
var committed_commands: [5]CanvasCommand = undefined;
|
|
1849
|
+
var committed_builder = Builder.init(&committed_commands);
|
|
1850
|
+
try emitWidgetTree(&committed_builder, .{
|
|
1851
|
+
.id = 55,
|
|
1852
|
+
.kind = .menu_item,
|
|
1853
|
+
.frame = geometry.RectF.init(0, 0, 180, 30),
|
|
1854
|
+
.text = "Copy token",
|
|
1855
|
+
.state = .{ .selected = true },
|
|
1856
|
+
}, tokens);
|
|
1857
|
+
const committed_list = committed_builder.displayList();
|
|
1858
|
+
try std.testing.expectEqual(@as(usize, 4), committed_list.commandCount());
|
|
1859
|
+
switch (committed_list.commands[0]) {
|
|
1860
|
+
.draw_text => |text| try std.testing.expectEqualDeep(Color.rgb8(240, 246, 252), text.color),
|
|
1861
|
+
else => return error.TestUnexpectedResult,
|
|
1862
|
+
}
|
|
1863
|
+
switch (committed_list.commands[2]) {
|
|
1864
|
+
.stroke_path => |stroke| try expectFillColor(Color.rgb8(240, 246, 252), stroke.stroke.fill),
|
|
1865
|
+
else => return error.TestUnexpectedResult,
|
|
1866
|
+
}
|
|
1867
|
+
}
|
|
1868
|
+
|
|
1869
|
+
test "widget emitter applies selection and range control tokens" {
|
|
1870
|
+
const tokens = DesignTokens{
|
|
1871
|
+
.controls = .{
|
|
1872
|
+
.segmented_control = .{
|
|
1873
|
+
.active_background = Color.rgb8(30, 50, 70),
|
|
1874
|
+
.foreground = Color.rgb8(245, 248, 252),
|
|
1875
|
+
.border = Color.rgb8(80, 96, 112),
|
|
1876
|
+
},
|
|
1877
|
+
.checkbox = .{
|
|
1878
|
+
.active_background = Color.rgb8(32, 64, 96),
|
|
1879
|
+
.foreground = Color.rgb8(250, 252, 255),
|
|
1880
|
+
.border = Color.rgb8(88, 104, 120),
|
|
1881
|
+
},
|
|
1882
|
+
.switch_control = .{
|
|
1883
|
+
.background = Color.rgb8(48, 54, 60),
|
|
1884
|
+
.active_background = Color.rgb8(34, 70, 108),
|
|
1885
|
+
.foreground = Color.rgb8(248, 250, 252),
|
|
1886
|
+
.border = Color.rgb8(84, 94, 104),
|
|
1887
|
+
},
|
|
1888
|
+
.slider = .{
|
|
1889
|
+
.background = Color.rgb8(50, 56, 64),
|
|
1890
|
+
.active_background = Color.rgb8(38, 76, 114),
|
|
1891
|
+
.foreground = Color.rgb8(246, 248, 250),
|
|
1892
|
+
.border = Color.rgb8(82, 92, 102),
|
|
1893
|
+
},
|
|
1894
|
+
.progress = .{
|
|
1895
|
+
.background = Color.rgb8(52, 58, 66),
|
|
1896
|
+
.active_background = Color.rgb8(40, 80, 120),
|
|
1897
|
+
},
|
|
1898
|
+
},
|
|
1899
|
+
};
|
|
1900
|
+
|
|
1901
|
+
var commands: [18]CanvasCommand = undefined;
|
|
1902
|
+
var builder = Builder.init(&commands);
|
|
1903
|
+
try emitWidgetTree(&builder, .{ .id = 60, .kind = .segmented_control, .frame = geometry.RectF.init(0, 0, 120, 32), .text = "Open", .state = .{ .selected = true } }, tokens);
|
|
1904
|
+
try emitWidgetTree(&builder, .{ .id = 61, .kind = .checkbox, .frame = geometry.RectF.init(0, 40, 140, 32), .text = "Check", .state = .{ .selected = true } }, tokens);
|
|
1905
|
+
try emitWidgetTree(&builder, .{ .id = 62, .kind = .switch_control, .frame = geometry.RectF.init(0, 80, 140, 32), .text = "Live", .value = 1 }, tokens);
|
|
1906
|
+
try emitWidgetTree(&builder, .{ .id = 63, .kind = .slider, .frame = geometry.RectF.init(0, 124, 160, 32), .value = 0.25 }, tokens);
|
|
1907
|
+
try emitWidgetTree(&builder, .{ .id = 64, .kind = .progress, .frame = geometry.RectF.init(0, 172, 160, 8), .value = 0.5 }, tokens);
|
|
1908
|
+
|
|
1909
|
+
const display_list = builder.displayList();
|
|
1910
|
+
try std.testing.expectEqual(@as(usize, 18), display_list.commandCount());
|
|
1911
|
+
switch (display_list.commands[0]) {
|
|
1912
|
+
.fill_rounded_rect => |fill| try expectFillColor(Color.rgb8(30, 50, 70), fill.fill),
|
|
1913
|
+
else => return error.TestUnexpectedResult,
|
|
1914
|
+
}
|
|
1915
|
+
switch (display_list.commands[2]) {
|
|
1916
|
+
.draw_text => |text| try std.testing.expectEqualDeep(Color.rgb8(245, 248, 252), text.color),
|
|
1917
|
+
else => return error.TestUnexpectedResult,
|
|
1918
|
+
}
|
|
1919
|
+
switch (display_list.commands[3]) {
|
|
1920
|
+
.fill_rounded_rect => |fill| try expectFillColor(Color.rgb8(32, 64, 96), fill.fill),
|
|
1921
|
+
else => return error.TestUnexpectedResult,
|
|
1922
|
+
}
|
|
1923
|
+
switch (display_list.commands[4]) {
|
|
1924
|
+
.stroke_rect => |stroke| try expectFillColor(Color.rgb8(88, 104, 120), stroke.stroke.fill),
|
|
1925
|
+
else => return error.TestUnexpectedResult,
|
|
1926
|
+
}
|
|
1927
|
+
switch (display_list.commands[5]) {
|
|
1928
|
+
.draw_line => |line| try expectFillColor(Color.rgb8(250, 252, 255), line.stroke.fill),
|
|
1929
|
+
else => return error.TestUnexpectedResult,
|
|
1930
|
+
}
|
|
1931
|
+
switch (display_list.commands[8]) {
|
|
1932
|
+
.fill_rounded_rect => |fill| try expectFillColor(Color.rgb8(34, 70, 108), fill.fill),
|
|
1933
|
+
else => return error.TestUnexpectedResult,
|
|
1934
|
+
}
|
|
1935
|
+
switch (display_list.commands[10]) {
|
|
1936
|
+
.fill_rounded_rect => |fill| try expectFillColor(Color.rgb8(248, 250, 252), fill.fill),
|
|
1937
|
+
else => return error.TestUnexpectedResult,
|
|
1938
|
+
}
|
|
1939
|
+
switch (display_list.commands[12]) {
|
|
1940
|
+
.fill_rounded_rect => |fill| try expectFillColor(Color.rgb8(50, 56, 64), fill.fill),
|
|
1941
|
+
else => return error.TestUnexpectedResult,
|
|
1942
|
+
}
|
|
1943
|
+
switch (display_list.commands[13]) {
|
|
1944
|
+
.fill_rounded_rect => |fill| try expectFillColor(Color.rgb8(38, 76, 114), fill.fill),
|
|
1945
|
+
else => return error.TestUnexpectedResult,
|
|
1946
|
+
}
|
|
1947
|
+
switch (display_list.commands[14]) {
|
|
1948
|
+
.fill_rounded_rect => |fill| try expectFillColor(Color.rgb8(246, 248, 250), fill.fill),
|
|
1949
|
+
else => return error.TestUnexpectedResult,
|
|
1950
|
+
}
|
|
1951
|
+
switch (display_list.commands[16]) {
|
|
1952
|
+
.fill_rounded_rect => |fill| try expectFillColor(Color.rgb8(52, 58, 66), fill.fill),
|
|
1953
|
+
else => return error.TestUnexpectedResult,
|
|
1954
|
+
}
|
|
1955
|
+
switch (display_list.commands[17]) {
|
|
1956
|
+
.fill_rounded_rect => |fill| try expectFillColor(Color.rgb8(40, 80, 120), fill.fill),
|
|
1957
|
+
else => return error.TestUnexpectedResult,
|
|
1958
|
+
}
|
|
1959
|
+
}
|
|
1960
|
+
|
|
1961
|
+
test "widget emitter applies radio control tokens" {
|
|
1962
|
+
const tokens = DesignTokens{
|
|
1963
|
+
.controls = .{
|
|
1964
|
+
.radio = .{
|
|
1965
|
+
.active_background = Color.rgb8(36, 72, 108),
|
|
1966
|
+
.foreground = Color.rgb8(248, 250, 252),
|
|
1967
|
+
.border = Color.rgb8(90, 106, 122),
|
|
1968
|
+
},
|
|
1969
|
+
},
|
|
1970
|
+
};
|
|
1971
|
+
|
|
1972
|
+
var commands: [5]CanvasCommand = undefined;
|
|
1973
|
+
var builder = Builder.init(&commands);
|
|
1974
|
+
try emitWidgetTree(&builder, .{
|
|
1975
|
+
.id = 65,
|
|
1976
|
+
.kind = .radio,
|
|
1977
|
+
.frame = geometry.RectF.init(0, 0, 140, 32),
|
|
1978
|
+
.text = "Monthly",
|
|
1979
|
+
.state = .{ .selected = true },
|
|
1980
|
+
}, tokens);
|
|
1981
|
+
|
|
1982
|
+
const display_list = builder.displayList();
|
|
1983
|
+
try std.testing.expectEqual(@as(usize, 4), display_list.commandCount());
|
|
1984
|
+
switch (display_list.commands[1]) {
|
|
1985
|
+
.stroke_rect => |stroke| try expectFillColor(Color.rgb8(90, 106, 122), stroke.stroke.fill),
|
|
1986
|
+
else => return error.TestUnexpectedResult,
|
|
1987
|
+
}
|
|
1988
|
+
switch (display_list.commands[2]) {
|
|
1989
|
+
.fill_rounded_rect => |fill| try expectFillColor(Color.rgb8(36, 72, 108), fill.fill),
|
|
1990
|
+
else => return error.TestUnexpectedResult,
|
|
1991
|
+
}
|
|
1992
|
+
switch (display_list.commands[3]) {
|
|
1993
|
+
.draw_text => |text| try std.testing.expectEqualDeep(Color.rgb8(248, 250, 252), text.color),
|
|
1994
|
+
else => return error.TestUnexpectedResult,
|
|
1995
|
+
}
|
|
1996
|
+
}
|
|
1997
|
+
|
|
1998
|
+
test "widget emitter applies surface control tokens" {
|
|
1999
|
+
const tokens = DesignTokens{
|
|
2000
|
+
.controls = .{
|
|
2001
|
+
.panel = .{
|
|
2002
|
+
.background = Color.rgb8(20, 24, 28),
|
|
2003
|
+
.border = Color.rgb8(80, 88, 96),
|
|
2004
|
+
},
|
|
2005
|
+
.popover = .{
|
|
2006
|
+
.hover_background = Color.rgb8(24, 30, 36),
|
|
2007
|
+
.border = Color.rgb8(90, 98, 106),
|
|
2008
|
+
},
|
|
2009
|
+
.menu_surface = .{
|
|
2010
|
+
.active_background = Color.rgb8(28, 36, 44),
|
|
2011
|
+
.border = Color.rgb8(100, 108, 116),
|
|
2012
|
+
},
|
|
2013
|
+
.tooltip = .{
|
|
2014
|
+
.background = Color.rgb8(240, 244, 248),
|
|
2015
|
+
.foreground = Color.rgb8(18, 24, 30),
|
|
2016
|
+
},
|
|
2017
|
+
},
|
|
2018
|
+
};
|
|
2019
|
+
|
|
2020
|
+
var commands: [12]CanvasCommand = undefined;
|
|
2021
|
+
var builder = Builder.init(&commands);
|
|
2022
|
+
try emitWidgetTree(&builder, .{ .id = 70, .kind = .panel, .frame = geometry.RectF.init(0, 0, 160, 80) }, tokens);
|
|
2023
|
+
try emitWidgetTree(&builder, .{ .id = 71, .kind = .popover, .frame = geometry.RectF.init(0, 90, 160, 80), .state = .{ .hovered = true } }, tokens);
|
|
2024
|
+
try emitWidgetTree(&builder, .{ .id = 72, .kind = .menu_surface, .frame = geometry.RectF.init(0, 180, 160, 80), .state = .{ .selected = true } }, tokens);
|
|
2025
|
+
try emitWidgetTree(&builder, .{ .id = 73, .kind = .tooltip, .frame = geometry.RectF.init(0, 270, 120, 28), .text = "Hint" }, tokens);
|
|
2026
|
+
|
|
2027
|
+
const display_list = builder.displayList();
|
|
2028
|
+
try std.testing.expectEqual(@as(usize, 12), display_list.commandCount());
|
|
2029
|
+
switch (display_list.commands[1]) {
|
|
2030
|
+
.fill_rounded_rect => |fill| try expectFillColor(Color.rgb8(20, 24, 28), fill.fill),
|
|
2031
|
+
else => return error.TestUnexpectedResult,
|
|
2032
|
+
}
|
|
2033
|
+
switch (display_list.commands[2]) {
|
|
2034
|
+
.stroke_rect => |stroke| try expectFillColor(Color.rgb8(80, 88, 96), stroke.stroke.fill),
|
|
2035
|
+
else => return error.TestUnexpectedResult,
|
|
2036
|
+
}
|
|
2037
|
+
switch (display_list.commands[4]) {
|
|
2038
|
+
.fill_rounded_rect => |fill| try expectFillColor(Color.rgb8(24, 30, 36), fill.fill),
|
|
2039
|
+
else => return error.TestUnexpectedResult,
|
|
2040
|
+
}
|
|
2041
|
+
switch (display_list.commands[5]) {
|
|
2042
|
+
.stroke_rect => |stroke| try expectFillColor(Color.rgb8(90, 98, 106), stroke.stroke.fill),
|
|
2043
|
+
else => return error.TestUnexpectedResult,
|
|
2044
|
+
}
|
|
2045
|
+
switch (display_list.commands[7]) {
|
|
2046
|
+
.fill_rounded_rect => |fill| try expectFillColor(Color.rgb8(28, 36, 44), fill.fill),
|
|
2047
|
+
else => return error.TestUnexpectedResult,
|
|
2048
|
+
}
|
|
2049
|
+
switch (display_list.commands[8]) {
|
|
2050
|
+
.stroke_rect => |stroke| try expectFillColor(Color.rgb8(100, 108, 116), stroke.stroke.fill),
|
|
2051
|
+
else => return error.TestUnexpectedResult,
|
|
2052
|
+
}
|
|
2053
|
+
switch (display_list.commands[10]) {
|
|
2054
|
+
.fill_rounded_rect => |fill| try expectFillColor(Color.rgb8(240, 244, 248), fill.fill),
|
|
2055
|
+
else => return error.TestUnexpectedResult,
|
|
2056
|
+
}
|
|
2057
|
+
switch (display_list.commands[11]) {
|
|
2058
|
+
.draw_text => |text| try std.testing.expectEqualDeep(Color.rgb8(18, 24, 30), text.color),
|
|
2059
|
+
else => return error.TestUnexpectedResult,
|
|
2060
|
+
}
|
|
2061
|
+
}
|
|
2062
|
+
|
|
2063
|
+
test "widget emitter applies control radius and stroke tokens" {
|
|
2064
|
+
const tokens = DesignTokens{
|
|
2065
|
+
.controls = .{
|
|
2066
|
+
.button_primary = .{
|
|
2067
|
+
.border = Color.rgb8(20, 70, 120),
|
|
2068
|
+
.radius = 10,
|
|
2069
|
+
.stroke_width = 3,
|
|
2070
|
+
},
|
|
2071
|
+
.text_field = .{
|
|
2072
|
+
.border = Color.rgb8(80, 90, 100),
|
|
2073
|
+
.radius = 4,
|
|
2074
|
+
.stroke_width = 2,
|
|
2075
|
+
},
|
|
2076
|
+
.checkbox = .{
|
|
2077
|
+
.border = Color.rgb8(88, 104, 120),
|
|
2078
|
+
.radius = 1,
|
|
2079
|
+
.stroke_width = 5,
|
|
2080
|
+
},
|
|
2081
|
+
.panel = .{
|
|
2082
|
+
.border = Color.rgb8(72, 82, 92),
|
|
2083
|
+
.radius = 14,
|
|
2084
|
+
.stroke_width = 2.5,
|
|
2085
|
+
},
|
|
2086
|
+
},
|
|
2087
|
+
};
|
|
2088
|
+
|
|
2089
|
+
var commands: [12]CanvasCommand = undefined;
|
|
2090
|
+
var builder = Builder.init(&commands);
|
|
2091
|
+
try emitWidgetTree(&builder, .{ .id = 80, .kind = .button, .variant = .primary, .frame = geometry.RectF.init(0, 0, 120, 32), .text = "Save" }, tokens);
|
|
2092
|
+
try emitWidgetTree(&builder, .{ .id = 81, .kind = .text_field, .frame = geometry.RectF.init(0, 40, 160, 34), .text = "Name" }, tokens);
|
|
2093
|
+
try emitWidgetTree(&builder, .{ .id = 82, .kind = .checkbox, .frame = geometry.RectF.init(0, 86, 40, 24) }, tokens);
|
|
2094
|
+
try emitWidgetTree(&builder, .{ .id = 83, .kind = .panel, .frame = geometry.RectF.init(0, 120, 180, 90), .style = .{ .radius = 6, .stroke_width = 1 } }, tokens);
|
|
2095
|
+
|
|
2096
|
+
// Buttons are flat, so the button's chrome sits at [0]/[1].
|
|
2097
|
+
const display_list = builder.displayList();
|
|
2098
|
+
try std.testing.expectEqual(@as(usize, 11), display_list.commandCount());
|
|
2099
|
+
switch (display_list.commands[0]) {
|
|
2100
|
+
.fill_rounded_rect => |fill| try std.testing.expectEqualDeep(Radius.all(10), fill.radius),
|
|
2101
|
+
else => return error.TestUnexpectedResult,
|
|
2102
|
+
}
|
|
2103
|
+
switch (display_list.commands[1]) {
|
|
2104
|
+
.stroke_rect => |stroke| {
|
|
2105
|
+
try std.testing.expectEqualDeep(Radius.all(10), stroke.radius);
|
|
2106
|
+
try std.testing.expectEqual(@as(f32, 3), stroke.stroke.width);
|
|
2107
|
+
try expectFillColor(Color.rgb8(20, 70, 120), stroke.stroke.fill);
|
|
2108
|
+
},
|
|
2109
|
+
else => return error.TestUnexpectedResult,
|
|
2110
|
+
}
|
|
2111
|
+
switch (display_list.commands[3]) {
|
|
2112
|
+
.fill_rounded_rect => |fill| try std.testing.expectEqualDeep(Radius.all(4), fill.radius),
|
|
2113
|
+
else => return error.TestUnexpectedResult,
|
|
2114
|
+
}
|
|
2115
|
+
switch (display_list.commands[4]) {
|
|
2116
|
+
.stroke_rect => |stroke| {
|
|
2117
|
+
try std.testing.expectEqualDeep(Radius.all(4), stroke.radius);
|
|
2118
|
+
try std.testing.expectEqual(@as(f32, 2), stroke.stroke.width);
|
|
2119
|
+
try expectFillColor(Color.rgb8(80, 90, 100), stroke.stroke.fill);
|
|
2120
|
+
},
|
|
2121
|
+
else => return error.TestUnexpectedResult,
|
|
2122
|
+
}
|
|
2123
|
+
switch (display_list.commands[6]) {
|
|
2124
|
+
.fill_rounded_rect => |fill| try std.testing.expectEqualDeep(Radius.all(1), fill.radius),
|
|
2125
|
+
else => return error.TestUnexpectedResult,
|
|
2126
|
+
}
|
|
2127
|
+
switch (display_list.commands[7]) {
|
|
2128
|
+
.stroke_rect => |stroke| {
|
|
2129
|
+
try std.testing.expectEqualDeep(Radius.all(1), stroke.radius);
|
|
2130
|
+
try std.testing.expectEqual(@as(f32, 5), stroke.stroke.width);
|
|
2131
|
+
try expectFillColor(Color.rgb8(88, 104, 120), stroke.stroke.fill);
|
|
2132
|
+
},
|
|
2133
|
+
else => return error.TestUnexpectedResult,
|
|
2134
|
+
}
|
|
2135
|
+
switch (display_list.commands[9]) {
|
|
2136
|
+
.fill_rounded_rect => |fill| try std.testing.expectEqualDeep(Radius.all(6), fill.radius),
|
|
2137
|
+
else => return error.TestUnexpectedResult,
|
|
2138
|
+
}
|
|
2139
|
+
switch (display_list.commands[10]) {
|
|
2140
|
+
.stroke_rect => |stroke| {
|
|
2141
|
+
try std.testing.expectEqualDeep(Radius.all(6), stroke.radius);
|
|
2142
|
+
try std.testing.expectEqual(@as(f32, 1), stroke.stroke.width);
|
|
2143
|
+
try expectFillColor(Color.rgb8(72, 82, 92), stroke.stroke.fill);
|
|
2144
|
+
},
|
|
2145
|
+
else => return error.TestUnexpectedResult,
|
|
2146
|
+
}
|
|
2147
|
+
}
|
|
2148
|
+
|
|
2149
|
+
test "widget emitter applies control sizes" {
|
|
2150
|
+
const tokens = DesignTokens{};
|
|
2151
|
+
|
|
2152
|
+
var commands: [13]CanvasCommand = undefined;
|
|
2153
|
+
var builder = Builder.init(&commands);
|
|
2154
|
+
try emitWidgetTree(&builder, .{ .id = 40, .kind = .button, .frame = geometry.RectF.init(0, 0, 120, 32), .text = "Small", .size = .sm }, tokens);
|
|
2155
|
+
try emitWidgetTree(&builder, .{ .id = 41, .kind = .button, .frame = geometry.RectF.init(0, 40, 120, 32), .text = "Large", .size = .lg }, tokens);
|
|
2156
|
+
try emitWidgetTree(&builder, .{ .id = 42, .kind = .text_field, .frame = geometry.RectF.init(0, 80, 120, 32), .text = "Input", .size = .sm }, tokens);
|
|
2157
|
+
try emitWidgetTree(&builder, .{ .id = 43, .kind = .checkbox, .frame = geometry.RectF.init(0, 120, 80, 20), .size = .lg }, tokens);
|
|
2158
|
+
|
|
2159
|
+
// Buttons are flat (fill + border + label each). The corner steps
|
|
2160
|
+
// once at sm (8 vs the default/lg 10) and the label steps down to
|
|
2161
|
+
// 12.8 at sm; the 10px inset holds across the ladder.
|
|
2162
|
+
const display_list = builder.displayList();
|
|
2163
|
+
try std.testing.expectEqual(@as(usize, 11), display_list.commandCount());
|
|
2164
|
+
switch (display_list.commands[0]) {
|
|
2165
|
+
.fill_rounded_rect => |fill| try std.testing.expectEqualDeep(Radius.all(8), fill.radius),
|
|
2166
|
+
else => return error.TestUnexpectedResult,
|
|
2167
|
+
}
|
|
2168
|
+
switch (display_list.commands[2]) {
|
|
2169
|
+
.draw_text => |text| {
|
|
2170
|
+
try std.testing.expectEqual(@as(f32, 12.8), text.size);
|
|
2171
|
+
try std.testing.expect(text.text_layout != null);
|
|
2172
|
+
// The shared 10px inset on each side of the 120 frame.
|
|
2173
|
+
try std.testing.expectApproxEqAbs(@as(f32, 100), text.text_layout.?.max_width, 0.001);
|
|
2174
|
+
},
|
|
2175
|
+
else => return error.TestUnexpectedResult,
|
|
2176
|
+
}
|
|
2177
|
+
switch (display_list.commands[3]) {
|
|
2178
|
+
.fill_rounded_rect => |fill| try std.testing.expectEqualDeep(Radius.all(10), fill.radius),
|
|
2179
|
+
else => return error.TestUnexpectedResult,
|
|
2180
|
+
}
|
|
2181
|
+
switch (display_list.commands[5]) {
|
|
2182
|
+
.draw_text => |text| {
|
|
2183
|
+
try std.testing.expectEqual(@as(f32, 14), text.size);
|
|
2184
|
+
try std.testing.expect(text.text_layout != null);
|
|
2185
|
+
// lg keeps the same 10px inset — sizes step height and
|
|
2186
|
+
// radius, never the padding register.
|
|
2187
|
+
try std.testing.expectApproxEqAbs(@as(f32, 100), text.text_layout.?.max_width, 0.001);
|
|
2188
|
+
},
|
|
2189
|
+
else => return error.TestUnexpectedResult,
|
|
2190
|
+
}
|
|
2191
|
+
switch (display_list.commands[8]) {
|
|
2192
|
+
.draw_text => |text| {
|
|
2193
|
+
try std.testing.expectEqual(@as(f32, 13), text.size);
|
|
2194
|
+
try std.testing.expect(text.text_layout != null);
|
|
2195
|
+
try std.testing.expectApproxEqAbs(@as(f32, 100), text.text_layout.?.max_width, 0.001);
|
|
2196
|
+
},
|
|
2197
|
+
else => return error.TestUnexpectedResult,
|
|
2198
|
+
}
|
|
2199
|
+
switch (display_list.commands[9]) {
|
|
2200
|
+
.fill_rounded_rect => |fill| try std.testing.expectApproxEqAbs(@as(f32, 18), fill.rect.width, 0.001),
|
|
2201
|
+
else => return error.TestUnexpectedResult,
|
|
2202
|
+
}
|
|
2203
|
+
}
|
|
2204
|
+
|
|
2205
|
+
test "widget emitter applies per-widget style overrides" {
|
|
2206
|
+
const base_style = WidgetStyle{
|
|
2207
|
+
.background = Color.rgb8(12, 18, 24),
|
|
2208
|
+
.foreground = Color.rgb8(235, 241, 247),
|
|
2209
|
+
.border = Color.rgb8(54, 64, 74),
|
|
2210
|
+
.focus_ring = Color.rgb8(90, 120, 255),
|
|
2211
|
+
.radius = 5,
|
|
2212
|
+
.stroke_width = 2,
|
|
2213
|
+
};
|
|
2214
|
+
const active_style = WidgetStyle{
|
|
2215
|
+
.accent = Color.rgb8(30, 80, 210),
|
|
2216
|
+
.accent_foreground = Color.rgb8(255, 255, 255),
|
|
2217
|
+
.border = Color.rgb8(30, 80, 210),
|
|
2218
|
+
.radius = 4,
|
|
2219
|
+
};
|
|
2220
|
+
|
|
2221
|
+
var commands: [9]CanvasCommand = undefined;
|
|
2222
|
+
var builder = Builder.init(&commands);
|
|
2223
|
+
try emitWidgetTree(&builder, .{
|
|
2224
|
+
.id = 30,
|
|
2225
|
+
.kind = .button,
|
|
2226
|
+
.frame = geometry.RectF.init(0, 0, 128, 36),
|
|
2227
|
+
.text = "Brand",
|
|
2228
|
+
.state = .{ .focused = true },
|
|
2229
|
+
.style = base_style,
|
|
2230
|
+
}, .{});
|
|
2231
|
+
try emitWidgetTree(&builder, .{
|
|
2232
|
+
.id = 31,
|
|
2233
|
+
.kind = .button,
|
|
2234
|
+
.frame = geometry.RectF.init(0, 48, 128, 36),
|
|
2235
|
+
.text = "Active",
|
|
2236
|
+
.state = .{ .pressed = true },
|
|
2237
|
+
.style = active_style,
|
|
2238
|
+
}, .{});
|
|
2239
|
+
|
|
2240
|
+
// Buttons are flat — styled chrome starts at [0].
|
|
2241
|
+
const display_list = builder.displayList();
|
|
2242
|
+
try std.testing.expectEqual(@as(usize, 7), display_list.commandCount());
|
|
2243
|
+
switch (display_list.commands[0]) {
|
|
2244
|
+
.fill_rounded_rect => |fill| {
|
|
2245
|
+
try expectFillColor(Color.rgb8(12, 18, 24), fill.fill);
|
|
2246
|
+
try std.testing.expectEqualDeep(Radius.all(5), fill.radius);
|
|
2247
|
+
},
|
|
2248
|
+
else => return error.TestUnexpectedResult,
|
|
2249
|
+
}
|
|
2250
|
+
switch (display_list.commands[1]) {
|
|
2251
|
+
.stroke_rect => |stroke| {
|
|
2252
|
+
try expectFillColor(Color.rgb8(54, 64, 74), stroke.stroke.fill);
|
|
2253
|
+
try std.testing.expectEqual(@as(f32, 2), stroke.stroke.width);
|
|
2254
|
+
try std.testing.expectEqualDeep(Radius.all(5), stroke.radius);
|
|
2255
|
+
},
|
|
2256
|
+
else => return error.TestUnexpectedResult,
|
|
2257
|
+
}
|
|
2258
|
+
switch (display_list.commands[2]) {
|
|
2259
|
+
.stroke_rect => |stroke| try expectFillColor(Color.rgb8(90, 120, 255), stroke.stroke.fill),
|
|
2260
|
+
else => return error.TestUnexpectedResult,
|
|
2261
|
+
}
|
|
2262
|
+
switch (display_list.commands[3]) {
|
|
2263
|
+
.draw_text => |text| try std.testing.expectEqualDeep(Color.rgb8(235, 241, 247), text.color),
|
|
2264
|
+
else => return error.TestUnexpectedResult,
|
|
2265
|
+
}
|
|
2266
|
+
switch (display_list.commands[4]) {
|
|
2267
|
+
.fill_rounded_rect => |fill| {
|
|
2268
|
+
try expectFillColor(Color.rgb8(30, 80, 210), fill.fill);
|
|
2269
|
+
try std.testing.expectEqualDeep(Radius.all(4), fill.radius);
|
|
2270
|
+
},
|
|
2271
|
+
else => return error.TestUnexpectedResult,
|
|
2272
|
+
}
|
|
2273
|
+
switch (display_list.commands[6]) {
|
|
2274
|
+
.draw_text => |text| try std.testing.expectEqualDeep(Color.rgb8(255, 255, 255), text.color),
|
|
2275
|
+
else => return error.TestUnexpectedResult,
|
|
2276
|
+
}
|
|
2277
|
+
}
|
|
2278
|
+
|
|
2279
|
+
test "widget emitter applies density tokens to spacing and affordances" {
|
|
2280
|
+
const button = Widget{
|
|
2281
|
+
.id = 1,
|
|
2282
|
+
.kind = .button,
|
|
2283
|
+
.frame = geometry.RectF.init(0, 0, 140, 40),
|
|
2284
|
+
.text = "Density",
|
|
2285
|
+
};
|
|
2286
|
+
|
|
2287
|
+
// The label inset is the shared 10px register, density-scaled
|
|
2288
|
+
// (8.75/10/11.25); buttons are flat so the label lands at [2]
|
|
2289
|
+
// behind fill and border.
|
|
2290
|
+
var compact_button_commands: [5]CanvasCommand = undefined;
|
|
2291
|
+
var compact_button_builder = Builder.init(&compact_button_commands);
|
|
2292
|
+
try emitWidgetTree(&compact_button_builder, button, .{ .density = .compact });
|
|
2293
|
+
switch (compact_button_builder.displayList().commands[2]) {
|
|
2294
|
+
.draw_text => |text| {
|
|
2295
|
+
try std.testing.expectApproxEqAbs(@as(f32, 8.75), text.origin.x, 0.001);
|
|
2296
|
+
try std.testing.expect(text.text_layout != null);
|
|
2297
|
+
try std.testing.expectApproxEqAbs(@as(f32, 122.5), text.text_layout.?.max_width, 0.001);
|
|
2298
|
+
try std.testing.expectEqual(TextAlign.center, text.text_layout.?.alignment);
|
|
2299
|
+
},
|
|
2300
|
+
else => return error.TestUnexpectedResult,
|
|
2301
|
+
}
|
|
2302
|
+
|
|
2303
|
+
var regular_button_commands: [5]CanvasCommand = undefined;
|
|
2304
|
+
var regular_button_builder = Builder.init(®ular_button_commands);
|
|
2305
|
+
try emitWidgetTree(®ular_button_builder, button, .{ .density = .regular });
|
|
2306
|
+
switch (regular_button_builder.displayList().commands[2]) {
|
|
2307
|
+
.draw_text => |text| {
|
|
2308
|
+
try std.testing.expectApproxEqAbs(@as(f32, 10), text.origin.x, 0.001);
|
|
2309
|
+
try std.testing.expect(text.text_layout != null);
|
|
2310
|
+
try std.testing.expectApproxEqAbs(@as(f32, 120), text.text_layout.?.max_width, 0.001);
|
|
2311
|
+
try std.testing.expectEqual(TextAlign.center, text.text_layout.?.alignment);
|
|
2312
|
+
},
|
|
2313
|
+
else => return error.TestUnexpectedResult,
|
|
2314
|
+
}
|
|
2315
|
+
|
|
2316
|
+
var spacious_button_commands: [5]CanvasCommand = undefined;
|
|
2317
|
+
var spacious_button_builder = Builder.init(&spacious_button_commands);
|
|
2318
|
+
try emitWidgetTree(&spacious_button_builder, button, .{ .density = .spacious });
|
|
2319
|
+
switch (spacious_button_builder.displayList().commands[2]) {
|
|
2320
|
+
.draw_text => |text| {
|
|
2321
|
+
try std.testing.expectApproxEqAbs(@as(f32, 11.25), text.origin.x, 0.001);
|
|
2322
|
+
try std.testing.expect(text.text_layout != null);
|
|
2323
|
+
try std.testing.expectApproxEqAbs(@as(f32, 117.5), text.text_layout.?.max_width, 0.001);
|
|
2324
|
+
try std.testing.expectEqual(TextAlign.center, text.text_layout.?.alignment);
|
|
2325
|
+
},
|
|
2326
|
+
else => return error.TestUnexpectedResult,
|
|
2327
|
+
}
|
|
2328
|
+
|
|
2329
|
+
const checkbox = Widget{
|
|
2330
|
+
.id = 2,
|
|
2331
|
+
.kind = .checkbox,
|
|
2332
|
+
.frame = geometry.RectF.init(0, 0, 80, 20),
|
|
2333
|
+
};
|
|
2334
|
+
|
|
2335
|
+
var compact_checkbox_commands: [2]CanvasCommand = undefined;
|
|
2336
|
+
var compact_checkbox_builder = Builder.init(&compact_checkbox_commands);
|
|
2337
|
+
try emitWidgetTree(&compact_checkbox_builder, checkbox, .{ .density = .compact });
|
|
2338
|
+
switch (compact_checkbox_builder.displayList().commands[0]) {
|
|
2339
|
+
.fill_rounded_rect => |fill| try std.testing.expectApproxEqAbs(@as(f32, 14), fill.rect.width, 0.001),
|
|
2340
|
+
else => return error.TestUnexpectedResult,
|
|
2341
|
+
}
|
|
2342
|
+
|
|
2343
|
+
var regular_checkbox_commands: [2]CanvasCommand = undefined;
|
|
2344
|
+
var regular_checkbox_builder = Builder.init(®ular_checkbox_commands);
|
|
2345
|
+
try emitWidgetTree(®ular_checkbox_builder, checkbox, .{ .density = .regular });
|
|
2346
|
+
switch (regular_checkbox_builder.displayList().commands[0]) {
|
|
2347
|
+
.fill_rounded_rect => |fill| try std.testing.expectApproxEqAbs(@as(f32, 16), fill.rect.width, 0.001),
|
|
2348
|
+
else => return error.TestUnexpectedResult,
|
|
2349
|
+
}
|
|
2350
|
+
|
|
2351
|
+
var spacious_checkbox_commands: [2]CanvasCommand = undefined;
|
|
2352
|
+
var spacious_checkbox_builder = Builder.init(&spacious_checkbox_commands);
|
|
2353
|
+
try emitWidgetTree(&spacious_checkbox_builder, checkbox, .{ .density = .spacious });
|
|
2354
|
+
switch (spacious_checkbox_builder.displayList().commands[0]) {
|
|
2355
|
+
.fill_rounded_rect => |fill| try std.testing.expectApproxEqAbs(@as(f32, 18), fill.rect.width, 0.001),
|
|
2356
|
+
else => return error.TestUnexpectedResult,
|
|
2357
|
+
}
|
|
2358
|
+
}
|
|
2359
|
+
|
|
2360
|
+
test "widget pixel snap tokens align widget chrome and text origins" {
|
|
2361
|
+
const tokens = DesignTokens{
|
|
2362
|
+
.pixel_snap = .{ .geometry = true, .text = true, .scale = 1 },
|
|
2363
|
+
};
|
|
2364
|
+
const button = Widget{
|
|
2365
|
+
.id = 42,
|
|
2366
|
+
.kind = .button,
|
|
2367
|
+
.frame = geometry.RectF.init(0.26, 0.51, 100.4, 32.4),
|
|
2368
|
+
.text = "Snap",
|
|
2369
|
+
};
|
|
2370
|
+
|
|
2371
|
+
var commands: [4]CanvasCommand = undefined;
|
|
2372
|
+
var builder = Builder.init(&commands);
|
|
2373
|
+
try emitWidgetTree(&builder, button, tokens);
|
|
2374
|
+
|
|
2375
|
+
// Fill + border + label — buttons are flat.
|
|
2376
|
+
const display_list = builder.displayList();
|
|
2377
|
+
try std.testing.expectEqual(@as(usize, 3), display_list.commandCount());
|
|
2378
|
+
switch (display_list.commands[0]) {
|
|
2379
|
+
.fill_rounded_rect => |fill| try expectRect(geometry.RectF.init(0, 1, 101, 32), fill.rect),
|
|
2380
|
+
else => return error.TestUnexpectedResult,
|
|
2381
|
+
}
|
|
2382
|
+
switch (display_list.commands[2]) {
|
|
2383
|
+
.draw_text => |text| {
|
|
2384
|
+
try std.testing.expectEqual(@round(text.origin.x), text.origin.x);
|
|
2385
|
+
try std.testing.expectEqual(@round(text.origin.y), text.origin.y);
|
|
2386
|
+
},
|
|
2387
|
+
else => return error.TestUnexpectedResult,
|
|
2388
|
+
}
|
|
2389
|
+
}
|
|
2390
|
+
|
|
2391
|
+
test "widget layout emission can render runtime focus state" {
|
|
2392
|
+
const tokens = DesignTokens{
|
|
2393
|
+
.colors = .{
|
|
2394
|
+
.accent = Color.rgb8(10, 20, 30),
|
|
2395
|
+
.focus_ring = Color.rgb8(1, 2, 3),
|
|
2396
|
+
},
|
|
2397
|
+
.stroke = .{ .focus = 3 },
|
|
2398
|
+
};
|
|
2399
|
+
const children = [_]Widget{
|
|
2400
|
+
.{
|
|
2401
|
+
.id = 2,
|
|
2402
|
+
.kind = .button,
|
|
2403
|
+
.frame = geometry.RectF.init(0, 0, 100, 32),
|
|
2404
|
+
.text = "Run",
|
|
2405
|
+
},
|
|
2406
|
+
.{
|
|
2407
|
+
.id = 3,
|
|
2408
|
+
.kind = .button,
|
|
2409
|
+
.frame = geometry.RectF.init(0, 40, 100, 32),
|
|
2410
|
+
.text = "Stop",
|
|
2411
|
+
.state = .{ .hovered = true, .pressed = true, .focused = true },
|
|
2412
|
+
},
|
|
2413
|
+
};
|
|
2414
|
+
|
|
2415
|
+
var nodes: [3]WidgetLayoutNode = undefined;
|
|
2416
|
+
const layout = try layoutWidgetTree(.{ .kind = .stack, .children = &children }, geometry.RectF.init(0, 0, 140, 100), &nodes);
|
|
2417
|
+
|
|
2418
|
+
var commands: [10]CanvasCommand = undefined;
|
|
2419
|
+
var builder = Builder.init(&commands);
|
|
2420
|
+
try layout.emitDisplayListWithState(&builder, tokens, .{ .focused_id = 2, .focus_visible_id = 2, .hovered_id = 2, .pressed_id = 2 });
|
|
2421
|
+
|
|
2422
|
+
// Flat buttons: 4 commands for the focused/pressed one (fill,
|
|
2423
|
+
// border, focus ring, label), 3 for the resting one.
|
|
2424
|
+
const display_list = builder.displayList();
|
|
2425
|
+
try std.testing.expectEqual(@as(usize, 7), display_list.commandCount());
|
|
2426
|
+
switch (display_list.commands[0]) {
|
|
2427
|
+
.fill_rounded_rect => |fill| try expectFillColor(tokens.colors.accent, fill.fill),
|
|
2428
|
+
else => return error.TestUnexpectedResult,
|
|
2429
|
+
}
|
|
2430
|
+
var saw_runtime_focus = false;
|
|
2431
|
+
var saw_stale_focus = false;
|
|
2432
|
+
for (display_list.commands) |command| {
|
|
2433
|
+
if (command.objectId()) |id| {
|
|
2434
|
+
if (id == widgetPartId(2, 3)) saw_runtime_focus = true;
|
|
2435
|
+
if (id == widgetPartId(3, 3)) saw_stale_focus = true;
|
|
2436
|
+
}
|
|
2437
|
+
}
|
|
2438
|
+
try std.testing.expect(saw_runtime_focus);
|
|
2439
|
+
try std.testing.expect(!saw_stale_focus);
|
|
2440
|
+
}
|
|
2441
|
+
|
|
2442
|
+
test "input-group wears the focus ring for its focused descendant" {
|
|
2443
|
+
const tokens = DesignTokens{};
|
|
2444
|
+
const group_children = [_]Widget{
|
|
2445
|
+
.{
|
|
2446
|
+
.id = 3,
|
|
2447
|
+
.kind = .textarea,
|
|
2448
|
+
.layout = .{ .grow = 1 },
|
|
2449
|
+
// The dissolved entry chrome `Ui.inputGroup` stamps.
|
|
2450
|
+
.style = .{
|
|
2451
|
+
.background = Color.rgba8(0, 0, 0, 0),
|
|
2452
|
+
.border = Color.rgba8(0, 0, 0, 0),
|
|
2453
|
+
.focus_ring = Color.rgba8(0, 0, 0, 0),
|
|
2454
|
+
},
|
|
2455
|
+
},
|
|
2456
|
+
.{ .id = 4, .kind = .row, .frame = geometry.RectF.init(0, 0, 0, 32) },
|
|
2457
|
+
};
|
|
2458
|
+
const children = [_]Widget{.{
|
|
2459
|
+
.id = 2,
|
|
2460
|
+
.kind = .input_group,
|
|
2461
|
+
.frame = geometry.RectF.init(0, 0, 200, 112),
|
|
2462
|
+
.children = &group_children,
|
|
2463
|
+
}};
|
|
2464
|
+
|
|
2465
|
+
var nodes: [4]WidgetLayoutNode = undefined;
|
|
2466
|
+
const layout = try layoutWidgetTree(.{ .kind = .stack, .children = &children }, geometry.RectF.init(0, 0, 240, 140), &nodes);
|
|
2467
|
+
|
|
2468
|
+
// Focus on the inner textarea: the GROUP's ring (part slot 3 on id 2)
|
|
2469
|
+
// is emitted — focus-within, not the group's own focus.
|
|
2470
|
+
var focused_commands: [24]CanvasCommand = undefined;
|
|
2471
|
+
var focused_builder = Builder.init(&focused_commands);
|
|
2472
|
+
try layout.emitDisplayListWithState(&focused_builder, tokens, .{ .focused_id = 3, .focus_visible_id = 3 });
|
|
2473
|
+
var saw_group_ring = false;
|
|
2474
|
+
for (focused_builder.displayList().commands) |command| {
|
|
2475
|
+
if (command.objectId()) |id| {
|
|
2476
|
+
if (id == widgetPartId(2, 3)) saw_group_ring = true;
|
|
2477
|
+
}
|
|
2478
|
+
}
|
|
2479
|
+
try std.testing.expect(saw_group_ring);
|
|
2480
|
+
|
|
2481
|
+
// No focus anywhere: no ring.
|
|
2482
|
+
var idle_commands: [24]CanvasCommand = undefined;
|
|
2483
|
+
var idle_builder = Builder.init(&idle_commands);
|
|
2484
|
+
try layout.emitDisplayListWithState(&idle_builder, tokens, .{});
|
|
2485
|
+
for (idle_builder.displayList().commands) |command| {
|
|
2486
|
+
if (command.objectId()) |id| {
|
|
2487
|
+
try std.testing.expect(id != widgetPartId(2, 3));
|
|
2488
|
+
}
|
|
2489
|
+
}
|
|
2490
|
+
|
|
2491
|
+
// Focus somewhere OUTSIDE the group's subtree: still no ring.
|
|
2492
|
+
var outside_commands: [24]CanvasCommand = undefined;
|
|
2493
|
+
var outside_builder = Builder.init(&outside_commands);
|
|
2494
|
+
try layout.emitDisplayListWithState(&outside_builder, tokens, .{ .focused_id = 99, .focus_visible_id = 99 });
|
|
2495
|
+
for (outside_builder.displayList().commands) |command| {
|
|
2496
|
+
if (command.objectId()) |id| {
|
|
2497
|
+
try std.testing.expect(id != widgetPartId(2, 3));
|
|
2498
|
+
}
|
|
2499
|
+
}
|
|
2500
|
+
}
|
|
2501
|
+
|
|
2502
|
+
test "input-group focus change dirties the group's ring region" {
|
|
2503
|
+
const tokens = DesignTokens{};
|
|
2504
|
+
const group_children = [_]Widget{
|
|
2505
|
+
.{ .id = 3, .kind = .textarea, .layout = .{ .grow = 1 } },
|
|
2506
|
+
};
|
|
2507
|
+
const children = [_]Widget{.{
|
|
2508
|
+
.id = 2,
|
|
2509
|
+
.kind = .input_group,
|
|
2510
|
+
.frame = geometry.RectF.init(20, 20, 200, 112),
|
|
2511
|
+
.children = &group_children,
|
|
2512
|
+
}};
|
|
2513
|
+
|
|
2514
|
+
var nodes: [3]WidgetLayoutNode = undefined;
|
|
2515
|
+
const layout = try layoutWidgetTree(.{ .kind = .stack, .children = &children }, geometry.RectF.init(0, 0, 260, 160), &nodes);
|
|
2516
|
+
|
|
2517
|
+
// Focus arriving on the inner textarea must dirty the GROUP's
|
|
2518
|
+
// focus-ring region (frame + ring offset + stroke), not just the
|
|
2519
|
+
// textarea's own bounds — the group wears the ring on its behalf.
|
|
2520
|
+
const dirty = layout.renderStateDirtyBoundsWithTokens(.{}, .{ .focused_id = 3, .focus_visible_id = 3 }, tokens).?;
|
|
2521
|
+
const ring = drawing_model.strokeBounds(widget_render_style.focusRingRect(geometry.RectF.init(20, 20, 200, 112), tokens), tokens.stroke.focus);
|
|
2522
|
+
try std.testing.expect(dirty.x <= ring.x);
|
|
2523
|
+
try std.testing.expect(dirty.y <= ring.y);
|
|
2524
|
+
try std.testing.expect(dirty.maxX() >= ring.maxX());
|
|
2525
|
+
try std.testing.expect(dirty.maxY() >= ring.maxY());
|
|
2526
|
+
}
|
|
2527
|
+
|
|
2528
|
+
test "widget layer tokens order display emission and hit testing" {
|
|
2529
|
+
const children = [_]Widget{
|
|
2530
|
+
.{
|
|
2531
|
+
.id = 2,
|
|
2532
|
+
.kind = .popover,
|
|
2533
|
+
.frame = geometry.RectF.init(8, 8, 96, 64),
|
|
2534
|
+
},
|
|
2535
|
+
.{
|
|
2536
|
+
.id = 3,
|
|
2537
|
+
.kind = .button,
|
|
2538
|
+
.frame = geometry.RectF.init(12, 12, 80, 32),
|
|
2539
|
+
.text = "Base",
|
|
2540
|
+
},
|
|
2541
|
+
};
|
|
2542
|
+
|
|
2543
|
+
var nodes: [3]WidgetLayoutNode = undefined;
|
|
2544
|
+
const layout = try layoutWidgetTree(.{ .kind = .stack, .children = &children }, geometry.RectF.init(0, 0, 120, 90), &nodes);
|
|
2545
|
+
|
|
2546
|
+
var commands: [8]CanvasCommand = undefined;
|
|
2547
|
+
var builder = Builder.init(&commands);
|
|
2548
|
+
try layout.emitDisplayList(&builder, .{});
|
|
2549
|
+
// The button contributes 3 flat commands (fill, border, label),
|
|
2550
|
+
// the popover 3 (its own shadow, fill, border).
|
|
2551
|
+
const display_list = builder.displayList();
|
|
2552
|
+
try std.testing.expectEqual(@as(usize, 6), display_list.commandCount());
|
|
2553
|
+
try std.testing.expectEqual(@as(?ObjectId, widgetPartId(3, 1)), display_list.commands[0].objectId());
|
|
2554
|
+
try std.testing.expectEqual(@as(?ObjectId, widgetPartId(2, 1)), display_list.commands[3].objectId());
|
|
2555
|
+
try std.testing.expectEqual(@as(ObjectId, 2), layout.hitTest(geometry.PointF.init(20, 20)).?.id);
|
|
2556
|
+
|
|
2557
|
+
const lowered_overlay = DesignTokens{
|
|
2558
|
+
.layer = .{
|
|
2559
|
+
.base = 10,
|
|
2560
|
+
.floating = 20,
|
|
2561
|
+
.overlay = 0,
|
|
2562
|
+
.modal = 30,
|
|
2563
|
+
},
|
|
2564
|
+
};
|
|
2565
|
+
var lowered_commands: [8]CanvasCommand = undefined;
|
|
2566
|
+
var lowered_builder = Builder.init(&lowered_commands);
|
|
2567
|
+
try layout.emitDisplayList(&lowered_builder, lowered_overlay);
|
|
2568
|
+
const lowered_display_list = lowered_builder.displayList();
|
|
2569
|
+
try std.testing.expectEqual(@as(?ObjectId, widgetPartId(2, 1)), lowered_display_list.commands[0].objectId());
|
|
2570
|
+
try std.testing.expectEqual(@as(?ObjectId, widgetPartId(3, 1)), lowered_display_list.commands[3].objectId());
|
|
2571
|
+
try std.testing.expectEqual(@as(ObjectId, 3), layout.hitTestWithTokens(geometry.PointF.init(20, 20), lowered_overlay).?.id);
|
|
2572
|
+
}
|
|
2573
|
+
|
|
2574
|
+
test "widget explicit layers override token defaults for overlay ordering" {
|
|
2575
|
+
const children = [_]Widget{
|
|
2576
|
+
.{
|
|
2577
|
+
.id = 2,
|
|
2578
|
+
.kind = .popover,
|
|
2579
|
+
.frame = geometry.RectF.init(8, 8, 96, 64),
|
|
2580
|
+
},
|
|
2581
|
+
.{
|
|
2582
|
+
.id = 3,
|
|
2583
|
+
.kind = .button,
|
|
2584
|
+
.frame = geometry.RectF.init(12, 12, 80, 32),
|
|
2585
|
+
.text = "Top",
|
|
2586
|
+
.layer = 500,
|
|
2587
|
+
},
|
|
2588
|
+
};
|
|
2589
|
+
|
|
2590
|
+
var nodes: [3]WidgetLayoutNode = undefined;
|
|
2591
|
+
const layout = try layoutWidgetTree(.{ .kind = .stack, .children = &children }, geometry.RectF.init(0, 0, 120, 90), &nodes);
|
|
2592
|
+
|
|
2593
|
+
var commands: [8]CanvasCommand = undefined;
|
|
2594
|
+
var builder = Builder.init(&commands);
|
|
2595
|
+
try layout.emitDisplayList(&builder, .{});
|
|
2596
|
+
// The popover's 3 chrome commands paint first; the elevated flat
|
|
2597
|
+
// button's fill follows directly.
|
|
2598
|
+
const display_list = builder.displayList();
|
|
2599
|
+
try std.testing.expectEqual(@as(?ObjectId, widgetPartId(2, 1)), display_list.commands[0].objectId());
|
|
2600
|
+
try std.testing.expectEqual(@as(?ObjectId, widgetPartId(3, 1)), display_list.commands[3].objectId());
|
|
2601
|
+
try std.testing.expectEqual(@as(ObjectId, 3), layout.hitTest(geometry.PointF.init(20, 20)).?.id);
|
|
2602
|
+
}
|
|
2603
|
+
|
|
2604
|
+
test "widget emitter renders checkbox radio switch and slider controls" {
|
|
2605
|
+
const tokens = DesignTokens{
|
|
2606
|
+
.colors = .{
|
|
2607
|
+
.accent = Color.rgb8(10, 20, 30),
|
|
2608
|
+
.accent_text = Color.rgb8(240, 241, 242),
|
|
2609
|
+
.focus_ring = Color.rgb8(1, 2, 3),
|
|
2610
|
+
},
|
|
2611
|
+
.stroke = .{ .focus = 3 },
|
|
2612
|
+
};
|
|
2613
|
+
var commands: [20]CanvasCommand = undefined;
|
|
2614
|
+
var builder = Builder.init(&commands);
|
|
2615
|
+
try emitWidgetTree(&builder, .{
|
|
2616
|
+
.id = 10,
|
|
2617
|
+
.kind = .checkbox,
|
|
2618
|
+
.frame = geometry.RectF.init(0, 0, 120, 32),
|
|
2619
|
+
.text = "Live",
|
|
2620
|
+
.state = .{ .selected = true, .focused = true },
|
|
2621
|
+
}, tokens);
|
|
2622
|
+
try emitWidgetTree(&builder, .{
|
|
2623
|
+
.id = 11,
|
|
2624
|
+
.kind = .radio,
|
|
2625
|
+
.frame = geometry.RectF.init(0, 40, 120, 32),
|
|
2626
|
+
.text = "Monthly",
|
|
2627
|
+
.state = .{ .selected = true, .focused = true },
|
|
2628
|
+
}, tokens);
|
|
2629
|
+
try emitWidgetTree(&builder, .{
|
|
2630
|
+
.id = 12,
|
|
2631
|
+
.kind = .switch_control,
|
|
2632
|
+
.frame = geometry.RectF.init(0, 80, 120, 32),
|
|
2633
|
+
.text = "Mode",
|
|
2634
|
+
.value = 1,
|
|
2635
|
+
}, tokens);
|
|
2636
|
+
try emitWidgetTree(&builder, .{
|
|
2637
|
+
.id = 13,
|
|
2638
|
+
.kind = .slider,
|
|
2639
|
+
.frame = geometry.RectF.init(0, 124, 160, 32),
|
|
2640
|
+
.value = 0.25,
|
|
2641
|
+
.state = .{ .focused = true },
|
|
2642
|
+
}, tokens);
|
|
2643
|
+
|
|
2644
|
+
const display_list = builder.displayList();
|
|
2645
|
+
try std.testing.expectEqual(@as(usize, 19), display_list.commandCount());
|
|
2646
|
+
switch (display_list.commands[0]) {
|
|
2647
|
+
.fill_rounded_rect => |fill| try expectFillColor(tokens.colors.accent, fill.fill),
|
|
2648
|
+
else => return error.TestUnexpectedResult,
|
|
2649
|
+
}
|
|
2650
|
+
try std.testing.expect(display_list.commands[3] == .draw_line);
|
|
2651
|
+
try std.testing.expect(display_list.commands[4] == .draw_line);
|
|
2652
|
+
switch (display_list.commands[5]) {
|
|
2653
|
+
.draw_text => |text| try std.testing.expectEqualStrings("Live", text.text),
|
|
2654
|
+
else => return error.TestUnexpectedResult,
|
|
2655
|
+
}
|
|
2656
|
+
switch (display_list.commands[6]) {
|
|
2657
|
+
.fill_rounded_rect => |fill| try expectFillColor(tokens.colors.surface, fill.fill),
|
|
2658
|
+
else => return error.TestUnexpectedResult,
|
|
2659
|
+
}
|
|
2660
|
+
switch (display_list.commands[9]) {
|
|
2661
|
+
.fill_rounded_rect => |fill| {
|
|
2662
|
+
try std.testing.expectEqual(@as(ObjectId, widgetPartId(11, 4)), fill.id);
|
|
2663
|
+
try expectFillColor(tokens.colors.accent, fill.fill);
|
|
2664
|
+
},
|
|
2665
|
+
else => return error.TestUnexpectedResult,
|
|
2666
|
+
}
|
|
2667
|
+
switch (display_list.commands[10]) {
|
|
2668
|
+
.draw_text => |text| try std.testing.expectEqualStrings("Monthly", text.text),
|
|
2669
|
+
else => return error.TestUnexpectedResult,
|
|
2670
|
+
}
|
|
2671
|
+
switch (display_list.commands[11]) {
|
|
2672
|
+
.fill_rounded_rect => |fill| try expectFillColor(tokens.colors.accent, fill.fill),
|
|
2673
|
+
else => return error.TestUnexpectedResult,
|
|
2674
|
+
}
|
|
2675
|
+
// The switch track is borderless now, so the toggle's label follows
|
|
2676
|
+
// its fill and knob directly.
|
|
2677
|
+
switch (display_list.commands[13]) {
|
|
2678
|
+
.draw_text => |text| try std.testing.expectEqualStrings("Mode", text.text),
|
|
2679
|
+
else => return error.TestUnexpectedResult,
|
|
2680
|
+
}
|
|
2681
|
+
// 4px slider rail centered in the 32px row: y = 124 + 14.
|
|
2682
|
+
switch (display_list.commands[15]) {
|
|
2683
|
+
.fill_rounded_rect => |fill| try expectRect(geometry.RectF.init(0, 138, 40, 4), fill.rect),
|
|
2684
|
+
else => return error.TestUnexpectedResult,
|
|
2685
|
+
}
|
|
2686
|
+
// The knob's resting hairline wears the focus-ring neutral; focus
|
|
2687
|
+
// adds the offset ring in the same color outside it.
|
|
2688
|
+
switch (display_list.commands[17]) {
|
|
2689
|
+
.stroke_rect => |stroke| {
|
|
2690
|
+
try std.testing.expectEqual(@as(ObjectId, widgetPartId(13, 4)), stroke.id);
|
|
2691
|
+
try expectFillColor(tokens.colors.focus_ring, stroke.stroke.fill);
|
|
2692
|
+
},
|
|
2693
|
+
else => return error.TestUnexpectedResult,
|
|
2694
|
+
}
|
|
2695
|
+
switch (display_list.commands[18]) {
|
|
2696
|
+
.stroke_rect => |stroke| {
|
|
2697
|
+
try std.testing.expectEqual(@as(ObjectId, widgetPartId(13, 5)), stroke.id);
|
|
2698
|
+
try std.testing.expectEqual(@as(f32, 3), stroke.stroke.width);
|
|
2699
|
+
try expectFillColor(tokens.colors.focus_ring, stroke.stroke.fill);
|
|
2700
|
+
},
|
|
2701
|
+
else => return error.TestUnexpectedResult,
|
|
2702
|
+
}
|
|
2703
|
+
}
|
|
2704
|
+
|
|
2705
|
+
test "checkbox radio and switch focus rings stay on the control glyph" {
|
|
2706
|
+
const tokens = DesignTokens{
|
|
2707
|
+
.colors = .{ .focus_ring = Color.rgb8(1, 2, 3) },
|
|
2708
|
+
.stroke = .{ .focus = 3 },
|
|
2709
|
+
};
|
|
2710
|
+
|
|
2711
|
+
var checkbox_commands: [8]CanvasCommand = undefined;
|
|
2712
|
+
var checkbox_builder = Builder.init(&checkbox_commands);
|
|
2713
|
+
try emitWidgetTree(&checkbox_builder, .{
|
|
2714
|
+
.id = 20,
|
|
2715
|
+
.kind = .checkbox,
|
|
2716
|
+
.frame = geometry.RectF.init(10, 10, 160, 32),
|
|
2717
|
+
.text = "Live",
|
|
2718
|
+
.state = .{ .focused = true },
|
|
2719
|
+
}, tokens);
|
|
2720
|
+
const checkbox_display_list = checkbox_builder.displayList();
|
|
2721
|
+
const checkbox_box = checkbox_display_list.findCommandById(widgetPartId(20, 2)).?.command;
|
|
2722
|
+
const checkbox_focus = checkbox_display_list.findCommandById(widgetPartId(20, 3)).?.command;
|
|
2723
|
+
switch (checkbox_box) {
|
|
2724
|
+
.stroke_rect => |box| switch (checkbox_focus) {
|
|
2725
|
+
.stroke_rect => |focus| {
|
|
2726
|
+
// The ring wraps the box 2px outside it — still glyph-
|
|
2727
|
+
// sized, nowhere near the clickable label's row width.
|
|
2728
|
+
try std.testing.expectEqualDeep(widget_render_style.focusRingRect(box.rect, tokens), focus.rect);
|
|
2729
|
+
try std.testing.expect(focus.rect.width < 32);
|
|
2730
|
+
try std.testing.expect(focus.rect.width < 160);
|
|
2731
|
+
try expectFillColor(tokens.colors.focus_ring, focus.stroke.fill);
|
|
2732
|
+
},
|
|
2733
|
+
else => return error.TestUnexpectedResult,
|
|
2734
|
+
},
|
|
2735
|
+
else => return error.TestUnexpectedResult,
|
|
2736
|
+
}
|
|
2737
|
+
|
|
2738
|
+
var radio_commands: [8]CanvasCommand = undefined;
|
|
2739
|
+
var radio_builder = Builder.init(&radio_commands);
|
|
2740
|
+
try emitWidgetTree(&radio_builder, .{
|
|
2741
|
+
.id = 21,
|
|
2742
|
+
.kind = .radio,
|
|
2743
|
+
.frame = geometry.RectF.init(10, 52, 160, 32),
|
|
2744
|
+
.text = "Monthly",
|
|
2745
|
+
.state = .{ .focused = true },
|
|
2746
|
+
}, tokens);
|
|
2747
|
+
const radio_display_list = radio_builder.displayList();
|
|
2748
|
+
const radio_circle = radio_display_list.findCommandById(widgetPartId(21, 2)).?.command;
|
|
2749
|
+
const radio_focus = radio_display_list.findCommandById(widgetPartId(21, 3)).?.command;
|
|
2750
|
+
switch (radio_circle) {
|
|
2751
|
+
.stroke_rect => |circle| switch (radio_focus) {
|
|
2752
|
+
.stroke_rect => |focus| {
|
|
2753
|
+
try std.testing.expectEqualDeep(widget_render_style.focusRingRect(circle.rect, tokens), focus.rect);
|
|
2754
|
+
try std.testing.expect(focus.rect.width < 32);
|
|
2755
|
+
try std.testing.expect(focus.rect.width < 160);
|
|
2756
|
+
try expectFillColor(tokens.colors.focus_ring, focus.stroke.fill);
|
|
2757
|
+
},
|
|
2758
|
+
else => return error.TestUnexpectedResult,
|
|
2759
|
+
},
|
|
2760
|
+
else => return error.TestUnexpectedResult,
|
|
2761
|
+
}
|
|
2762
|
+
|
|
2763
|
+
var switch_commands: [8]CanvasCommand = undefined;
|
|
2764
|
+
var switch_builder = Builder.init(&switch_commands);
|
|
2765
|
+
try emitWidgetTree(&switch_builder, .{
|
|
2766
|
+
.id = 22,
|
|
2767
|
+
.kind = .switch_control,
|
|
2768
|
+
.frame = geometry.RectF.init(10, 94, 160, 32),
|
|
2769
|
+
.text = "Alerts",
|
|
2770
|
+
.state = .{ .focused = true },
|
|
2771
|
+
}, tokens);
|
|
2772
|
+
const switch_display_list = switch_builder.displayList();
|
|
2773
|
+
// The borderless track's fill (slot 1) anchors the ring geometry.
|
|
2774
|
+
const switch_track = switch_display_list.findCommandById(widgetPartId(22, 1)).?.command;
|
|
2775
|
+
const switch_focus = switch_display_list.findCommandById(widgetPartId(22, 4)).?.command;
|
|
2776
|
+
switch (switch_track) {
|
|
2777
|
+
.fill_rounded_rect => |track| switch (switch_focus) {
|
|
2778
|
+
.stroke_rect => |focus| {
|
|
2779
|
+
try std.testing.expectEqualDeep(widget_render_style.focusRingRect(track.rect, tokens), focus.rect);
|
|
2780
|
+
try std.testing.expect(focus.rect.width < 80);
|
|
2781
|
+
try std.testing.expect(focus.rect.width < 160);
|
|
2782
|
+
try expectFillColor(tokens.colors.focus_ring, focus.stroke.fill);
|
|
2783
|
+
},
|
|
2784
|
+
else => return error.TestUnexpectedResult,
|
|
2785
|
+
},
|
|
2786
|
+
else => return error.TestUnexpectedResult,
|
|
2787
|
+
}
|
|
2788
|
+
}
|
|
2789
|
+
|
|
2790
|
+
test "selection control focus bounds exclude clickable labels" {
|
|
2791
|
+
const tokens = DesignTokens{
|
|
2792
|
+
.stroke = .{ .focus = 4 },
|
|
2793
|
+
};
|
|
2794
|
+
const children = [_]Widget{
|
|
2795
|
+
.{
|
|
2796
|
+
.id = 20,
|
|
2797
|
+
.kind = .checkbox,
|
|
2798
|
+
.frame = geometry.RectF.init(10, 10, 160, 32),
|
|
2799
|
+
.text = "Selected",
|
|
2800
|
+
},
|
|
2801
|
+
.{
|
|
2802
|
+
.id = 21,
|
|
2803
|
+
.kind = .switch_control,
|
|
2804
|
+
.frame = geometry.RectF.init(10, 52, 160, 32),
|
|
2805
|
+
.text = "Live",
|
|
2806
|
+
},
|
|
2807
|
+
};
|
|
2808
|
+
|
|
2809
|
+
var nodes: [3]WidgetLayoutNode = undefined;
|
|
2810
|
+
const layout = try layoutWidgetTree(.{ .kind = .stack, .children = &children }, geometry.RectF.init(0, 0, 220, 100), &nodes);
|
|
2811
|
+
|
|
2812
|
+
const checkbox_label_hit = layout.hitTest(geometry.PointF.init(80, 26)).?;
|
|
2813
|
+
try std.testing.expectEqual(@as(ObjectId, 20), checkbox_label_hit.id);
|
|
2814
|
+
try std.testing.expectEqual(WidgetKind.checkbox, checkbox_label_hit.kind);
|
|
2815
|
+
|
|
2816
|
+
const switch_label_hit = layout.hitTest(geometry.PointF.init(100, 68)).?;
|
|
2817
|
+
try std.testing.expectEqual(@as(ObjectId, 21), switch_label_hit.id);
|
|
2818
|
+
try std.testing.expectEqual(WidgetKind.switch_control, switch_label_hit.kind);
|
|
2819
|
+
|
|
2820
|
+
// Dirty bounds cover the offset ring: control glyph + 2px ring
|
|
2821
|
+
// offset + half the 4px focus stroke on every side.
|
|
2822
|
+
try expectRectApprox(
|
|
2823
|
+
geometry.RectF.init(6, 13.2, 25.6, 25.6),
|
|
2824
|
+
layout.renderStateDirtyBoundsWithTokens(.{}, .{ .focused_id = 20, .focus_visible_id = 20 }, tokens),
|
|
2825
|
+
);
|
|
2826
|
+
try expectRect(
|
|
2827
|
+
geometry.RectF.init(6, 52, 64, 32),
|
|
2828
|
+
layout.renderStateDirtyBoundsWithTokens(.{}, .{ .focused_id = 21, .focus_visible_id = 21 }, tokens),
|
|
2829
|
+
);
|
|
2830
|
+
}
|
|
2831
|
+
|
|
2832
|
+
test "hover target resolves composite row children to the row" {
|
|
2833
|
+
// A two-line list row: title text, then a snippet line inside a
|
|
2834
|
+
// nested row with a link — the shape the notes/feed list panes
|
|
2835
|
+
// render. Probe points derive from the LAID-OUT frames so the test
|
|
2836
|
+
// pins behavior, not layout arithmetic.
|
|
2837
|
+
const snippet = Widget{ .id = 6, .kind = .text, .frame = geometry.RectF.init(0, 0, 140, 20), .text = "Snippet line" };
|
|
2838
|
+
const link = Widget{ .id = 7, .kind = .text, .frame = geometry.RectF.init(0, 0, 50, 20), .text = "More", .semantics = .{ .role = .link } };
|
|
2839
|
+
const inner_row = Widget{ .id = 5, .kind = .row, .frame = geometry.RectF.init(0, 0, 0, 20), .layout = .{ .gap = 8 }, .children = &.{ snippet, link } };
|
|
2840
|
+
const title = Widget{ .id = 4, .kind = .text, .frame = geometry.RectF.init(0, 0, 120, 20), .text = "Title" };
|
|
2841
|
+
const column = Widget{ .id = 3, .kind = .column, .layout = .{ .gap = 8 }, .children = &.{ title, inner_row } };
|
|
2842
|
+
const row = Widget{ .id = 2, .kind = .list_item, .frame = geometry.RectF.init(0, 0, 0, 72), .layout = .{ .padding = geometry.InsetsF.all(10) }, .children = &.{column} };
|
|
2843
|
+
const caption = Widget{ .id = 8, .kind = .text, .frame = geometry.RectF.init(0, 90, 120, 20), .text = "Bare caption" };
|
|
2844
|
+
|
|
2845
|
+
var nodes: [8]WidgetLayoutNode = undefined;
|
|
2846
|
+
const layout = try layoutWidgetTree(.{ .kind = .stack, .children = &.{ row, caption } }, geometry.RectF.init(0, 0, 320, 130), &nodes);
|
|
2847
|
+
|
|
2848
|
+
const row_frame = layout.findById(2).?.frame.normalized();
|
|
2849
|
+
const title_frame = layout.findById(4).?.frame.normalized();
|
|
2850
|
+
const snippet_frame = layout.findById(6).?.frame.normalized();
|
|
2851
|
+
const link_frame = layout.findById(7).?.frame.normalized();
|
|
2852
|
+
|
|
2853
|
+
// The raw hit over the title line is the text child; hover resolves
|
|
2854
|
+
// to the row, so the wash covers the whole row. The cursor stays the
|
|
2855
|
+
// native arrow — rows are controls, and the hand belongs to links.
|
|
2856
|
+
const title_hit = layout.hitTest(title_frame.center()).?;
|
|
2857
|
+
try std.testing.expectEqual(@as(ObjectId, 4), title_hit.id);
|
|
2858
|
+
const title_hover = layout.hoverTargetForHit(title_hit).?;
|
|
2859
|
+
try std.testing.expectEqual(@as(ObjectId, 2), title_hover.id);
|
|
2860
|
+
try std.testing.expectEqual(WidgetKind.list_item, title_hover.kind);
|
|
2861
|
+
try std.testing.expectEqual(WidgetCursor.arrow, layout.cursorForHit(title_hover));
|
|
2862
|
+
|
|
2863
|
+
// The snippet line, the gap between the lines, and the row's own
|
|
2864
|
+
// padding corner all belong to the row too.
|
|
2865
|
+
const snippet_hover = layout.hoverTargetForHit(layout.hitTest(snippet_frame.center())).?;
|
|
2866
|
+
try std.testing.expectEqual(@as(ObjectId, 2), snippet_hover.id);
|
|
2867
|
+
const gap_point = geometry.PointF.init(title_frame.center().x, (title_frame.maxY() + snippet_frame.y) / 2);
|
|
2868
|
+
const gap_hover = layout.hoverTargetForHit(layout.hitTest(gap_point)).?;
|
|
2869
|
+
try std.testing.expectEqual(@as(ObjectId, 2), gap_hover.id);
|
|
2870
|
+
const corner_point = geometry.PointF.init(row_frame.x + 3, row_frame.y + 3);
|
|
2871
|
+
const corner_hover = layout.hoverTargetForHit(layout.hitTest(corner_point)).?;
|
|
2872
|
+
try std.testing.expectEqual(@as(ObjectId, 2), corner_hover.id);
|
|
2873
|
+
|
|
2874
|
+
// A link keeps its own hover: the pointer cursor is the link's
|
|
2875
|
+
// affordance even inside a pressable row.
|
|
2876
|
+
const link_hover = layout.hoverTargetForHit(layout.hitTest(link_frame.center())).?;
|
|
2877
|
+
try std.testing.expectEqual(@as(ObjectId, 7), link_hover.id);
|
|
2878
|
+
try std.testing.expectEqual(WidgetCursor.pointing_hand, layout.cursorForHit(link_hover));
|
|
2879
|
+
|
|
2880
|
+
// Bare text with no claiming ancestor keeps itself (selection
|
|
2881
|
+
// affordance), and stays on the default cursor.
|
|
2882
|
+
const caption_frame = layout.findById(8).?.frame.normalized();
|
|
2883
|
+
const caption_hover = layout.hoverTargetForHit(layout.hitTest(caption_frame.center())).?;
|
|
2884
|
+
try std.testing.expectEqual(@as(ObjectId, 8), caption_hover.id);
|
|
2885
|
+
try std.testing.expectEqual(WidgetCursor.arrow, layout.cursorForHit(caption_hover));
|
|
2886
|
+
}
|
|
2887
|
+
|
|
2888
|
+
test "widget emitter renders list item and segmented control states" {
|
|
2889
|
+
const tokens = DesignTokens{
|
|
2890
|
+
.colors = .{
|
|
2891
|
+
.accent = Color.rgb8(10, 20, 30),
|
|
2892
|
+
.accent_text = Color.rgb8(240, 241, 242),
|
|
2893
|
+
.focus_ring = Color.rgb8(1, 2, 3),
|
|
2894
|
+
.surface_pressed = Color.rgb8(220, 224, 230),
|
|
2895
|
+
},
|
|
2896
|
+
.stroke = .{ .focus = 3 },
|
|
2897
|
+
};
|
|
2898
|
+
var commands: [7]CanvasCommand = undefined;
|
|
2899
|
+
var builder = Builder.init(&commands);
|
|
2900
|
+
try emitWidgetTree(&builder, .{
|
|
2901
|
+
.id = 20,
|
|
2902
|
+
.kind = .list_item,
|
|
2903
|
+
.frame = geometry.RectF.init(0, 0, 160, 32),
|
|
2904
|
+
.text = "Inbox",
|
|
2905
|
+
.state = .{ .selected = true, .focused = true },
|
|
2906
|
+
}, tokens);
|
|
2907
|
+
try emitWidgetTree(&builder, .{
|
|
2908
|
+
.id = 21,
|
|
2909
|
+
.kind = .segmented_control,
|
|
2910
|
+
.frame = geometry.RectF.init(0, 40, 96, 32),
|
|
2911
|
+
.text = "Open",
|
|
2912
|
+
.state = .{ .selected = true, .focused = true },
|
|
2913
|
+
}, tokens);
|
|
2914
|
+
|
|
2915
|
+
const display_list = builder.displayList();
|
|
2916
|
+
try std.testing.expectEqual(@as(usize, 7), display_list.commandCount());
|
|
2917
|
+
switch (display_list.commands[0]) {
|
|
2918
|
+
.fill_rounded_rect => |fill| try expectFillColor(tokens.colors.surface_pressed, fill.fill),
|
|
2919
|
+
else => return error.TestUnexpectedResult,
|
|
2920
|
+
}
|
|
2921
|
+
switch (display_list.commands[1]) {
|
|
2922
|
+
.stroke_rect => |stroke| try expectFillColor(tokens.colors.focus_ring, stroke.stroke.fill),
|
|
2923
|
+
else => return error.TestUnexpectedResult,
|
|
2924
|
+
}
|
|
2925
|
+
switch (display_list.commands[2]) {
|
|
2926
|
+
.draw_text => |text| try std.testing.expectEqualStrings("Inbox", text.text),
|
|
2927
|
+
else => return error.TestUnexpectedResult,
|
|
2928
|
+
}
|
|
2929
|
+
// The active tab lifts to the page surface with a hairline border;
|
|
2930
|
+
// its label stays on the foreground, not the accent text.
|
|
2931
|
+
switch (display_list.commands[3]) {
|
|
2932
|
+
.fill_rounded_rect => |fill| try expectFillColor(tokens.colors.surface, fill.fill),
|
|
2933
|
+
else => return error.TestUnexpectedResult,
|
|
2934
|
+
}
|
|
2935
|
+
switch (display_list.commands[4]) {
|
|
2936
|
+
.stroke_rect => |stroke| try expectFillColor(tokens.colors.border, stroke.stroke.fill),
|
|
2937
|
+
else => return error.TestUnexpectedResult,
|
|
2938
|
+
}
|
|
2939
|
+
switch (display_list.commands[5]) {
|
|
2940
|
+
.stroke_rect => |stroke| {
|
|
2941
|
+
try std.testing.expectEqual(@as(f32, 3), stroke.stroke.width);
|
|
2942
|
+
try expectFillColor(tokens.colors.focus_ring, stroke.stroke.fill);
|
|
2943
|
+
},
|
|
2944
|
+
else => return error.TestUnexpectedResult,
|
|
2945
|
+
}
|
|
2946
|
+
switch (display_list.commands[6]) {
|
|
2947
|
+
.draw_text => |text| try std.testing.expectEqualDeep(tokens.colors.text, text.color),
|
|
2948
|
+
else => return error.TestUnexpectedResult,
|
|
2949
|
+
}
|
|
2950
|
+
}
|
|
2951
|
+
|
|
2952
|
+
test "widget emitter reports depth and display list overflow" {
|
|
2953
|
+
var tiny_commands: [2]CanvasCommand = undefined;
|
|
2954
|
+
var tiny_builder = Builder.init(&tiny_commands);
|
|
2955
|
+
try std.testing.expectError(error.DisplayListFull, emitWidgetTree(&tiny_builder, .{
|
|
2956
|
+
.kind = .button,
|
|
2957
|
+
.frame = geometry.RectF.init(0, 0, 120, 36),
|
|
2958
|
+
.text = "Overflow",
|
|
2959
|
+
}, .{}));
|
|
2960
|
+
|
|
2961
|
+
var widgets: [max_widget_depth + 1]Widget = undefined;
|
|
2962
|
+
var index = widgets.len;
|
|
2963
|
+
while (index > 0) {
|
|
2964
|
+
index -= 1;
|
|
2965
|
+
widgets[index] = .{
|
|
2966
|
+
.kind = .stack,
|
|
2967
|
+
.children = if (index + 1 < widgets.len) widgets[index + 1 .. index + 2] else &.{},
|
|
2968
|
+
};
|
|
2969
|
+
}
|
|
2970
|
+
|
|
2971
|
+
var commands: [1]CanvasCommand = undefined;
|
|
2972
|
+
var builder = Builder.init(&commands);
|
|
2973
|
+
try std.testing.expectError(error.WidgetDepthExceeded, emitWidgetTree(&builder, widgets[0], .{}));
|
|
2974
|
+
}
|
|
2975
|
+
|
|
2976
|
+
test "widget control aim point targets the rendered glyph of stretched selection controls" {
|
|
2977
|
+
const tokens: canvas.DesignTokens = .{};
|
|
2978
|
+
// A stretched switch: 718px frame, ~42px track at the left edge.
|
|
2979
|
+
const stretched: canvas.Widget = .{
|
|
2980
|
+
.id = 5,
|
|
2981
|
+
.kind = .switch_control,
|
|
2982
|
+
.frame = geometry.RectF.init(0, 100, 718, 24),
|
|
2983
|
+
.text = "Group",
|
|
2984
|
+
};
|
|
2985
|
+
const switch_aim = canvas.widgetControlAimPoint(stretched, tokens);
|
|
2986
|
+
try std.testing.expect(switch_aim.x < 60);
|
|
2987
|
+
try std.testing.expectApproxEqAbs(@as(f32, 112), switch_aim.y, 1);
|
|
2988
|
+
|
|
2989
|
+
const checkbox: canvas.Widget = .{
|
|
2990
|
+
.id = 6,
|
|
2991
|
+
.kind = .checkbox,
|
|
2992
|
+
.frame = geometry.RectF.init(0, 0, 500, 28),
|
|
2993
|
+
.text = "Live",
|
|
2994
|
+
};
|
|
2995
|
+
try std.testing.expect(canvas.widgetControlAimPoint(checkbox, tokens).x < 30);
|
|
2996
|
+
|
|
2997
|
+
const radio: canvas.Widget = .{
|
|
2998
|
+
.id = 7,
|
|
2999
|
+
.kind = .radio,
|
|
3000
|
+
.frame = geometry.RectF.init(0, 0, 500, 28),
|
|
3001
|
+
.text = "Monthly",
|
|
3002
|
+
};
|
|
3003
|
+
try std.testing.expect(canvas.widgetControlAimPoint(radio, tokens).x < 30);
|
|
3004
|
+
|
|
3005
|
+
// Non-selection controls keep the frame center.
|
|
3006
|
+
const button: canvas.Widget = .{
|
|
3007
|
+
.id = 8,
|
|
3008
|
+
.kind = .button,
|
|
3009
|
+
.frame = geometry.RectF.init(0, 0, 500, 44),
|
|
3010
|
+
.text = "Save",
|
|
3011
|
+
};
|
|
3012
|
+
const button_aim = canvas.widgetControlAimPoint(button, tokens);
|
|
3013
|
+
try std.testing.expectApproxEqAbs(@as(f32, 250), button_aim.x, 0.01);
|
|
3014
|
+
try std.testing.expectApproxEqAbs(@as(f32, 22), button_aim.y, 0.01);
|
|
3015
|
+
}
|