@native-sdk/cli 0.0.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +176 -0
- package/README.md +50 -1
- package/app.zon +30 -0
- package/bin/native.js +156 -0
- package/build/app.zig +716 -0
- package/build.zig +2593 -0
- package/build.zig.zon +24 -0
- package/native-sdk.d.ts +615 -0
- package/package.json +44 -8
- package/skill-data/automation/SKILL.md +248 -0
- package/skill-data/core/SKILL.md +249 -0
- package/skill-data/core/references/app-model-runtime.md +141 -0
- package/skill-data/core/references/bridge-security-native-capabilities.md +230 -0
- package/skill-data/core/references/frontend-assets.md +124 -0
- package/skill-data/core/references/project-anatomy.md +108 -0
- package/skill-data/core/references/web-engines-packaging-debugging.md +199 -0
- package/skill-data/native-ui/SKILL.md +1080 -0
- package/skills/native-sdk/SKILL.md +33 -0
- package/src/app_runner/root.zig +740 -0
- package/src/assets/root.zig +20 -0
- package/src/automation/protocol.zig +285 -0
- package/src/automation/root.zig +13 -0
- package/src/automation/server.zig +506 -0
- package/src/automation/snapshot.zig +1202 -0
- package/src/automation/watcher.zig +165 -0
- package/src/bridge/root.zig +507 -0
- package/src/debug/root.zig +246 -0
- package/src/embed/app_exports.zig +11 -0
- package/src/embed/c_api.zig +793 -0
- package/src/embed/c_exports.zig +10 -0
- package/src/embed/chrome.zig +168 -0
- package/src/embed/conversions.zig +359 -0
- package/src/embed/host.zig +960 -0
- package/src/embed/root.zig +81 -0
- package/src/embed/tests.zig +2552 -0
- package/src/embed/types.zig +382 -0
- package/src/embed/ui_host.zig +289 -0
- package/src/extensions/root.zig +197 -0
- package/src/frontend/root.zig +48 -0
- package/src/js/root.zig +65 -0
- package/src/platform/android/NativeSdkActivity.java +1370 -0
- package/src/platform/android/android_host.c +696 -0
- package/src/platform/android/files.zig +9 -0
- package/src/platform/android/native_sdk_app.h +237 -0
- package/src/platform/ios/files.zig +8 -0
- package/src/platform/ios/native_sdk_app.h +289 -0
- package/src/platform/ios/uikit_host.m +2739 -0
- package/src/platform/linux/cef_host.cpp +599 -0
- package/src/platform/linux/gtk_host.c +5362 -0
- package/src/platform/linux/gtk_host.h +265 -0
- package/src/platform/linux/root.zig +1519 -0
- package/src/platform/macos/appkit_host.h +604 -0
- package/src/platform/macos/appkit_host.m +10392 -0
- package/src/platform/macos/automation_host.h +14 -0
- package/src/platform/macos/automation_host.m +12 -0
- package/src/platform/macos/cef_host.mm +3028 -0
- package/src/platform/macos/root.zig +2260 -0
- package/src/platform/null_platform.zig +2232 -0
- package/src/platform/null_platform_tests.zig +670 -0
- package/src/platform/policy_values.zig +14 -0
- package/src/platform/root.zig +181 -0
- package/src/platform/types.zig +2681 -0
- package/src/platform/windows/cef_host.cpp +3 -0
- package/src/platform/windows/root.zig +1521 -0
- package/src/platform/windows/webview2_host.cpp +6230 -0
- package/src/primitives/app_dirs/root.zig +440 -0
- package/src/primitives/app_manifest/root.zig +109 -0
- package/src/primitives/app_manifest/tests.zig +758 -0
- package/src/primitives/app_manifest/types.zig +587 -0
- package/src/primitives/app_manifest/validation.zig +828 -0
- package/src/primitives/assets/root.zig +520 -0
- package/src/primitives/canvas/a11y_audit.zig +390 -0
- package/src/primitives/canvas/a11y_audit_tests.zig +225 -0
- package/src/primitives/canvas/app_icon.zig +1590 -0
- package/src/primitives/canvas/chart.zig +392 -0
- package/src/primitives/canvas/chart_tests.zig +751 -0
- package/src/primitives/canvas/commands.zig +446 -0
- package/src/primitives/canvas/drawing.zig +309 -0
- package/src/primitives/canvas/equality.zig +316 -0
- package/src/primitives/canvas/events.zig +696 -0
- package/src/primitives/canvas/font_coverage.zig +118 -0
- package/src/primitives/canvas/font_ttf.zig +510 -0
- package/src/primitives/canvas/font_ttf_tests.zig +280 -0
- package/src/primitives/canvas/fonts/Geist-Regular.ttf +0 -0
- package/src/primitives/canvas/fonts/GeistMono-Regular.ttf +0 -0
- package/src/primitives/canvas/frame.zig +679 -0
- package/src/primitives/canvas/frame_metrics.zig +462 -0
- package/src/primitives/canvas/gpu.zig +639 -0
- package/src/primitives/canvas/hash.zig +112 -0
- package/src/primitives/canvas/icons/alert.svg +1 -0
- package/src/primitives/canvas/icons/archive.svg +1 -0
- package/src/primitives/canvas/icons/arrow-down.svg +1 -0
- package/src/primitives/canvas/icons/arrow-right.svg +1 -0
- package/src/primitives/canvas/icons/arrow-up.svg +1 -0
- package/src/primitives/canvas/icons/check-circle.svg +1 -0
- package/src/primitives/canvas/icons/check.svg +1 -0
- package/src/primitives/canvas/icons/chevron-down.svg +1 -0
- package/src/primitives/canvas/icons/chevron-left.svg +1 -0
- package/src/primitives/canvas/icons/chevron-right.svg +1 -0
- package/src/primitives/canvas/icons/chevron-up.svg +1 -0
- package/src/primitives/canvas/icons/circle-dot.svg +1 -0
- package/src/primitives/canvas/icons/clock.svg +1 -0
- package/src/primitives/canvas/icons/copy.svg +1 -0
- package/src/primitives/canvas/icons/download.svg +1 -0
- package/src/primitives/canvas/icons/edit.svg +1 -0
- package/src/primitives/canvas/icons/ellipsis.svg +1 -0
- package/src/primitives/canvas/icons/external-link.svg +1 -0
- package/src/primitives/canvas/icons/eye.svg +1 -0
- package/src/primitives/canvas/icons/file-text.svg +1 -0
- package/src/primitives/canvas/icons/folder-open.svg +1 -0
- package/src/primitives/canvas/icons/folder.svg +1 -0
- package/src/primitives/canvas/icons/git-branch.svg +1 -0
- package/src/primitives/canvas/icons/git-merge.svg +1 -0
- package/src/primitives/canvas/icons/git-pull-request.svg +1 -0
- package/src/primitives/canvas/icons/info.svg +1 -0
- package/src/primitives/canvas/icons/menu.svg +1 -0
- package/src/primitives/canvas/icons/missing.svg +1 -0
- package/src/primitives/canvas/icons/moon.svg +1 -0
- package/src/primitives/canvas/icons/music.svg +1 -0
- package/src/primitives/canvas/icons/panel-left.svg +1 -0
- package/src/primitives/canvas/icons/panel-right.svg +1 -0
- package/src/primitives/canvas/icons/pause.svg +1 -0
- package/src/primitives/canvas/icons/play.svg +1 -0
- package/src/primitives/canvas/icons/plus.svg +1 -0
- package/src/primitives/canvas/icons/refresh-cw.svg +1 -0
- package/src/primitives/canvas/icons/repeat.svg +1 -0
- package/src/primitives/canvas/icons/save.svg +1 -0
- package/src/primitives/canvas/icons/search.svg +1 -0
- package/src/primitives/canvas/icons/send.svg +1 -0
- package/src/primitives/canvas/icons/settings.svg +1 -0
- package/src/primitives/canvas/icons/shuffle.svg +1 -0
- package/src/primitives/canvas/icons/skip-back.svg +1 -0
- package/src/primitives/canvas/icons/skip-forward.svg +1 -0
- package/src/primitives/canvas/icons/sun.svg +1 -0
- package/src/primitives/canvas/icons/terminal.svg +1 -0
- package/src/primitives/canvas/icons/trash.svg +1 -0
- package/src/primitives/canvas/icons/volume.svg +1 -0
- package/src/primitives/canvas/icons/wrench.svg +1 -0
- package/src/primitives/canvas/icons/x-circle.svg +1 -0
- package/src/primitives/canvas/icons/x.svg +1 -0
- package/src/primitives/canvas/icons.zig +249 -0
- package/src/primitives/canvas/layout_audit.zig +744 -0
- package/src/primitives/canvas/layout_audit_tests.zig +426 -0
- package/src/primitives/canvas/markdown.zig +1031 -0
- package/src/primitives/canvas/markdown_hostile_tests.zig +471 -0
- package/src/primitives/canvas/markdown_tests.zig +538 -0
- package/src/primitives/canvas/plan_key_index.zig +120 -0
- package/src/primitives/canvas/png.zig +355 -0
- package/src/primitives/canvas/reference.zig +1457 -0
- package/src/primitives/canvas/reference_blur.zig +104 -0
- package/src/primitives/canvas/reference_memo.zig +322 -0
- package/src/primitives/canvas/reference_paths.zig +184 -0
- package/src/primitives/canvas/reference_tests.zig +1650 -0
- package/src/primitives/canvas/render.zig +747 -0
- package/src/primitives/canvas/render_effects.zig +255 -0
- package/src/primitives/canvas/render_fingerprints.zig +256 -0
- package/src/primitives/canvas/render_generic_resources.zig +376 -0
- package/src/primitives/canvas/render_images.zig +247 -0
- package/src/primitives/canvas/render_layers.zig +260 -0
- package/src/primitives/canvas/render_paths.zig +347 -0
- package/src/primitives/canvas/render_resources.zig +51 -0
- package/src/primitives/canvas/render_tests.zig +3186 -0
- package/src/primitives/canvas/root.zig +744 -0
- package/src/primitives/canvas/serialization.zig +1528 -0
- package/src/primitives/canvas/svg_icon.zig +636 -0
- package/src/primitives/canvas/svg_icon_tests.zig +312 -0
- package/src/primitives/canvas/test_support.zig +422 -0
- package/src/primitives/canvas/testdata/markdown_document.md +83 -0
- package/src/primitives/canvas/tests.zig +30 -0
- package/src/primitives/canvas/text.zig +82 -0
- package/src/primitives/canvas/text_atlas.zig +408 -0
- package/src/primitives/canvas/text_batch_tests.zig +431 -0
- package/src/primitives/canvas/text_interaction.zig +615 -0
- package/src/primitives/canvas/text_layout.zig +1069 -0
- package/src/primitives/canvas/text_layout_cache.zig +281 -0
- package/src/primitives/canvas/text_layout_hash.zig +113 -0
- package/src/primitives/canvas/text_layout_types.zig +128 -0
- package/src/primitives/canvas/text_measure_cache.zig +279 -0
- package/src/primitives/canvas/text_metrics.zig +309 -0
- package/src/primitives/canvas/text_metrics_tests.zig +262 -0
- package/src/primitives/canvas/text_span_tests.zig +608 -0
- package/src/primitives/canvas/text_spans.zig +1010 -0
- package/src/primitives/canvas/text_tests.zig +1949 -0
- package/src/primitives/canvas/themes/geist.zig +470 -0
- package/src/primitives/canvas/tokens.zig +1522 -0
- package/src/primitives/canvas/ui.zig +2686 -0
- package/src/primitives/canvas/ui_markup.zig +3791 -0
- package/src/primitives/canvas/ui_markup_binary.zig +522 -0
- package/src/primitives/canvas/ui_markup_binary_tests.zig +591 -0
- package/src/primitives/canvas/ui_markup_compiled.zig +2565 -0
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +1669 -0
- package/src/primitives/canvas/ui_markup_contract.zig +1620 -0
- package/src/primitives/canvas/ui_markup_contract_tests.zig +953 -0
- package/src/primitives/canvas/ui_markup_edit.zig +416 -0
- package/src/primitives/canvas/ui_markup_edit_tests.zig +341 -0
- package/src/primitives/canvas/ui_markup_expr.zig +1152 -0
- package/src/primitives/canvas/ui_markup_expr_tests.zig +779 -0
- package/src/primitives/canvas/ui_markup_huge_model_tests.zig +505 -0
- package/src/primitives/canvas/ui_markup_reflect.zig +127 -0
- package/src/primitives/canvas/ui_markup_tests.zig +1545 -0
- package/src/primitives/canvas/ui_markup_view.zig +2352 -0
- package/src/primitives/canvas/ui_markup_view_tests.zig +3709 -0
- package/src/primitives/canvas/ui_provenance.zig +96 -0
- package/src/primitives/canvas/ui_provenance_tests.zig +186 -0
- package/src/primitives/canvas/ui_schema.zig +825 -0
- package/src/primitives/canvas/ui_schema_tests.zig +128 -0
- package/src/primitives/canvas/ui_tests.zig +1432 -0
- package/src/primitives/canvas/vector.zig +919 -0
- package/src/primitives/canvas/vector_tests.zig +547 -0
- package/src/primitives/canvas/virtual_extent_tests.zig +317 -0
- package/src/primitives/canvas/virtual_extents.zig +540 -0
- package/src/primitives/canvas/widget_access.zig +208 -0
- package/src/primitives/canvas/widget_anchored_tests.zig +264 -0
- package/src/primitives/canvas/widget_builtin_tests.zig +3160 -0
- package/src/primitives/canvas/widget_invalidation.zig +748 -0
- package/src/primitives/canvas/widget_layout.zig +2055 -0
- package/src/primitives/canvas/widget_layout_tests.zig +2691 -0
- package/src/primitives/canvas/widget_metrics.zig +228 -0
- package/src/primitives/canvas/widget_render.zig +2534 -0
- package/src/primitives/canvas/widget_render_controls.zig +1563 -0
- package/src/primitives/canvas/widget_render_scroll.zig +136 -0
- package/src/primitives/canvas/widget_render_style.zig +626 -0
- package/src/primitives/canvas/widget_render_surfaces.zig +794 -0
- package/src/primitives/canvas/widget_routing.zig +475 -0
- package/src/primitives/canvas/widget_runtime.zig +307 -0
- package/src/primitives/canvas/widget_runtime_tests.zig +3015 -0
- package/src/primitives/canvas/widget_semantics.zig +480 -0
- package/src/primitives/canvas/widget_semantics_tests.zig +2129 -0
- package/src/primitives/canvas/widget_tests.zig +8 -0
- package/src/primitives/canvas/widget_text_input.zig +351 -0
- package/src/primitives/canvas/widget_text_select.zig +147 -0
- package/src/primitives/canvas/widget_tree.zig +232 -0
- package/src/primitives/canvas/widgets.zig +1319 -0
- package/src/primitives/diagnostics/root.zig +445 -0
- package/src/primitives/geometry/root.zig +889 -0
- package/src/primitives/json/root.zig +272 -0
- package/src/primitives/platform_info/root.zig +450 -0
- package/src/primitives/trace/root.zig +569 -0
- package/src/root.zig +165 -0
- package/src/runtime/api.zig +431 -0
- package/src/runtime/async_bridge.zig +49 -0
- package/src/runtime/automation_commands.zig +686 -0
- package/src/runtime/automation_liveness_tests.zig +140 -0
- package/src/runtime/automation_snapshot.zig +246 -0
- package/src/runtime/automation_widget_dispatch.zig +617 -0
- package/src/runtime/bridge_dispatch_tests.zig +202 -0
- package/src/runtime/bridge_payload.zig +194 -0
- package/src/runtime/bridge_permission_tests.zig +551 -0
- package/src/runtime/bridge_responses.zig +414 -0
- package/src/runtime/builtin_bridge.zig +554 -0
- package/src/runtime/canvas_budget_edge_tests.zig +415 -0
- package/src/runtime/canvas_font_tests.zig +410 -0
- package/src/runtime/canvas_fonts.zig +229 -0
- package/src/runtime/canvas_frame.zig +1734 -0
- package/src/runtime/canvas_frame_animation_tests.zig +609 -0
- package/src/runtime/canvas_frame_cache_tests.zig +333 -0
- package/src/runtime/canvas_frame_helpers.zig +414 -0
- package/src/runtime/canvas_frame_invalidation_tests.zig +544 -0
- package/src/runtime/canvas_frame_packet_tests.zig +1353 -0
- package/src/runtime/canvas_frame_patch_tests.zig +1051 -0
- package/src/runtime/canvas_frame_retained_tests.zig +753 -0
- package/src/runtime/canvas_frame_tests.zig +9 -0
- package/src/runtime/canvas_frame_text_layout_budget_tests.zig +149 -0
- package/src/runtime/canvas_image_tests.zig +362 -0
- package/src/runtime/canvas_images.zig +224 -0
- package/src/runtime/canvas_limits.zig +317 -0
- package/src/runtime/canvas_screenshot_tests.zig +289 -0
- package/src/runtime/canvas_widget_accessibility_tests.zig +1494 -0
- package/src/runtime/canvas_widget_anchored_tests.zig +678 -0
- package/src/runtime/canvas_widget_chart_tests.zig +249 -0
- package/src/runtime/canvas_widget_clipboard_tests.zig +399 -0
- package/src/runtime/canvas_widget_context_menu.zig +318 -0
- package/src/runtime/canvas_widget_context_menu_tests.zig +462 -0
- package/src/runtime/canvas_widget_control_tests.zig +2164 -0
- package/src/runtime/canvas_widget_disclosure_tests.zig +440 -0
- package/src/runtime/canvas_widget_display.zig +677 -0
- package/src/runtime/canvas_widget_event_tests.zig +1779 -0
- package/src/runtime/canvas_widget_events.zig +1098 -0
- package/src/runtime/canvas_widget_floating_tests.zig +695 -0
- package/src/runtime/canvas_widget_layout_tests.zig +26 -0
- package/src/runtime/canvas_widget_runtime.zig +1335 -0
- package/src/runtime/canvas_widget_scroll_driver_tests.zig +582 -0
- package/src/runtime/canvas_widget_scroll_drivers.zig +202 -0
- package/src/runtime/canvas_widget_scroll_tests.zig +1549 -0
- package/src/runtime/canvas_widget_semantics_tests.zig +810 -0
- package/src/runtime/canvas_widget_split_tree_tests.zig +1031 -0
- package/src/runtime/canvas_widget_state.zig +798 -0
- package/src/runtime/canvas_widget_text_tests.zig +2104 -0
- package/src/runtime/canvas_widget_window_drag_tests.zig +284 -0
- package/src/runtime/clock.zig +231 -0
- package/src/runtime/core.zig +927 -0
- package/src/runtime/effects.zig +4197 -0
- package/src/runtime/effects_audio_tests.zig +690 -0
- package/src/runtime/effects_clipboard_tests.zig +317 -0
- package/src/runtime/effects_fetch_tests.zig +1031 -0
- package/src/runtime/effects_file_tests.zig +407 -0
- package/src/runtime/effects_tests.zig +1251 -0
- package/src/runtime/flow.zig +1175 -0
- package/src/runtime/frame_profile.zig +221 -0
- package/src/runtime/gpu_surface_events.zig +639 -0
- package/src/runtime/launch_timing.zig +59 -0
- package/src/runtime/markdown_app_tests.zig +224 -0
- package/src/runtime/native_command_event_tests.zig +431 -0
- package/src/runtime/platform_bridge_tests.zig +8 -0
- package/src/runtime/platform_config_tests.zig +392 -0
- package/src/runtime/root.zig +150 -0
- package/src/runtime/runtime_event_tests.zig +1079 -0
- package/src/runtime/session_journal.zig +1522 -0
- package/src/runtime/session_record.zig +332 -0
- package/src/runtime/session_replay.zig +274 -0
- package/src/runtime/session_state.zig +30 -0
- package/src/runtime/session_tests.zig +399 -0
- package/src/runtime/shell_layout.zig +472 -0
- package/src/runtime/shell_layout_tests.zig +1246 -0
- package/src/runtime/shell_view_tests.zig +604 -0
- package/src/runtime/state.zig +110 -0
- package/src/runtime/system_services.zig +392 -0
- package/src/runtime/test_support.zig +79 -0
- package/src/runtime/tests.zig +30 -0
- package/src/runtime/ui_app.zig +3290 -0
- package/src/runtime/ui_app_huge_model_tests.zig +351 -0
- package/src/runtime/ui_app_provenance.zig +370 -0
- package/src/runtime/ui_app_tests.zig +3254 -0
- package/src/runtime/ui_app_virtual_variable_tests.zig +485 -0
- package/src/runtime/ui_app_window_tests.zig +442 -0
- package/src/runtime/validation.zig +206 -0
- package/src/runtime/view.zig +908 -0
- package/src/runtime/view_canvas.zig +850 -0
- package/src/runtime/view_widget_control.zig +433 -0
- package/src/runtime/view_widget_scroll.zig +360 -0
- package/src/runtime/view_widget_text.zig +275 -0
- package/src/runtime/view_widget_tree.zig +843 -0
- package/src/runtime/webview_view_bridge_tests.zig +664 -0
- package/src/runtime/widget_bridge.zig +231 -0
- package/src/runtime/window_command_bridge_tests.zig +403 -0
- package/src/runtime/window_storage.zig +255 -0
- package/src/runtime/window_view_runtime.zig +727 -0
- package/src/runtime/window_views.zig +334 -0
- package/src/security/root.zig +118 -0
- package/src/tooling/android.zig +1172 -0
- package/src/tooling/assets.zig +128 -0
- package/src/tooling/buildgraph.zig +379 -0
- package/src/tooling/cef.zig +671 -0
- package/src/tooling/codesign.zig +172 -0
- package/src/tooling/components/identity_tests.zig +185 -0
- package/src/tooling/components/stepper.zig +113 -0
- package/src/tooling/components/timeline.native +27 -0
- package/src/tooling/components/timeline_item.zig +131 -0
- package/src/tooling/default_icon.icns +0 -0
- package/src/tooling/default_icon.png +0 -0
- package/src/tooling/dev.zig +172 -0
- package/src/tooling/doctor.zig +349 -0
- package/src/tooling/eject_components.zig +170 -0
- package/src/tooling/embedlib.zig +290 -0
- package/src/tooling/ios.zig +528 -0
- package/src/tooling/manifest.zig +1939 -0
- package/src/tooling/package.zig +2388 -0
- package/src/tooling/process_tree.zig +114 -0
- package/src/tooling/raw_manifest.zig +193 -0
- package/src/tooling/root.zig +22 -0
- package/src/tooling/templates.zig +3191 -0
- package/src/tooling/toolchain.zig +371 -0
- package/src/tooling/verbs.zig +204 -0
- package/src/tooling/web_engine.zig +135 -0
- package/src/tooling/xcodeproj.zig +462 -0
- package/src/window_state/root.zig +507 -0
- package/index.js +0 -2
|
@@ -0,0 +1,2534 @@
|
|
|
1
|
+
const std = @import("std");
|
|
2
|
+
const geometry = @import("geometry");
|
|
3
|
+
const canvas = @import("root.zig");
|
|
4
|
+
const drawing_model = @import("drawing.zig");
|
|
5
|
+
const text_model = @import("text.zig");
|
|
6
|
+
const text_spans_model = @import("text_spans.zig");
|
|
7
|
+
const token_model = @import("tokens.zig");
|
|
8
|
+
const widget_model = @import("widgets.zig");
|
|
9
|
+
const event_model = @import("events.zig");
|
|
10
|
+
const equality_model = @import("equality.zig");
|
|
11
|
+
const widget_tree = @import("widget_tree.zig");
|
|
12
|
+
const widget_layout = @import("widget_layout.zig");
|
|
13
|
+
const widget_access = @import("widget_access.zig");
|
|
14
|
+
const widget_semantics = @import("widget_semantics.zig");
|
|
15
|
+
const widget_metrics = @import("widget_metrics.zig");
|
|
16
|
+
const widget_text_input = @import("widget_text_input.zig");
|
|
17
|
+
const widget_text_select = @import("widget_text_select.zig");
|
|
18
|
+
const widget_render_style = @import("widget_render_style.zig");
|
|
19
|
+
const widget_render_scroll = @import("widget_render_scroll.zig");
|
|
20
|
+
const widget_render_surfaces = @import("widget_render_surfaces.zig");
|
|
21
|
+
const widget_render_controls = @import("widget_render_controls.zig");
|
|
22
|
+
const icon_model = @import("icons.zig");
|
|
23
|
+
const chart_model = @import("chart.zig");
|
|
24
|
+
|
|
25
|
+
const Error = canvas.Error;
|
|
26
|
+
const ObjectId = canvas.ObjectId;
|
|
27
|
+
const Builder = canvas.Builder;
|
|
28
|
+
const Affine = drawing_model.Affine;
|
|
29
|
+
const Color = drawing_model.Color;
|
|
30
|
+
const Radius = drawing_model.Radius;
|
|
31
|
+
const Fill = drawing_model.Fill;
|
|
32
|
+
const Stroke = drawing_model.Stroke;
|
|
33
|
+
const Clip = drawing_model.Clip;
|
|
34
|
+
const Shadow = drawing_model.Shadow;
|
|
35
|
+
const TextWrap = text_model.TextWrap;
|
|
36
|
+
const TextAlign = text_model.TextAlign;
|
|
37
|
+
const TextLayoutOptions = text_model.TextLayoutOptions;
|
|
38
|
+
const DesignTokens = token_model.DesignTokens;
|
|
39
|
+
const ControlVisualTokens = token_model.ControlVisualTokens;
|
|
40
|
+
const WidgetPaintOrder = widget_tree.WidgetPaintOrder;
|
|
41
|
+
const widgetPaintLayer = widget_tree.widgetPaintLayer;
|
|
42
|
+
const nextWidgetPaintChild = widget_tree.nextWidgetPaintChild;
|
|
43
|
+
const widgetLayoutDirectChildCount = widget_tree.widgetLayoutDirectChildCount;
|
|
44
|
+
const nextWidgetLayoutPaintChild = widget_tree.nextWidgetLayoutPaintChild;
|
|
45
|
+
const widgetTransform = widget_tree.widgetTransform;
|
|
46
|
+
const widgetClipsContent = widget_tree.widgetClipsContent;
|
|
47
|
+
const booleanControlSelected = widget_access.booleanControlSelected;
|
|
48
|
+
const widgetPlaceholder = widget_text_input.widgetPlaceholder;
|
|
49
|
+
const widgetTextInputSize = widget_text_input.widgetTextInputSize;
|
|
50
|
+
const widgetTextInputLayoutOptions = widget_text_input.widgetTextInputLayoutOptions;
|
|
51
|
+
const widgetTextInputOrigin = widget_text_input.widgetTextInputOrigin;
|
|
52
|
+
const widgetTextInputClipRect = widget_text_input.widgetTextInputClipRect;
|
|
53
|
+
const widgetTextInputInset = widget_text_input.widgetTextInputInset;
|
|
54
|
+
const widgetButtonTextSize = widget_metrics.widgetButtonTextSize;
|
|
55
|
+
const widgetBodyTextSize = widget_metrics.widgetBodyTextSize;
|
|
56
|
+
const widgetLabelTextSize = widget_metrics.widgetLabelTextSize;
|
|
57
|
+
const widgetLineHeight = widget_metrics.widgetLineHeight;
|
|
58
|
+
const widgetTypographySize = widget_metrics.widgetTypographySize;
|
|
59
|
+
const widgetButtonInset = widget_metrics.widgetButtonInset;
|
|
60
|
+
const widgetControlInset = widget_metrics.widgetControlInset;
|
|
61
|
+
const widgetSizedDensityValue = widget_metrics.widgetSizedDensityValue;
|
|
62
|
+
const widgetSizedTokenValue = widget_metrics.widgetSizedTokenValue;
|
|
63
|
+
const widgetControlHeight = widget_metrics.widgetControlHeight;
|
|
64
|
+
const densityValue = widget_metrics.densityValue;
|
|
65
|
+
const WidgetKind = widget_model.WidgetKind;
|
|
66
|
+
const WidgetState = widget_model.WidgetState;
|
|
67
|
+
const WidgetRenderState = widget_model.WidgetRenderState;
|
|
68
|
+
const WidgetSize = widget_model.WidgetSize;
|
|
69
|
+
const Widget = widget_model.Widget;
|
|
70
|
+
const estimateTextWidth = text_model.estimateTextWidth;
|
|
71
|
+
const measureTextWidthForFont = text_model.measureTextWidthForFont;
|
|
72
|
+
const affinesEqual = equality_model.affinesEqual;
|
|
73
|
+
pub const textSelectionFillColor = widget_render_style.textSelectionFillColor;
|
|
74
|
+
pub const textSelectionTextColor = widget_render_style.textSelectionTextColor;
|
|
75
|
+
pub const textEditingInkColor = widget_render_style.textEditingInkColor;
|
|
76
|
+
pub const staticTextSelectionFillColor = widget_render_style.staticTextSelectionFillColor;
|
|
77
|
+
pub const colorWithAlpha = widget_render_style.colorWithAlpha;
|
|
78
|
+
const colorFill = widget_render_style.colorFill;
|
|
79
|
+
const widgetBackgroundFill = widget_render_style.widgetBackgroundFill;
|
|
80
|
+
const widgetAccentFill = widget_render_style.widgetAccentFill;
|
|
81
|
+
const widgetBorderFill = widget_render_style.widgetBorderFill;
|
|
82
|
+
const widgetBackgroundColor = widget_render_style.widgetBackgroundColor;
|
|
83
|
+
const widgetAccentColor = widget_render_style.widgetAccentColor;
|
|
84
|
+
const widgetBorderColor = widget_render_style.widgetBorderColor;
|
|
85
|
+
const widgetForegroundColor = widget_render_style.widgetForegroundColor;
|
|
86
|
+
const widgetAccentForegroundColor = widget_render_style.widgetAccentForegroundColor;
|
|
87
|
+
const widgetRadius = widget_render_style.widgetRadius;
|
|
88
|
+
pub const controlRadius = widget_render_style.controlRadius;
|
|
89
|
+
pub const controlStrokeWidth = widget_render_style.controlStrokeWidth;
|
|
90
|
+
pub const selectControlVisualTokens = widget_render_style.selectControlVisualTokens;
|
|
91
|
+
pub const textInputControlVisualTokens = widget_render_style.textInputControlVisualTokens;
|
|
92
|
+
const alertControlVisualTokens = widget_render_style.alertControlVisualTokens;
|
|
93
|
+
const cardControlVisualTokens = widget_render_style.cardControlVisualTokens;
|
|
94
|
+
const dialogControlVisualTokens = widget_render_style.dialogControlVisualTokens;
|
|
95
|
+
const drawerControlVisualTokens = widget_render_style.drawerControlVisualTokens;
|
|
96
|
+
const sheetControlVisualTokens = widget_render_style.sheetControlVisualTokens;
|
|
97
|
+
pub const listItemControlVisualTokens = widget_render_style.listItemControlVisualTokens;
|
|
98
|
+
pub const selectionControlVisualTokens = widget_render_style.selectionControlVisualTokens;
|
|
99
|
+
pub const surfaceControlVisualTokens = widget_render_style.surfaceControlVisualTokens;
|
|
100
|
+
pub const componentControlVisualTokens = widget_render_style.componentControlVisualTokens;
|
|
101
|
+
const componentPillRadius = widget_render_style.componentPillRadius;
|
|
102
|
+
const badgeBackgroundColor = widget_render_style.badgeBackgroundColor;
|
|
103
|
+
const badgeBorderColor = widget_render_style.badgeBorderColor;
|
|
104
|
+
const badgeTextColor = widget_render_style.badgeTextColor;
|
|
105
|
+
const badgeStrokeWidth = widget_render_style.badgeStrokeWidth;
|
|
106
|
+
pub const buttonStrokeWidth = widget_render_style.buttonStrokeWidth;
|
|
107
|
+
pub const transparentColor = widget_render_style.transparentColor;
|
|
108
|
+
pub const checkboxWidgetBoxRect = widget_render_controls.checkboxWidgetBoxRect;
|
|
109
|
+
pub const radioWidgetCircleRect = widget_render_controls.radioWidgetCircleRect;
|
|
110
|
+
pub const toggleWidgetTrackRect = widget_render_controls.toggleWidgetTrackRect;
|
|
111
|
+
pub const sliderWidgetKnobRect = widget_render_controls.sliderWidgetKnobRect;
|
|
112
|
+
|
|
113
|
+
const max_widget_depth: usize = 32;
|
|
114
|
+
|
|
115
|
+
/// Frame-lifetime scratch for widget-built path elements: `.chart`
|
|
116
|
+
/// widgets build their line/band `PathElement`s here at emit time, and
|
|
117
|
+
/// `.spinner` widgets their arc segment (unlike icons, whose elements
|
|
118
|
+
/// are comptime-static); emitted commands slice into it. The event loop
|
|
119
|
+
/// is single-threaded and the runtime copies the display list into
|
|
120
|
+
/// per-view storage within the same emit call stack, so one threadlocal
|
|
121
|
+
/// buffer per frame is sound — reset at each emit entry point. Sized to
|
|
122
|
+
/// mirror the runtime's per-view path-element budget
|
|
123
|
+
/// (`canvas_limits.max_canvas_path_elements_per_view`; a lockstep test
|
|
124
|
+
/// keeps them equal), so overflow here fails exactly where the per-view
|
|
125
|
+
/// copy would have refused anyway — loudly, by budget name.
|
|
126
|
+
threadlocal var frame_path_elements: [chart_model.max_chart_path_elements_per_frame]drawing_model.PathElement = undefined;
|
|
127
|
+
threadlocal var frame_path_len: usize = 0;
|
|
128
|
+
|
|
129
|
+
/// Frame-lifetime scratch for formatted chart label text (y tick values
|
|
130
|
+
/// and hover-detail rows): `drawText` commands slice into it under the
|
|
131
|
+
/// same single-threaded copy-before-return contract as the path
|
|
132
|
+
/// elements above. Overflow fails loudly by budget name.
|
|
133
|
+
threadlocal var frame_label_bytes: [chart_model.max_chart_label_bytes_per_frame]u8 = undefined;
|
|
134
|
+
threadlocal var frame_label_len: usize = 0;
|
|
135
|
+
|
|
136
|
+
fn resetFramePathScratch() void {
|
|
137
|
+
frame_path_len = 0;
|
|
138
|
+
frame_label_len = 0;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/// Persist a formatted label into the frame scratch so the emitted
|
|
142
|
+
/// command outlives the local formatting buffer.
|
|
143
|
+
fn allocFrameLabelBytes(text: []const u8) Error![]const u8 {
|
|
144
|
+
if (frame_label_len + text.len > frame_label_bytes.len) return error.ChartLabelBytesFull;
|
|
145
|
+
const start = frame_label_len;
|
|
146
|
+
frame_label_len += text.len;
|
|
147
|
+
@memcpy(frame_label_bytes[start..frame_label_len], text);
|
|
148
|
+
return frame_label_bytes[start..frame_label_len];
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/// Frame-lifetime scratch (same single-threaded emit contract as the
|
|
152
|
+
/// path-element scratch above) holding the root bounds of the tree being
|
|
153
|
+
/// emitted: the rect a modal surface's scrim covers. Chrome emission
|
|
154
|
+
/// happens deep in the recursion where no ancestor frame is in scope, so
|
|
155
|
+
/// the entry points record it here.
|
|
156
|
+
threadlocal var scrim_viewport: ?geometry.RectF = null;
|
|
157
|
+
|
|
158
|
+
fn allocFramePathElements(count: usize) Error![]drawing_model.PathElement {
|
|
159
|
+
if (frame_path_len + count > frame_path_elements.len) return error.ChartPathElementListFull;
|
|
160
|
+
const start = frame_path_len;
|
|
161
|
+
frame_path_len += count;
|
|
162
|
+
return frame_path_elements[start .. start + count];
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
pub fn emitWidgetTree(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!void {
|
|
166
|
+
resetFramePathScratch();
|
|
167
|
+
scrim_viewport = widget.frame.normalized();
|
|
168
|
+
try emitWidgetDepth(builder, widget, tokens, 0);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
pub fn emitWidgetLayout(builder: *Builder, layout: anytype, tokens: DesignTokens) Error!void {
|
|
172
|
+
return emitWidgetLayoutWithState(builder, layout, tokens, .{});
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
pub fn emitWidgetLayoutWithState(builder: *Builder, layout: anytype, tokens: DesignTokens, state: WidgetRenderState) Error!void {
|
|
176
|
+
resetFramePathScratch();
|
|
177
|
+
scrim_viewport = widgetLayoutRootBounds(layout);
|
|
178
|
+
try emitWidgetLayoutChildren(builder, layout, null, tokens, state);
|
|
179
|
+
try emitWidgetLayoutAnchored(builder, layout, tokens, state);
|
|
180
|
+
try emitWidgetLayoutChartHoverDetails(builder, layout, tokens, state);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/// The union of the layout's root-node frames: the whole laid-out
|
|
184
|
+
/// surface, which is what a modal scrim covers.
|
|
185
|
+
pub fn widgetLayoutRootBounds(layout: anytype) ?geometry.RectF {
|
|
186
|
+
var bounds: ?geometry.RectF = null;
|
|
187
|
+
for (layout.nodes) |node| {
|
|
188
|
+
if (node.parent_index != null) continue;
|
|
189
|
+
const frame = node.frame.normalized();
|
|
190
|
+
bounds = if (bounds) |current| geometry.RectF.unionWith(current, frame) else frame;
|
|
191
|
+
}
|
|
192
|
+
return bounds;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/// The late z-pass for anchored floating surfaces: they are skipped by
|
|
196
|
+
/// the in-tree walk above and emitted here LAST, at the top level, so no
|
|
197
|
+
/// ancestor scroll/clip region crops them (window-clipped, not
|
|
198
|
+
/// parent-clipped) and they paint above everything in the tree. Node
|
|
199
|
+
/// order is tree order, so a nested anchored surface (submenu) paints
|
|
200
|
+
/// above the surface it hangs from. Ancestor hiding still applies.
|
|
201
|
+
fn emitWidgetLayoutAnchored(builder: *Builder, layout: anytype, tokens: DesignTokens, state: WidgetRenderState) Error!void {
|
|
202
|
+
for (layout.nodes, 0..) |node, index| {
|
|
203
|
+
if (!widget_tree.widgetIsAnchored(node.widget)) continue;
|
|
204
|
+
if (widget_tree.isWidgetHiddenInAncestors(layout, index)) continue;
|
|
205
|
+
// A floating surface anchored inside a concealed disclosure
|
|
206
|
+
// subtree stays down with its anchor — concealed content is
|
|
207
|
+
// laid out but must not paint window-level chrome.
|
|
208
|
+
if (widget_tree.isWidgetConcealedByDisclosure(layout, index)) continue;
|
|
209
|
+
try emitWidgetLayoutNode(builder, layout, index, tokens, state, .none);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
fn emitWidgetDepth(builder: *Builder, widget: Widget, tokens: DesignTokens, depth: usize) Error!void {
|
|
214
|
+
if (depth >= max_widget_depth) return error.WidgetDepthExceeded;
|
|
215
|
+
if (widget.semantics.hidden) return;
|
|
216
|
+
|
|
217
|
+
const opacity = widgetOpacity(widget);
|
|
218
|
+
if (opacity <= 0) return;
|
|
219
|
+
const wrap_opacity = opacity < 1;
|
|
220
|
+
const transform = widgetTransform(widget);
|
|
221
|
+
const wrap_transform = !affinesEqual(transform, Affine.identity());
|
|
222
|
+
const inverse_transform = if (wrap_transform) transform.inverse() orelse return error.InvalidTransform else Affine.identity();
|
|
223
|
+
if (wrap_opacity) try builder.pushOpacity(opacity);
|
|
224
|
+
if (wrap_transform) try builder.transform(transform);
|
|
225
|
+
try emitWidgetDepthContent(builder, widget, tokens, depth);
|
|
226
|
+
if (wrap_transform) try builder.transform(inverse_transform);
|
|
227
|
+
if (wrap_opacity) try builder.popOpacity();
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
fn emitWidgetDepthContent(builder: *Builder, widget: Widget, tokens: DesignTokens, depth: usize) Error!void {
|
|
231
|
+
const paint_widget = widgetWithFrame(widget, pixelSnapGeometryRect(tokens, widget.frame));
|
|
232
|
+
try emitWidgetBackdropBlur(builder, paint_widget, tokens);
|
|
233
|
+
switch (paint_widget.kind) {
|
|
234
|
+
.stack, .row, .column, .grid, .list, .breadcrumb, .pagination, .radio_group, .toggle_group, .split, .tree => try emitWidgetClippedChildren(builder, paint_widget, tokens, depth),
|
|
235
|
+
.button_group => try emitButtonGroupWidget(builder, paint_widget, tokens, depth),
|
|
236
|
+
.table, .data_grid => {
|
|
237
|
+
try emitWidgetClippedChildren(builder, paint_widget, tokens, depth);
|
|
238
|
+
try emitTableRowSeparators(builder, paint_widget.children, tokens);
|
|
239
|
+
},
|
|
240
|
+
.data_row => {
|
|
241
|
+
try emitDataRowWidgetWash(builder, paint_widget, tokens);
|
|
242
|
+
try emitWidgetClippedChildren(builder, paint_widget, tokens, depth);
|
|
243
|
+
},
|
|
244
|
+
.tabs => try emitTabsWidget(builder, paint_widget, tokens, depth),
|
|
245
|
+
.scroll_view => try emitScrollViewWidget(builder, paint_widget, tokens, depth),
|
|
246
|
+
.alert => try emitAlertWidget(builder, paint_widget, tokens, depth),
|
|
247
|
+
.card => try emitCardWidget(builder, paint_widget, tokens, depth),
|
|
248
|
+
.dialog => try emitDialogSurfaceWidget(builder, paint_widget, tokens, depth),
|
|
249
|
+
.drawer => try emitDrawerSurfaceWidget(builder, paint_widget, tokens, depth),
|
|
250
|
+
.sheet => try emitSheetSurfaceWidget(builder, paint_widget, tokens, depth),
|
|
251
|
+
.accordion => try emitAccordionWidget(builder, paint_widget, tokens, depth),
|
|
252
|
+
.bubble => try emitBubbleWidget(builder, paint_widget, tokens, depth),
|
|
253
|
+
.resizable, .panel => try emitPanelWidget(builder, paint_widget, tokens, depth),
|
|
254
|
+
.popover => try emitPopoverWidget(builder, paint_widget, tokens, depth),
|
|
255
|
+
.menu_surface, .dropdown_menu => try emitMenuSurfaceWidget(builder, paint_widget, tokens, depth),
|
|
256
|
+
.text => try emitTextWidget(builder, paint_widget, tokens),
|
|
257
|
+
.icon => try emitIconWidget(builder, paint_widget, tokens),
|
|
258
|
+
.image => try emitImageWidget(builder, paint_widget),
|
|
259
|
+
.avatar => try emitAvatarWidget(builder, paint_widget, tokens),
|
|
260
|
+
.badge => try emitBadgeWidget(builder, paint_widget, tokens),
|
|
261
|
+
.button, .toggle_button, .toggle => try widget_render_controls.emitButtonWidget(builder, paint_widget, tokens),
|
|
262
|
+
.icon_button => try widget_render_controls.emitIconButtonWidget(builder, paint_widget, tokens),
|
|
263
|
+
.select => try widget_render_controls.emitSelectWidget(builder, paint_widget, tokens),
|
|
264
|
+
.input, .text_field, .textarea => try widget_render_controls.emitTextFieldWidget(builder, paint_widget, tokens),
|
|
265
|
+
.search_field, .combobox => try widget_render_controls.emitSearchFieldWidget(builder, paint_widget, tokens),
|
|
266
|
+
.tooltip => try widget_render_controls.emitTooltipWidget(builder, paint_widget, tokens),
|
|
267
|
+
.menu_item => try widget_render_controls.emitMenuItemWidget(builder, paint_widget, tokens),
|
|
268
|
+
.list_item => {
|
|
269
|
+
try widget_render_controls.emitListItemWidget(builder, paint_widget, tokens);
|
|
270
|
+
// Custom row content (the list-row composite): children flow
|
|
271
|
+
// inside the flat wash chrome.
|
|
272
|
+
try emitWidgetClippedChildren(builder, paint_widget, tokens, depth);
|
|
273
|
+
},
|
|
274
|
+
.data_cell => try emitDataCellContent(builder, paint_widget, tokens),
|
|
275
|
+
.status_bar => try emitStatusBarWidget(builder, paint_widget, tokens),
|
|
276
|
+
.segmented_control => try widget_render_controls.emitSegmentedControlWidget(builder, paint_widget, tokens),
|
|
277
|
+
.checkbox => try widget_render_controls.emitCheckboxWidget(builder, paint_widget, tokens),
|
|
278
|
+
.radio => try widget_render_controls.emitRadioWidget(builder, paint_widget, tokens),
|
|
279
|
+
.switch_control => try widget_render_controls.emitToggleWidget(builder, paint_widget, tokens),
|
|
280
|
+
.slider => try widget_render_controls.emitSliderWidget(builder, paint_widget, tokens),
|
|
281
|
+
.progress => try widget_render_controls.emitProgressWidget(builder, paint_widget, tokens),
|
|
282
|
+
.separator => try emitSeparatorWidget(builder, paint_widget, tokens),
|
|
283
|
+
.split_divider => try emitSplitDividerWidget(builder, paint_widget, tokens),
|
|
284
|
+
.skeleton => try emitSkeletonWidget(builder, paint_widget, tokens),
|
|
285
|
+
.spinner => try emitSpinnerWidget(builder, paint_widget, tokens),
|
|
286
|
+
.chart => try emitChartWidget(builder, paint_widget, tokens),
|
|
287
|
+
.input_group => {
|
|
288
|
+
// Focus-within: the GROUP wears the focus ring for its
|
|
289
|
+
// focused descendant (the entry's own ring is dissolved), so
|
|
290
|
+
// the whole group reads as one field.
|
|
291
|
+
var group = paint_widget;
|
|
292
|
+
if (!group.state.focused) group.state.focused = widgetSubtreeHasFocusedState(paint_widget);
|
|
293
|
+
try widget_render_controls.emitInputGroupWidget(builder, group, tokens);
|
|
294
|
+
try emitWidgetClippedChildren(builder, paint_widget, tokens, depth);
|
|
295
|
+
},
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/// Whether any descendant carries the focused state (the tree path's
|
|
300
|
+
/// focus-within source: state is baked into the widgets themselves).
|
|
301
|
+
fn widgetSubtreeHasFocusedState(widget: Widget) bool {
|
|
302
|
+
for (widget.children) |child| {
|
|
303
|
+
if (child.state.focused) return true;
|
|
304
|
+
if (widgetSubtreeHasFocusedState(child)) return true;
|
|
305
|
+
}
|
|
306
|
+
return false;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/// Whether any descendant NODE carries baked focused state (the layout
|
|
310
|
+
/// path's focus-within source for static trees — docs scenes, tests —
|
|
311
|
+
/// resolved through the layout's parent links, which survive layout
|
|
312
|
+
/// retention where `widget.children` slices may not).
|
|
313
|
+
fn layoutSubtreeHasBakedFocus(layout: anytype, node_index: usize) bool {
|
|
314
|
+
for (layout.nodes, 0..) |node, index| {
|
|
315
|
+
if (index == node_index or !node.widget.state.focused) continue;
|
|
316
|
+
var current = node.parent_index;
|
|
317
|
+
while (current) |current_index| {
|
|
318
|
+
if (current_index == node_index) return true;
|
|
319
|
+
current = layout.nodes[current_index].parent_index;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
return false;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/// Whether the focus-visible widget sits inside `node_index`'s subtree
|
|
326
|
+
/// (the layout path's focus-within source: runtime focus is an id in
|
|
327
|
+
/// `WidgetRenderState`, resolved against the layout's parent links).
|
|
328
|
+
fn layoutSubtreeHasFocusVisible(layout: anytype, node_index: usize, state: WidgetRenderState) bool {
|
|
329
|
+
const focus_id = state.focus_visible_id orelse return false;
|
|
330
|
+
if (focus_id == 0) return false;
|
|
331
|
+
for (layout.nodes, 0..) |node, index| {
|
|
332
|
+
if (node.widget.id != focus_id) continue;
|
|
333
|
+
var current: ?usize = index;
|
|
334
|
+
while (current) |current_index| {
|
|
335
|
+
if (current_index == node_index) return true;
|
|
336
|
+
current = layout.nodes[current_index].parent_index;
|
|
337
|
+
}
|
|
338
|
+
return false;
|
|
339
|
+
}
|
|
340
|
+
return false;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/// A table cell draws its chrome (fill, border, focus ring) and then its
|
|
344
|
+
/// text: span-carrying cells (markdown tables) draw inline-styled runs
|
|
345
|
+
/// through the span paragraph emitter, classic cells keep the single-line
|
|
346
|
+
/// path byte-identical.
|
|
347
|
+
fn emitDataCellContent(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!void {
|
|
348
|
+
if (widget.spans.len == 0) return widget_render_controls.emitDataCellWidget(builder, widget, tokens);
|
|
349
|
+
_ = try widget_render_controls.emitDataCellWidgetChrome(builder, widget, tokens);
|
|
350
|
+
try emitTextSpansWidget(builder, widget, tokens);
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
fn emitWidgetChildren(builder: *Builder, children: []const Widget, tokens: DesignTokens, depth: usize) Error!void {
|
|
354
|
+
var emitted: usize = 0;
|
|
355
|
+
var previous: ?WidgetPaintOrder = null;
|
|
356
|
+
while (emitted < children.len) : (emitted += 1) {
|
|
357
|
+
const child_index = nextWidgetPaintChild(children, tokens, previous) orelse return;
|
|
358
|
+
const child = children[child_index];
|
|
359
|
+
try emitWidgetDepth(builder, child, tokens, depth + 1);
|
|
360
|
+
previous = .{ .layer = widgetPaintLayer(child, tokens), .index = child_index };
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/// Whether a button group stamps member positions into the render walk.
|
|
365
|
+
/// Under the house `.segmented` register only a gap-0 (the default)
|
|
366
|
+
/// group stamps — attached segments collapse corners and seams, while
|
|
367
|
+
/// an author who spaces the group out has asked for separate buttons,
|
|
368
|
+
/// and rounding off their inner corners then would be dishonest chrome.
|
|
369
|
+
/// Under the `.detached` register every member stamps regardless of
|
|
370
|
+
/// gap: the stamp switches the member to the group's chip treatment
|
|
371
|
+
/// (full corners, group control table), so spacing carries no opt-out
|
|
372
|
+
/// meaning there. The button emitters key the corner/seam collapse on
|
|
373
|
+
/// the register, never on the stamp alone.
|
|
374
|
+
fn buttonGroupStampsSegments(widget: Widget, tokens: DesignTokens) bool {
|
|
375
|
+
return switch (tokens.controls.button_group_style) {
|
|
376
|
+
.segmented => widget.layout.gap <= 0,
|
|
377
|
+
.detached => true,
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/// A group child's position among the group's VISIBLE children, in
|
|
382
|
+
/// layout (slice) order — paint order may reorder emission by layer,
|
|
383
|
+
/// but which corner a segment keeps is a where-does-it-sit question,
|
|
384
|
+
/// never a when-does-it-paint question. Hidden children vacate their
|
|
385
|
+
/// position so the bar re-caps itself around them.
|
|
386
|
+
fn buttonGroupChildSegment(children: []const Widget, child_index: usize) widget_model.WidgetGroupSegment {
|
|
387
|
+
var visible_total: usize = 0;
|
|
388
|
+
var ordinal: usize = 0;
|
|
389
|
+
for (children, 0..) |child, index| {
|
|
390
|
+
if (child.semantics.hidden) continue;
|
|
391
|
+
if (index == child_index) ordinal = visible_total;
|
|
392
|
+
visible_total += 1;
|
|
393
|
+
}
|
|
394
|
+
return buttonGroupSegmentAt(ordinal, visible_total);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
fn buttonGroupSegmentAt(ordinal: usize, visible_total: usize) widget_model.WidgetGroupSegment {
|
|
398
|
+
// A lone segment is just a button: full corners, full border.
|
|
399
|
+
if (visible_total <= 1) return .none;
|
|
400
|
+
if (ordinal == 0) return .first;
|
|
401
|
+
if (ordinal == visible_total - 1) return .last;
|
|
402
|
+
return .middle;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
/// The tree walk's button-group emission: `emitWidgetClippedChildren`
|
|
406
|
+
/// with the group segment stamp applied to each child copy on the way
|
|
407
|
+
/// down, so the button emitters can shape corners and collapse the
|
|
408
|
+
/// shared seams (segmented register) or swap to the group chip
|
|
409
|
+
/// treatment (detached register). The layout walk applies the same
|
|
410
|
+
/// stamp in `emitWidgetLayoutChildren` — the two walks must agree or a
|
|
411
|
+
/// docs scene and a live app would render different bars.
|
|
412
|
+
fn emitButtonGroupWidget(builder: *Builder, widget: Widget, tokens: DesignTokens, depth: usize) Error!void {
|
|
413
|
+
if (!buttonGroupStampsSegments(widget, tokens)) return emitWidgetClippedChildren(builder, widget, tokens, depth);
|
|
414
|
+
if (widget.layout.clip_content) try builder.pushClip(widgetContentClip(widget, tokens));
|
|
415
|
+
var emitted: usize = 0;
|
|
416
|
+
var previous: ?WidgetPaintOrder = null;
|
|
417
|
+
while (emitted < widget.children.len) : (emitted += 1) {
|
|
418
|
+
const child_index = nextWidgetPaintChild(widget.children, tokens, previous) orelse break;
|
|
419
|
+
var child = widget.children[child_index];
|
|
420
|
+
child.group_segment = buttonGroupChildSegment(widget.children, child_index);
|
|
421
|
+
try emitWidgetDepth(builder, child, tokens, depth + 1);
|
|
422
|
+
previous = .{ .layer = widgetPaintLayer(child, tokens), .index = child_index };
|
|
423
|
+
}
|
|
424
|
+
if (widget.layout.clip_content) try builder.popClip();
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
fn emitWidgetLayoutChildren(
|
|
428
|
+
builder: *Builder,
|
|
429
|
+
layout: anytype,
|
|
430
|
+
parent_index: ?usize,
|
|
431
|
+
tokens: DesignTokens,
|
|
432
|
+
state: WidgetRenderState,
|
|
433
|
+
) Error!void {
|
|
434
|
+
const child_count = widgetLayoutDirectChildCount(layout, parent_index);
|
|
435
|
+
// The layout walk's flush button-group stamp (the tree walk's twin
|
|
436
|
+
// lives in `emitButtonGroupWidget`): children of a gap-0 group get
|
|
437
|
+
// their segment position on the way down.
|
|
438
|
+
const group_index: ?usize = if (parent_index) |index| blk: {
|
|
439
|
+
const parent = layout.nodes[index].widget;
|
|
440
|
+
break :blk if (parent.kind == .button_group and buttonGroupStampsSegments(parent, tokens)) index else null;
|
|
441
|
+
} else null;
|
|
442
|
+
var emitted: usize = 0;
|
|
443
|
+
var previous: ?WidgetPaintOrder = null;
|
|
444
|
+
while (emitted < child_count) : (emitted += 1) {
|
|
445
|
+
const child_index = nextWidgetLayoutPaintChild(layout, parent_index, tokens, previous) orelse return;
|
|
446
|
+
// Anchored floating children paint in the late z-pass
|
|
447
|
+
// (`emitWidgetLayoutAnchored`), never in tree position.
|
|
448
|
+
if (!widget_tree.widgetIsAnchored(layout.nodes[child_index].widget)) {
|
|
449
|
+
const segment = if (group_index) |index|
|
|
450
|
+
layoutButtonGroupSegment(layout, index, child_index)
|
|
451
|
+
else
|
|
452
|
+
widget_model.WidgetGroupSegment.none;
|
|
453
|
+
try emitWidgetLayoutNode(builder, layout, child_index, tokens, state, segment);
|
|
454
|
+
}
|
|
455
|
+
previous = .{ .layer = widgetPaintLayer(layout.nodes[child_index].widget, tokens), .index = child_index };
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
/// A layout node's position among its button group's visible direct
|
|
460
|
+
/// children, in node (layout) order — the layout-walk twin of
|
|
461
|
+
/// `buttonGroupChildSegment`.
|
|
462
|
+
fn layoutButtonGroupSegment(layout: anytype, group_index: usize, child_index: usize) widget_model.WidgetGroupSegment {
|
|
463
|
+
var visible_total: usize = 0;
|
|
464
|
+
var ordinal: usize = 0;
|
|
465
|
+
for (layout.nodes, 0..) |node, index| {
|
|
466
|
+
if (node.parent_index != group_index) continue;
|
|
467
|
+
if (node.widget.semantics.hidden) continue;
|
|
468
|
+
if (index == child_index) ordinal = visible_total;
|
|
469
|
+
visible_total += 1;
|
|
470
|
+
}
|
|
471
|
+
return buttonGroupSegmentAt(ordinal, visible_total);
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
fn emitWidgetLayoutNode(
|
|
475
|
+
builder: *Builder,
|
|
476
|
+
layout: anytype,
|
|
477
|
+
node_index: usize,
|
|
478
|
+
tokens: DesignTokens,
|
|
479
|
+
state: WidgetRenderState,
|
|
480
|
+
segment: widget_model.WidgetGroupSegment,
|
|
481
|
+
) Error!void {
|
|
482
|
+
const node = layout.nodes[node_index];
|
|
483
|
+
if (node.widget.semantics.hidden) return;
|
|
484
|
+
|
|
485
|
+
var widget = widgetWithRenderState(widgetWithFrame(node.widget, node.frame), state);
|
|
486
|
+
widget.group_segment = segment;
|
|
487
|
+
const opacity = widgetOpacity(widget);
|
|
488
|
+
if (opacity <= 0) return;
|
|
489
|
+
const wrap_opacity = opacity < 1;
|
|
490
|
+
const transform = widgetTransform(widget);
|
|
491
|
+
const wrap_transform = !affinesEqual(transform, Affine.identity());
|
|
492
|
+
const inverse_transform = if (wrap_transform) transform.inverse() orelse return error.InvalidTransform else Affine.identity();
|
|
493
|
+
if (wrap_opacity) try builder.pushOpacity(opacity);
|
|
494
|
+
if (wrap_transform) try builder.transform(transform);
|
|
495
|
+
try emitWidgetLayoutNodeContent(builder, layout, node_index, tokens, state, widget);
|
|
496
|
+
if (wrap_transform) try builder.transform(inverse_transform);
|
|
497
|
+
if (wrap_opacity) try builder.popOpacity();
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
fn emitWidgetLayoutNodeContent(
|
|
501
|
+
builder: *Builder,
|
|
502
|
+
layout: anytype,
|
|
503
|
+
node_index: usize,
|
|
504
|
+
tokens: DesignTokens,
|
|
505
|
+
state: WidgetRenderState,
|
|
506
|
+
widget: Widget,
|
|
507
|
+
) Error!void {
|
|
508
|
+
const paint_widget = widgetWithFrame(widget, pixelSnapGeometryRect(tokens, widget.frame));
|
|
509
|
+
try emitWidgetBackdropBlur(builder, paint_widget, tokens);
|
|
510
|
+
switch (paint_widget.kind) {
|
|
511
|
+
.stack, .row, .column, .breadcrumb, .button_group, .pagination, .radio_group, .toggle_group, .split, .tree => {},
|
|
512
|
+
.data_row => try emitDataRowWidgetWash(builder, paint_widget, tokens),
|
|
513
|
+
.tabs => try widget_render_surfaces.emitTabsListWidgetChrome(builder, paint_widget, tokens),
|
|
514
|
+
.table, .data_grid => {
|
|
515
|
+
if (paint_widget.layout.virtualized) {
|
|
516
|
+
try emitWidgetLayoutScrollableChildren(builder, layout, node_index, tokens, state, paint_widget);
|
|
517
|
+
try emitTableRowSeparatorsLayout(builder, layout, node_index, tokens, paint_widget, true);
|
|
518
|
+
return;
|
|
519
|
+
}
|
|
520
|
+
try emitWidgetLayoutClippedChildren(builder, layout, node_index, tokens, state, paint_widget);
|
|
521
|
+
try emitTableRowSeparatorsLayout(builder, layout, node_index, tokens, paint_widget, false);
|
|
522
|
+
return;
|
|
523
|
+
},
|
|
524
|
+
.grid, .list => if (paint_widget.layout.virtualized) {
|
|
525
|
+
try emitWidgetLayoutScrollableChildren(builder, layout, node_index, tokens, state, paint_widget);
|
|
526
|
+
return;
|
|
527
|
+
},
|
|
528
|
+
.scroll_view => {
|
|
529
|
+
try builder.pushClip(.{ .id = widgetPartId(paint_widget.id, 1), .rect = paint_widget.frame });
|
|
530
|
+
try emitWidgetLayoutChildren(builder, layout, node_index, tokens, state);
|
|
531
|
+
try builder.popClip();
|
|
532
|
+
// Native scroll drivers own the (OS overlay) scrollbar.
|
|
533
|
+
if (!paint_widget.native_scroll) {
|
|
534
|
+
try widget_render_scroll.emitScrollViewScrollbar(builder, paint_widget.frame, widgetScrollSemantics(layout, node_index).metrics, tokens, paint_widget.id);
|
|
535
|
+
}
|
|
536
|
+
return;
|
|
537
|
+
},
|
|
538
|
+
.alert => try widget_render_surfaces.emitAlertWidgetChrome(builder, paint_widget, tokens),
|
|
539
|
+
.card => try widget_render_surfaces.emitCardWidgetChrome(builder, paint_widget, tokens),
|
|
540
|
+
.dialog => {
|
|
541
|
+
try emitModalSurfaceScrim(builder, paint_widget, tokens);
|
|
542
|
+
try widget_render_surfaces.emitDialogSurfaceWidgetChrome(builder, paint_widget, tokens);
|
|
543
|
+
},
|
|
544
|
+
.drawer => {
|
|
545
|
+
try emitModalSurfaceScrim(builder, paint_widget, tokens);
|
|
546
|
+
try widget_render_surfaces.emitDrawerSurfaceWidgetChrome(builder, paint_widget, tokens);
|
|
547
|
+
},
|
|
548
|
+
.sheet => {
|
|
549
|
+
try emitModalSurfaceScrim(builder, paint_widget, tokens);
|
|
550
|
+
try widget_render_surfaces.emitSheetSurfaceWidgetChrome(builder, paint_widget, tokens);
|
|
551
|
+
},
|
|
552
|
+
.accordion => {
|
|
553
|
+
try widget_render_surfaces.emitAccordionWidgetChrome(builder, paint_widget, tokens);
|
|
554
|
+
// Disclosure emission is tri-state. Settled closed: the
|
|
555
|
+
// content (laid out at full size below the header) emits
|
|
556
|
+
// NOTHING — byte-identical to the pre-disclosure display
|
|
557
|
+
// list. Mid-reveal (or mid-conceal): the content paints at
|
|
558
|
+
// its full-size geometry, clipped to the item's animated
|
|
559
|
+
// frame, so text reveals without ever re-wrapping. Settled
|
|
560
|
+
// open: the shared unclipped children pass below, exactly
|
|
561
|
+
// as before.
|
|
562
|
+
switch (accordionLayoutDisclosure(layout, node_index, paint_widget, state)) {
|
|
563
|
+
.closed => return,
|
|
564
|
+
.revealing => {
|
|
565
|
+
try builder.pushClip(.{ .id = widgetPartId(paint_widget.id, 9), .rect = paint_widget.frame });
|
|
566
|
+
try emitWidgetLayoutChildren(builder, layout, node_index, tokens, state);
|
|
567
|
+
try builder.popClip();
|
|
568
|
+
return;
|
|
569
|
+
},
|
|
570
|
+
.open => {},
|
|
571
|
+
}
|
|
572
|
+
},
|
|
573
|
+
.bubble => {
|
|
574
|
+
try widget_render_surfaces.emitBubbleWidgetChrome(builder, paint_widget, tokens);
|
|
575
|
+
// The bubble's variant re-inks its content: children render
|
|
576
|
+
// against the cascaded token palette (knockout body ink on a
|
|
577
|
+
// filled bubble) instead of the page's, so this subtree
|
|
578
|
+
// recurses with its own tokens and returns before the shared
|
|
579
|
+
// children pass below.
|
|
580
|
+
try emitWidgetLayoutClippedChildren(builder, layout, node_index, widget_render_surfaces.bubbleContentTokens(paint_widget, tokens), state, paint_widget);
|
|
581
|
+
// The reaction pill paints LAST, above the capsule and its
|
|
582
|
+
// content, from the PAGE tokens (never the cascaded
|
|
583
|
+
// palette) — mirrors `emitBubbleWidget` on the widget walk.
|
|
584
|
+
try widget_render_surfaces.emitBubbleWidgetReactions(builder, paint_widget, tokens);
|
|
585
|
+
return;
|
|
586
|
+
},
|
|
587
|
+
.resizable, .panel => try widget_render_surfaces.emitPanelWidgetChrome(builder, paint_widget, tokens),
|
|
588
|
+
.popover => try widget_render_surfaces.emitPopoverWidgetChrome(builder, paint_widget, tokens),
|
|
589
|
+
.menu_surface, .dropdown_menu => try widget_render_surfaces.emitMenuSurfaceWidgetChrome(builder, paint_widget, tokens),
|
|
590
|
+
.text => try emitTextWidget(builder, paint_widget, tokens),
|
|
591
|
+
.icon => try emitIconWidget(builder, paint_widget, tokens),
|
|
592
|
+
.image => try emitImageWidget(builder, paint_widget),
|
|
593
|
+
.avatar => try emitAvatarWidget(builder, paint_widget, tokens),
|
|
594
|
+
.badge => try emitBadgeWidget(builder, paint_widget, tokens),
|
|
595
|
+
.button, .toggle_button, .toggle => try widget_render_controls.emitButtonWidget(builder, paint_widget, tokens),
|
|
596
|
+
.icon_button => try widget_render_controls.emitIconButtonWidget(builder, paint_widget, tokens),
|
|
597
|
+
.select => try widget_render_controls.emitSelectWidget(builder, paint_widget, tokens),
|
|
598
|
+
.input, .text_field, .textarea => try widget_render_controls.emitTextFieldWidget(builder, paint_widget, tokens),
|
|
599
|
+
.search_field, .combobox => try widget_render_controls.emitSearchFieldWidget(builder, paint_widget, tokens),
|
|
600
|
+
.tooltip => try widget_render_controls.emitTooltipWidget(builder, paint_widget, tokens),
|
|
601
|
+
.menu_item => try widget_render_controls.emitMenuItemWidget(builder, paint_widget, tokens),
|
|
602
|
+
.list_item => try widget_render_controls.emitListItemWidget(builder, paint_widget, tokens),
|
|
603
|
+
.data_cell => try emitDataCellContent(builder, paint_widget, tokens),
|
|
604
|
+
.status_bar => try emitStatusBarWidget(builder, paint_widget, tokens),
|
|
605
|
+
.segmented_control => try widget_render_controls.emitSegmentedControlWidget(builder, paint_widget, tokens),
|
|
606
|
+
.checkbox => try widget_render_controls.emitCheckboxWidget(builder, paint_widget, tokens),
|
|
607
|
+
.radio => try widget_render_controls.emitRadioWidget(builder, paint_widget, tokens),
|
|
608
|
+
.switch_control => try widget_render_controls.emitToggleWidget(builder, paint_widget, tokens),
|
|
609
|
+
.slider => try widget_render_controls.emitSliderWidget(builder, paint_widget, tokens),
|
|
610
|
+
.progress => try widget_render_controls.emitProgressWidget(builder, paint_widget, tokens),
|
|
611
|
+
.separator => try emitSeparatorWidget(builder, paint_widget, tokens),
|
|
612
|
+
.split_divider => try emitSplitDividerWidget(builder, paint_widget, tokens),
|
|
613
|
+
.skeleton => try emitSkeletonWidget(builder, paint_widget, tokens),
|
|
614
|
+
.spinner => try emitSpinnerWidget(builder, paint_widget, tokens),
|
|
615
|
+
.chart => try emitChartWidget(builder, paint_widget, tokens),
|
|
616
|
+
.input_group => {
|
|
617
|
+
// Focus-within: the GROUP wears the focus ring for its
|
|
618
|
+
// focused descendant (the entry's own ring is dissolved), so
|
|
619
|
+
// the whole group reads as one field. With runtime render
|
|
620
|
+
// state the focused descendant is an id; without it (static
|
|
621
|
+
// trees, docs scenes) the baked child state is truth — the
|
|
622
|
+
// same override-vs-baked split `widgetWithRenderState` makes.
|
|
623
|
+
var group = paint_widget;
|
|
624
|
+
if (!group.state.focused) {
|
|
625
|
+
group.state.focused = if (state.focused_id != null or state.focus_visible_id != null)
|
|
626
|
+
layoutSubtreeHasFocusVisible(layout, node_index, state)
|
|
627
|
+
else
|
|
628
|
+
layoutSubtreeHasBakedFocus(layout, node_index);
|
|
629
|
+
}
|
|
630
|
+
try widget_render_controls.emitInputGroupWidget(builder, group, tokens);
|
|
631
|
+
},
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
try emitWidgetLayoutClippedChildren(builder, layout, node_index, tokens, state, paint_widget);
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
fn emitWidgetLayoutScrollableChildren(
|
|
638
|
+
builder: *Builder,
|
|
639
|
+
layout: anytype,
|
|
640
|
+
parent_index: usize,
|
|
641
|
+
tokens: DesignTokens,
|
|
642
|
+
state: WidgetRenderState,
|
|
643
|
+
widget: Widget,
|
|
644
|
+
) Error!void {
|
|
645
|
+
const clip = if (widget.layout.clip_content) widgetContentClip(widget, tokens) else Clip{
|
|
646
|
+
.id = widgetPartId(widget.id, 1),
|
|
647
|
+
.rect = widget.frame,
|
|
648
|
+
};
|
|
649
|
+
try builder.pushClip(clip);
|
|
650
|
+
try emitWidgetLayoutChildren(builder, layout, parent_index, tokens, state);
|
|
651
|
+
try builder.popClip();
|
|
652
|
+
// Native scroll drivers own the (OS overlay) scrollbar.
|
|
653
|
+
if (!widget.native_scroll) {
|
|
654
|
+
try widget_render_scroll.emitScrollViewScrollbar(builder, widget.frame, widgetScrollSemantics(layout, parent_index).metrics, tokens, widget.id);
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
fn widgetOpacity(widget: Widget) f32 {
|
|
659
|
+
return std.math.clamp(widget.opacity, 0, 1);
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
fn pixelSnapScale(tokens: DesignTokens) ?f32 {
|
|
663
|
+
const scale = tokens.pixel_snap.scale;
|
|
664
|
+
if (!std.math.isFinite(scale) or scale <= 0) return null;
|
|
665
|
+
return scale;
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
fn pixelSnapValueWithScale(value: f32, scale: f32) f32 {
|
|
669
|
+
return @round(value * scale) / scale;
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
fn pixelSnapGeometryRect(tokens: DesignTokens, rect: geometry.RectF) geometry.RectF {
|
|
673
|
+
if (!tokens.pixel_snap.geometry) return rect;
|
|
674
|
+
const scale = pixelSnapScale(tokens) orelse return rect;
|
|
675
|
+
const normalized = rect.normalized();
|
|
676
|
+
const x0 = pixelSnapValueWithScale(normalized.x, scale);
|
|
677
|
+
const y0 = pixelSnapValueWithScale(normalized.y, scale);
|
|
678
|
+
const x1 = pixelSnapValueWithScale(normalized.maxX(), scale);
|
|
679
|
+
const y1 = pixelSnapValueWithScale(normalized.maxY(), scale);
|
|
680
|
+
return geometry.RectF.init(x0, y0, @max(0, x1 - x0), @max(0, y1 - y0));
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
fn pixelSnapGeometryPoint(tokens: DesignTokens, point: geometry.PointF) geometry.PointF {
|
|
684
|
+
if (!tokens.pixel_snap.geometry) return point;
|
|
685
|
+
const scale = pixelSnapScale(tokens) orelse return point;
|
|
686
|
+
return geometry.PointF.init(
|
|
687
|
+
pixelSnapValueWithScale(point.x, scale),
|
|
688
|
+
pixelSnapValueWithScale(point.y, scale),
|
|
689
|
+
);
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
fn pixelSnapTextPoint(tokens: DesignTokens, point: geometry.PointF) geometry.PointF {
|
|
693
|
+
if (!tokens.pixel_snap.text) return point;
|
|
694
|
+
const scale = pixelSnapScale(tokens) orelse return point;
|
|
695
|
+
return geometry.PointF.init(
|
|
696
|
+
pixelSnapValueWithScale(point.x, scale),
|
|
697
|
+
pixelSnapValueWithScale(point.y, scale),
|
|
698
|
+
);
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
fn emitWidgetBackdropBlur(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!void {
|
|
702
|
+
const radius = widgetBackdropBlur(widget, tokens);
|
|
703
|
+
if (radius <= 0 or widget.frame.normalized().isEmpty()) return;
|
|
704
|
+
try builder.blur(.{
|
|
705
|
+
.id = widgetPartId(widget.id, 12),
|
|
706
|
+
.rect = widget.frame,
|
|
707
|
+
.radius = radius,
|
|
708
|
+
});
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
pub fn widgetBackdropBlur(widget: Widget, tokens: DesignTokens) f32 {
|
|
712
|
+
const explicit = nonNegative(widget.backdrop_blur);
|
|
713
|
+
if (explicit > 0) return explicit;
|
|
714
|
+
if (widget.backdrop_blur_token) |token| return nonNegative(tokens.blur.value(token));
|
|
715
|
+
return 0;
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
/// True when this widget's chrome carries the modal scrim: dialogs,
|
|
719
|
+
/// drawers, and sheets are modal — the user must deal with them before
|
|
720
|
+
/// the content behind — so the surface behind gets the token-driven
|
|
721
|
+
/// blur + dim treatment. Anchored surfaces (popover, menus, tooltips)
|
|
722
|
+
/// are NOT modal and never scrim.
|
|
723
|
+
pub fn widgetEmitsModalScrim(widget: Widget, tokens: DesignTokens) bool {
|
|
724
|
+
if (!widget.scrim) return false;
|
|
725
|
+
return switch (widget.kind) {
|
|
726
|
+
.dialog, .drawer, .sheet => tokens.colors.scrim.a > 0 or nonNegative(tokens.blur.scrim) > 0,
|
|
727
|
+
else => false,
|
|
728
|
+
};
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
/// The scrim behind a modal surface: a backdrop blur of everything
|
|
732
|
+
/// already painted across the whole root bounds (real content blur —
|
|
733
|
+
/// the reference rasterizer samples the framebuffer, the GPU packet
|
|
734
|
+
/// carries the same region-blur command), then the translucent wash on
|
|
735
|
+
/// top. Emitted immediately before the surface's own chrome, so
|
|
736
|
+
/// everything below the modal in paint order is behind the glass and
|
|
737
|
+
/// the modal itself stays crisp. Slots 13/14 (blur/wash) sit clear of
|
|
738
|
+
/// the chrome slots (fill 1, border 2, clip 9, text 10, widget backdrop
|
|
739
|
+
/// blur 12). Static by design: it tracks the surface's opacity/transform
|
|
740
|
+
/// wrappers, and honoring reduced motion costs nothing because nothing
|
|
741
|
+
/// here moves.
|
|
742
|
+
fn emitModalSurfaceScrim(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!void {
|
|
743
|
+
if (!widgetEmitsModalScrim(widget, tokens)) return;
|
|
744
|
+
const viewport = (scrim_viewport orelse widget.frame.normalized());
|
|
745
|
+
if (viewport.isEmpty()) return;
|
|
746
|
+
const blur_radius = nonNegative(tokens.blur.scrim);
|
|
747
|
+
if (blur_radius > 0) {
|
|
748
|
+
try builder.blur(.{
|
|
749
|
+
.id = widgetPartId(widget.id, 13),
|
|
750
|
+
.rect = viewport,
|
|
751
|
+
.radius = blur_radius,
|
|
752
|
+
});
|
|
753
|
+
}
|
|
754
|
+
if (tokens.colors.scrim.a > 0) {
|
|
755
|
+
try builder.fillRect(.{
|
|
756
|
+
.id = widgetPartId(widget.id, 14),
|
|
757
|
+
.rect = viewport,
|
|
758
|
+
.fill = colorFill(tokens.colors.scrim),
|
|
759
|
+
});
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
fn widgetContentClip(widget: Widget, tokens: DesignTokens) Clip {
|
|
764
|
+
return .{
|
|
765
|
+
.id = widgetPartId(widget.id, 9),
|
|
766
|
+
.rect = widget.frame,
|
|
767
|
+
.radius = widgetContentClipRadius(widget, tokens),
|
|
768
|
+
};
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
fn widgetContentClipRadius(widget: Widget, tokens: DesignTokens) Radius {
|
|
772
|
+
if (!widget.layout.clip_content) return .{};
|
|
773
|
+
return switch (widget.kind) {
|
|
774
|
+
// The bubble clips at its own capsule arc so wide content (an
|
|
775
|
+
// image child, a full-bleed row) shears along the chrome's
|
|
776
|
+
// corners instead of the generic surface radius.
|
|
777
|
+
.bubble => widget_render_surfaces.bubbleWidgetRadius(widget, tokens),
|
|
778
|
+
.alert, .card, .resizable, .panel, .menu_surface, .dropdown_menu => Radius.all(tokens.radius.lg),
|
|
779
|
+
.accordion => .{},
|
|
780
|
+
.dialog, .popover => Radius.all(tokens.radius.xl),
|
|
781
|
+
.drawer, .sheet => Radius.all(tokens.radius.lg),
|
|
782
|
+
.tooltip => Radius.all(tokens.radius.md),
|
|
783
|
+
else => .{},
|
|
784
|
+
};
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
fn emitAlertWidget(builder: *Builder, widget: Widget, tokens: DesignTokens, depth: usize) Error!void {
|
|
788
|
+
try widget_render_surfaces.emitAlertWidgetChrome(builder, widget, tokens);
|
|
789
|
+
try emitWidgetClippedChildren(builder, widget, tokens, depth);
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
fn emitCardWidget(builder: *Builder, widget: Widget, tokens: DesignTokens, depth: usize) Error!void {
|
|
793
|
+
try widget_render_surfaces.emitCardWidgetChrome(builder, widget, tokens);
|
|
794
|
+
try emitWidgetClippedChildren(builder, widget, tokens, depth);
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
fn emitDialogSurfaceWidget(builder: *Builder, widget: Widget, tokens: DesignTokens, depth: usize) Error!void {
|
|
798
|
+
try emitModalSurfaceScrim(builder, widget, tokens);
|
|
799
|
+
try widget_render_surfaces.emitDialogSurfaceWidgetChrome(builder, widget, tokens);
|
|
800
|
+
try emitWidgetClippedChildren(builder, widget, tokens, depth);
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
fn emitDrawerSurfaceWidget(builder: *Builder, widget: Widget, tokens: DesignTokens, depth: usize) Error!void {
|
|
804
|
+
try emitModalSurfaceScrim(builder, widget, tokens);
|
|
805
|
+
try widget_render_surfaces.emitDrawerSurfaceWidgetChrome(builder, widget, tokens);
|
|
806
|
+
try emitWidgetClippedChildren(builder, widget, tokens, depth);
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
fn emitSheetSurfaceWidget(builder: *Builder, widget: Widget, tokens: DesignTokens, depth: usize) Error!void {
|
|
810
|
+
try emitModalSurfaceScrim(builder, widget, tokens);
|
|
811
|
+
try widget_render_surfaces.emitSheetSurfaceWidgetChrome(builder, widget, tokens);
|
|
812
|
+
try emitWidgetClippedChildren(builder, widget, tokens, depth);
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
fn emitPanelWidget(builder: *Builder, widget: Widget, tokens: DesignTokens, depth: usize) Error!void {
|
|
816
|
+
try widget_render_surfaces.emitPanelWidgetChrome(builder, widget, tokens);
|
|
817
|
+
try emitWidgetClippedChildren(builder, widget, tokens, depth);
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
fn emitBubbleWidget(builder: *Builder, widget: Widget, tokens: DesignTokens, depth: usize) Error!void {
|
|
821
|
+
try widget_render_surfaces.emitBubbleWidgetChrome(builder, widget, tokens);
|
|
822
|
+
// Children render against the bubble's cascaded token palette
|
|
823
|
+
// (knockout body ink on a filled bubble) — the whole subtree, not
|
|
824
|
+
// just direct children, because the recursion below threads these
|
|
825
|
+
// tokens all the way down.
|
|
826
|
+
try emitWidgetClippedChildren(builder, widget, widget_render_surfaces.bubbleContentTokens(widget, tokens), depth);
|
|
827
|
+
// The reaction pill paints LAST — it straddles the bubble's bottom
|
|
828
|
+
// edge above the capsule and its content, the reference's overlap
|
|
829
|
+
// treatment — and from the PAGE tokens, never the bubble's cascaded
|
|
830
|
+
// palette: the pill sits on the conversation plane, so a primary
|
|
831
|
+
// bubble's knockout ink does not apply to it.
|
|
832
|
+
try widget_render_surfaces.emitBubbleWidgetReactions(builder, widget, tokens);
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
// The HIERARCHICAL walk's disclosure is discrete: this path emits
|
|
836
|
+
// source trees directly (static scenes, docs specimens) where no
|
|
837
|
+
// runtime tween exists, so a closed item simply skips its content.
|
|
838
|
+
// Animated disclosure lives on the LAYOUT walk above — the runtime's
|
|
839
|
+
// disclosure tween eases the retained frames and the layout emission
|
|
840
|
+
// clips the full-size content to the animated frame mid-reveal.
|
|
841
|
+
fn emitAccordionWidget(builder: *Builder, widget: Widget, tokens: DesignTokens, depth: usize) Error!void {
|
|
842
|
+
try widget_render_surfaces.emitAccordionWidgetChrome(builder, widget, tokens);
|
|
843
|
+
if (!accordionChildrenVisible(widget)) return;
|
|
844
|
+
try emitWidgetClippedChildren(builder, widget, tokens, depth);
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
/// One accordion's disclosure pose on the layout walk, judged from
|
|
848
|
+
/// retained state plus geometry:
|
|
849
|
+
/// - `open`: state open AND the frame holds everything the content
|
|
850
|
+
/// reaches — the settled pose; content emits unclipped, exactly
|
|
851
|
+
/// the pre-disclosure display list.
|
|
852
|
+
/// - `revealing`: the frame trails the content — a reveal in flight
|
|
853
|
+
/// (state open, frame still growing) or a conceal in flight (state
|
|
854
|
+
/// closed, but the runtime's tween says this id is still moving).
|
|
855
|
+
/// - `closed`: state closed with no tween in flight — content emits
|
|
856
|
+
/// nothing.
|
|
857
|
+
const AccordionLayoutDisclosure = enum { closed, revealing, open };
|
|
858
|
+
|
|
859
|
+
fn accordionLayoutDisclosure(layout: anytype, node_index: usize, widget: Widget, state: WidgetRenderState) AccordionLayoutDisclosure {
|
|
860
|
+
if (accordionChildrenVisible(widget)) {
|
|
861
|
+
return if (widget_tree.disclosureSettledOpen(layout, node_index)) .open else .revealing;
|
|
862
|
+
}
|
|
863
|
+
return if (state.disclosureRevealing(widget.id)) .revealing else .closed;
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
fn emitTabsWidget(builder: *Builder, widget: Widget, tokens: DesignTokens, depth: usize) Error!void {
|
|
867
|
+
try widget_render_surfaces.emitTabsListWidgetChrome(builder, widget, tokens);
|
|
868
|
+
try emitWidgetClippedChildren(builder, widget, tokens, depth);
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
fn emitPopoverWidget(builder: *Builder, widget: Widget, tokens: DesignTokens, depth: usize) Error!void {
|
|
872
|
+
try widget_render_surfaces.emitPopoverWidgetChrome(builder, widget, tokens);
|
|
873
|
+
try emitWidgetClippedChildren(builder, widget, tokens, depth);
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
fn emitMenuSurfaceWidget(builder: *Builder, widget: Widget, tokens: DesignTokens, depth: usize) Error!void {
|
|
877
|
+
try widget_render_surfaces.emitMenuSurfaceWidgetChrome(builder, widget, tokens);
|
|
878
|
+
try emitWidgetClippedChildren(builder, widget, tokens, depth);
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
fn emitScrollViewWidget(builder: *Builder, widget: Widget, tokens: DesignTokens, depth: usize) Error!void {
|
|
882
|
+
try builder.pushClip(.{ .id = widgetPartId(widget.id, 1), .rect = widget.frame });
|
|
883
|
+
try emitWidgetChildren(builder, widget.children, tokens, depth);
|
|
884
|
+
try builder.popClip();
|
|
885
|
+
// Native scroll drivers own the (OS overlay) scrollbar.
|
|
886
|
+
if (!widget.native_scroll) {
|
|
887
|
+
try widget_render_scroll.emitScrollViewScrollbar(builder, widget.frame, widget_render_scroll.widgetScrollMetricsForWidget(widget, tokens), tokens, widget.id);
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
fn emitWidgetClippedChildren(builder: *Builder, widget: Widget, tokens: DesignTokens, depth: usize) Error!void {
|
|
892
|
+
if (widget.layout.clip_content) try builder.pushClip(widgetContentClip(widget, tokens));
|
|
893
|
+
try emitWidgetChildren(builder, widget.children, tokens, depth);
|
|
894
|
+
if (widget.layout.clip_content) try builder.popClip();
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
fn widgetScrollSemantics(layout: anytype, node_index: usize) widget_semantics.WidgetScrollSemantics {
|
|
898
|
+
return widget_semantics.widgetScrollSemantics(layout, node_index, widget_layout.virtualWidgetScrollContentExtent);
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
fn emitWidgetLayoutClippedChildren(
|
|
902
|
+
builder: *Builder,
|
|
903
|
+
layout: anytype,
|
|
904
|
+
parent_index: usize,
|
|
905
|
+
tokens: DesignTokens,
|
|
906
|
+
state: WidgetRenderState,
|
|
907
|
+
widget: Widget,
|
|
908
|
+
) Error!void {
|
|
909
|
+
if (widget.layout.clip_content) try builder.pushClip(widgetContentClip(widget, tokens));
|
|
910
|
+
try emitWidgetLayoutChildren(builder, layout, parent_index, tokens, state);
|
|
911
|
+
if (widget.layout.clip_content) try builder.popClip();
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
fn emitTextWidget(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!void {
|
|
915
|
+
if (widget.spans.len > 0) return emitTextSpansWidget(builder, widget, tokens);
|
|
916
|
+
// Empty text leaves are hit/semantics-only: paragraph link hotspots
|
|
917
|
+
// and composite press overlays (timeline items) draw nothing.
|
|
918
|
+
if (widget.text.len == 0) return;
|
|
919
|
+
// Plain leaves paint the single line layout measured (wrapping is
|
|
920
|
+
// the span-paragraph path, `wrap="true"`), so a width-constrained
|
|
921
|
+
// title never paints a second line over the row below. Content past
|
|
922
|
+
// the frame follows the widget's overflow policy: trailing ellipsis
|
|
923
|
+
// by default — layout elides the drawn line while `widget.text`
|
|
924
|
+
// stays the selection/copy source of truth — or the explicit clip
|
|
925
|
+
// opt-in (`overflow="clip"`), which keeps the historical hard-cut
|
|
926
|
+
// behind a frame clip for fixed-format content.
|
|
927
|
+
const clip_overflow = widget.text_overflow == .clip;
|
|
928
|
+
if (clip_overflow) {
|
|
929
|
+
try builder.pushClip(.{ .id = widgetPartId(widget.id, 9), .rect = widget.frame });
|
|
930
|
+
}
|
|
931
|
+
try emitStaticTextSelection(builder, widget, tokens);
|
|
932
|
+
const text_size = widgetBodyTextSize(widget, tokens);
|
|
933
|
+
try builder.drawText(.{
|
|
934
|
+
.id = widgetPartId(widget.id, 1),
|
|
935
|
+
.font_id = tokens.typography.font_id,
|
|
936
|
+
.size = text_size,
|
|
937
|
+
.origin = pixelSnapTextPoint(tokens, textOrigin(widget.frame, text_size, 0)),
|
|
938
|
+
.color = widgetForegroundColor(widget, tokens, tokens.colors.text),
|
|
939
|
+
.text = widget.text,
|
|
940
|
+
.text_layout = .{
|
|
941
|
+
.max_width = textWrapMaxWidth(tokens, widget.frame.width),
|
|
942
|
+
.line_height = text_size * 1.25,
|
|
943
|
+
.wrap = .none,
|
|
944
|
+
.alignment = widget.text_alignment,
|
|
945
|
+
.overflow = widget.text_overflow,
|
|
946
|
+
.measure = tokens.text_measure,
|
|
947
|
+
},
|
|
948
|
+
});
|
|
949
|
+
if (clip_overflow) try builder.popClip();
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
/// Wrap budget for text painted inside a pixel-snapped frame — the
|
|
953
|
+
/// shared quantum hand-back (`widget_metrics.textWrapMaxWidth`), aliased
|
|
954
|
+
/// for the emit sites here.
|
|
955
|
+
const textWrapMaxWidth = widget_metrics.textWrapMaxWidth;
|
|
956
|
+
|
|
957
|
+
/// Static text selection highlight: fill rects behind the selected lines
|
|
958
|
+
/// of a `.text` widget (plain or span paragraph). Command ids are hashed
|
|
959
|
+
/// per line ordinal like span runs, so retained diffing stays stable.
|
|
960
|
+
fn emitStaticTextSelection(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!void {
|
|
961
|
+
const range = widget_access.widgetTextSelectionRange(widget) orelse return;
|
|
962
|
+
if (range.isCollapsed(widget.text.len)) return;
|
|
963
|
+
var rect_buffer: [widget_text_select.max_static_text_selection_rects]text_model.TextSelectionRect = undefined;
|
|
964
|
+
const rects = widget_text_select.staticTextSelectionRects(widget, tokens, range, &rect_buffer);
|
|
965
|
+
for (rects, 0..) |selection, ordinal| {
|
|
966
|
+
try builder.fillRoundedRect(.{
|
|
967
|
+
.id = textSelectionCommandId(widget.id, ordinal),
|
|
968
|
+
.rect = pixelSnapGeometryRect(tokens, selection.rect),
|
|
969
|
+
.radius = Radius.all(tokens.radius.sm),
|
|
970
|
+
.fill = .{ .color = staticTextSelectionFillColor(widget, tokens) },
|
|
971
|
+
});
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
/// Draw a span paragraph: one single-line text command per laid-out run
|
|
976
|
+
/// plus thin fill rects for underline/strikethrough decorations. Runs and
|
|
977
|
+
/// decorations get stable hashed command ids derived from the widget id
|
|
978
|
+
/// and their ordinal, so retained diffing works across frames.
|
|
979
|
+
fn emitTextSpansWidget(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!void {
|
|
980
|
+
const content = widget.frame.inset(widget.layout.padding);
|
|
981
|
+
var runs: [text_spans_model.max_text_span_runs_per_paragraph]text_spans_model.TextSpanRun = undefined;
|
|
982
|
+
const layout = text_spans_model.layoutTextSpans(
|
|
983
|
+
widget.spans,
|
|
984
|
+
widget_metrics.widgetTextSpanLayoutOptions(widget, tokens, textWrapMaxWidth(tokens, content.width)),
|
|
985
|
+
&runs,
|
|
986
|
+
);
|
|
987
|
+
|
|
988
|
+
// Span background highlights (intra-line diff emphasis): one
|
|
989
|
+
// full-line-height rect per run, the same geometry selection rects
|
|
990
|
+
// use, painted before selection and glyphs. Edge-snapped rects of
|
|
991
|
+
// adjacent runs share their boundary, so equal backgrounds abut
|
|
992
|
+
// without seams.
|
|
993
|
+
for (layout.runs, 0..) |run, ordinal| {
|
|
994
|
+
if (run.text.len == 0) continue;
|
|
995
|
+
const background = widget.spans[run.span_index].background orelse continue;
|
|
996
|
+
const bounds = text_spans_model.textSpanRunBounds(layout, run);
|
|
997
|
+
try builder.fillRect(.{
|
|
998
|
+
.id = textSpanBackgroundCommandId(widget.id, ordinal),
|
|
999
|
+
.rect = pixelSnapGeometryRect(tokens, geometry.RectF.init(
|
|
1000
|
+
content.x + bounds.x,
|
|
1001
|
+
content.y + bounds.y,
|
|
1002
|
+
bounds.width,
|
|
1003
|
+
bounds.height,
|
|
1004
|
+
)),
|
|
1005
|
+
.fill = colorFill(text_spans_model.textSpanColorValue(tokens.colors, background)),
|
|
1006
|
+
});
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
try emitStaticTextSelection(builder, widget, tokens);
|
|
1010
|
+
|
|
1011
|
+
var decoration_ordinal: usize = 0;
|
|
1012
|
+
for (layout.runs, 0..) |run, ordinal| {
|
|
1013
|
+
if (run.text.len == 0) continue;
|
|
1014
|
+
const span = widget.spans[run.span_index];
|
|
1015
|
+
const is_link = span.link.len > 0;
|
|
1016
|
+
const color = if (span.color) |ref|
|
|
1017
|
+
text_spans_model.textSpanColorValue(tokens.colors, ref)
|
|
1018
|
+
else if (is_link)
|
|
1019
|
+
widgetForegroundColor(widget, tokens, tokens.colors.accent)
|
|
1020
|
+
else
|
|
1021
|
+
widgetForegroundColor(widget, tokens, tokens.colors.text);
|
|
1022
|
+
const origin = pixelSnapTextPoint(tokens, geometry.PointF.init(content.x + run.x, content.y + run.baseline));
|
|
1023
|
+
try builder.drawText(.{
|
|
1024
|
+
.id = textSpanRunCommandId(widget.id, ordinal),
|
|
1025
|
+
.font_id = run.font_id,
|
|
1026
|
+
.size = run.size,
|
|
1027
|
+
.origin = origin,
|
|
1028
|
+
.color = color,
|
|
1029
|
+
.text = run.text,
|
|
1030
|
+
// Wrapping already happened at the span level (each run is one
|
|
1031
|
+
// line segment), so the options carry no wrap work — they carry
|
|
1032
|
+
// the measurement seam. Renderers that walk per-cluster
|
|
1033
|
+
// advances (the reference renderer behind every automation
|
|
1034
|
+
// screenshot) then advance with the same provider layout
|
|
1035
|
+
// positioned the runs with; without it a provider-kerned prose
|
|
1036
|
+
// run repainted at estimator advances overran the next span's
|
|
1037
|
+
// x and visually swallowed the inter-span space
|
|
1038
|
+
// ("remaining`experimental_`" -> "remainingexperimental_").
|
|
1039
|
+
.text_layout = .{
|
|
1040
|
+
.max_width = 0,
|
|
1041
|
+
.line_height = layout.line_height,
|
|
1042
|
+
.wrap = .none,
|
|
1043
|
+
.alignment = .start,
|
|
1044
|
+
.measure = tokens.text_measure,
|
|
1045
|
+
},
|
|
1046
|
+
});
|
|
1047
|
+
|
|
1048
|
+
const thickness = @max(1, tokens.stroke.hairline);
|
|
1049
|
+
if (span.underline or is_link) {
|
|
1050
|
+
try builder.fillRect(.{
|
|
1051
|
+
.id = textSpanDecorationCommandId(widget.id, decoration_ordinal),
|
|
1052
|
+
.rect = pixelSnapGeometryRect(tokens, geometry.RectF.init(
|
|
1053
|
+
content.x + run.x,
|
|
1054
|
+
content.y + run.baseline + @max(1, run.size * 0.1),
|
|
1055
|
+
run.width,
|
|
1056
|
+
thickness,
|
|
1057
|
+
)),
|
|
1058
|
+
.fill = colorFill(color),
|
|
1059
|
+
});
|
|
1060
|
+
decoration_ordinal += 1;
|
|
1061
|
+
}
|
|
1062
|
+
if (span.strikethrough) {
|
|
1063
|
+
try builder.fillRect(.{
|
|
1064
|
+
.id = textSpanDecorationCommandId(widget.id, decoration_ordinal),
|
|
1065
|
+
.rect = pixelSnapGeometryRect(tokens, geometry.RectF.init(
|
|
1066
|
+
content.x + run.x,
|
|
1067
|
+
content.y + run.baseline - run.size * 0.3,
|
|
1068
|
+
run.width,
|
|
1069
|
+
thickness,
|
|
1070
|
+
)),
|
|
1071
|
+
.fill = colorFill(color),
|
|
1072
|
+
});
|
|
1073
|
+
decoration_ordinal += 1;
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
}
|
|
1077
|
+
|
|
1078
|
+
pub fn textSpanRunCommandId(widget_id: ObjectId, ordinal: usize) ObjectId {
|
|
1079
|
+
return textSpanCommandId(0x5eed_59a2_0000_0001, widget_id, ordinal);
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
pub fn textSpanDecorationCommandId(widget_id: ObjectId, ordinal: usize) ObjectId {
|
|
1083
|
+
return textSpanCommandId(0x5eed_59a2_0000_0002, widget_id, ordinal);
|
|
1084
|
+
}
|
|
1085
|
+
|
|
1086
|
+
pub fn textSpanBackgroundCommandId(widget_id: ObjectId, ordinal: usize) ObjectId {
|
|
1087
|
+
return textSpanCommandId(0x5eed_59a2_0000_0004, widget_id, ordinal);
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
pub fn textSelectionCommandId(widget_id: ObjectId, ordinal: usize) ObjectId {
|
|
1091
|
+
return textSpanCommandId(0x5eed_59a2_0000_0003, widget_id, ordinal);
|
|
1092
|
+
}
|
|
1093
|
+
|
|
1094
|
+
fn textSpanCommandId(seed: u64, widget_id: ObjectId, ordinal: usize) ObjectId {
|
|
1095
|
+
var hasher = std.hash.Wyhash.init(seed);
|
|
1096
|
+
hasher.update(std.mem.asBytes(&widget_id));
|
|
1097
|
+
hasher.update(std.mem.asBytes(&@as(u64, ordinal)));
|
|
1098
|
+
const value = hasher.final();
|
|
1099
|
+
return if (value == 0) 1 else value;
|
|
1100
|
+
}
|
|
1101
|
+
|
|
1102
|
+
fn emitIconWidget(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!void {
|
|
1103
|
+
// A vector icon name — built-in or app-registered
|
|
1104
|
+
// (`icons.registerAppIcons`) — draws crisp parsed paths: `widget.icon`
|
|
1105
|
+
// first (the explicit channel), then an icon-name `text`; any other
|
|
1106
|
+
// text keeps the historical glyph rendering (apps that put literal
|
|
1107
|
+
// glyph characters in `icon.text` are untouched). The explicit
|
|
1108
|
+
// channel never falls through: a name that resolves nowhere draws the
|
|
1109
|
+
// missing-icon fallback (the build-time Debug warning names the
|
|
1110
|
+
// value), so a broken reference is visible, never silent.
|
|
1111
|
+
if (icon_model.resolveOrMissing(widget.icon)) |icon| {
|
|
1112
|
+
return emitVectorIconWidget(builder, widget, tokens, icon);
|
|
1113
|
+
}
|
|
1114
|
+
if (widget.text.len == 0) return;
|
|
1115
|
+
if (icon_model.resolve(widget.text)) |icon| {
|
|
1116
|
+
return emitVectorIconWidget(builder, widget, tokens, icon);
|
|
1117
|
+
}
|
|
1118
|
+
const size = iconGlyphSize(widget, tokens);
|
|
1119
|
+
try builder.drawText(.{
|
|
1120
|
+
.id = widgetPartId(widget.id, 1),
|
|
1121
|
+
.font_id = tokens.typography.font_id,
|
|
1122
|
+
.size = size,
|
|
1123
|
+
.origin = pixelSnapTextPoint(tokens, centeredTextOrigin(widget.frame, widget.text, size, tokens)),
|
|
1124
|
+
.color = widgetForegroundColor(widget, tokens, tokens.colors.text),
|
|
1125
|
+
.text = widget.text,
|
|
1126
|
+
});
|
|
1127
|
+
}
|
|
1128
|
+
|
|
1129
|
+
/// Draw a parsed vector icon fitted (contain, centered) into the widget
|
|
1130
|
+
/// frame via the shared `emitVectorIcon` helper (buttons and icon
|
|
1131
|
+
/// buttons draw inline icons through the same code path, so geometry and
|
|
1132
|
+
/// command shapes agree everywhere). `currentColor` resolves to the
|
|
1133
|
+
/// widget's foreground color token.
|
|
1134
|
+
fn emitVectorIconWidget(builder: *Builder, widget: Widget, tokens: DesignTokens, icon: *const icon_model.Icon) Error!void {
|
|
1135
|
+
const color = widgetForegroundColor(widget, tokens, tokens.colors.text);
|
|
1136
|
+
try widget_render_controls.emitVectorIcon(builder, widget.id, 1, widget.frame, color, icon);
|
|
1137
|
+
}
|
|
1138
|
+
|
|
1139
|
+
fn emitImageWidget(builder: *Builder, widget: Widget) Error!void {
|
|
1140
|
+
if (widget.image_id == 0 or widget.frame.normalized().isEmpty()) return;
|
|
1141
|
+
const clips_image = widget.image_fit == .cover;
|
|
1142
|
+
if (clips_image) try builder.pushClip(.{ .id = widgetPartId(widget.id, 2), .rect = widget.frame });
|
|
1143
|
+
try builder.drawImage(.{
|
|
1144
|
+
.id = widgetPartId(widget.id, 1),
|
|
1145
|
+
.image_id = widget.image_id,
|
|
1146
|
+
.src = widget.image_src,
|
|
1147
|
+
.dst = widget.frame,
|
|
1148
|
+
.opacity = widget.image_opacity,
|
|
1149
|
+
.fit = widget.image_fit,
|
|
1150
|
+
.sampling = widget.image_sampling,
|
|
1151
|
+
});
|
|
1152
|
+
if (clips_image) try builder.popClip();
|
|
1153
|
+
}
|
|
1154
|
+
|
|
1155
|
+
fn emitAvatarWidget(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!void {
|
|
1156
|
+
const visual = componentControlVisualTokens(widget, tokens);
|
|
1157
|
+
const radius = componentPillRadius(widget, visual, widget.frame.height * 0.5);
|
|
1158
|
+
const background = widgetBackgroundColor(widget, visual.background orelse tokens.colors.surface_subtle);
|
|
1159
|
+
try builder.fillRoundedRect(.{
|
|
1160
|
+
.id = widgetPartId(widget.id, 1),
|
|
1161
|
+
.rect = widget.frame,
|
|
1162
|
+
.radius = radius,
|
|
1163
|
+
.fill = colorFill(background),
|
|
1164
|
+
});
|
|
1165
|
+
|
|
1166
|
+
if (widget.image_id != 0) {
|
|
1167
|
+
try builder.pushClip(.{
|
|
1168
|
+
.id = widgetPartId(widget.id, 2),
|
|
1169
|
+
.rect = widget.frame,
|
|
1170
|
+
.radius = radius,
|
|
1171
|
+
});
|
|
1172
|
+
try builder.drawImage(.{
|
|
1173
|
+
.id = widgetPartId(widget.id, 3),
|
|
1174
|
+
.image_id = widget.image_id,
|
|
1175
|
+
.src = widget.image_src,
|
|
1176
|
+
.dst = widget.frame,
|
|
1177
|
+
.opacity = widget.image_opacity,
|
|
1178
|
+
.fit = widget.image_fit,
|
|
1179
|
+
.sampling = widget.image_sampling,
|
|
1180
|
+
// The render plan flattens the clip stack to rects, so the
|
|
1181
|
+
// pill clip above only crops the bounds; the draw's own
|
|
1182
|
+
// radius mask is what actually rounds the image.
|
|
1183
|
+
.radius = radius,
|
|
1184
|
+
});
|
|
1185
|
+
try builder.popClip();
|
|
1186
|
+
} else if (widget.text.len > 0) {
|
|
1187
|
+
const text_size = widgetLabelTextSize(widget, tokens);
|
|
1188
|
+
try builder.drawText(.{
|
|
1189
|
+
.id = widgetPartId(widget.id, 3),
|
|
1190
|
+
.font_id = tokens.typography.font_id,
|
|
1191
|
+
.size = text_size,
|
|
1192
|
+
// Layout alignment centers the line inside `max_width`, so
|
|
1193
|
+
// the origin must be the frame START like every other
|
|
1194
|
+
// center-aligned text_layout draw — a pre-centered origin
|
|
1195
|
+
// here applied the centering offset twice and pushed the
|
|
1196
|
+
// initials right of the circle center.
|
|
1197
|
+
.origin = pixelSnapTextPoint(tokens, boundedTextOrigin(widget.frame, text_size, 0)),
|
|
1198
|
+
.color = widgetForegroundColor(widget, tokens, visual.foreground orelse tokens.colors.text_muted),
|
|
1199
|
+
.text = widget.text,
|
|
1200
|
+
.text_layout = boundedTextLayout(widget.frame, text_size, 0, .center, .none, tokens),
|
|
1201
|
+
});
|
|
1202
|
+
}
|
|
1203
|
+
|
|
1204
|
+
try builder.strokeRect(.{
|
|
1205
|
+
.id = widgetPartId(widget.id, 4),
|
|
1206
|
+
.rect = widget.frame,
|
|
1207
|
+
.radius = radius,
|
|
1208
|
+
.stroke = .{
|
|
1209
|
+
.fill = widgetBorderFill(widget, visual.border orelse tokens.colors.border),
|
|
1210
|
+
.width = controlStrokeWidth(widget, visual, tokens.stroke.hairline),
|
|
1211
|
+
},
|
|
1212
|
+
});
|
|
1213
|
+
}
|
|
1214
|
+
|
|
1215
|
+
fn emitBadgeWidget(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!void {
|
|
1216
|
+
const visual = componentControlVisualTokens(widget, tokens);
|
|
1217
|
+
const radius = componentPillRadius(widget, visual, widget.frame.height * 0.5);
|
|
1218
|
+
const text_size = widget_metrics.widgetBadgeTextSize(widget, tokens);
|
|
1219
|
+
const text_inset = widgetControlInset(widget, tokens, tokens.spacing.sm);
|
|
1220
|
+
try builder.fillRoundedRect(.{
|
|
1221
|
+
.id = widgetPartId(widget.id, 1),
|
|
1222
|
+
.rect = widget.frame,
|
|
1223
|
+
.radius = radius,
|
|
1224
|
+
.fill = colorFill(badgeBackgroundColor(widget, tokens, visual)),
|
|
1225
|
+
});
|
|
1226
|
+
try builder.strokeRect(.{
|
|
1227
|
+
.id = widgetPartId(widget.id, 2),
|
|
1228
|
+
.rect = widget.frame,
|
|
1229
|
+
.radius = radius,
|
|
1230
|
+
.stroke = .{
|
|
1231
|
+
.fill = widgetBorderFill(widget, badgeBorderColor(widget, tokens, visual)),
|
|
1232
|
+
.width = badgeStrokeWidth(widget, tokens, visual),
|
|
1233
|
+
},
|
|
1234
|
+
});
|
|
1235
|
+
const content_color = badgeTextColor(widget, tokens, visual);
|
|
1236
|
+
// Inline vector icon: icon-only badges center it (the stepper's
|
|
1237
|
+
// completed check, status chips); icon + text draws it before the
|
|
1238
|
+
// label. One widget, one tint — and no text glyph outside the bundled
|
|
1239
|
+
// face's coverage (the stepper-checkmark tofu fix).
|
|
1240
|
+
const icon = icon_model.resolveOrMissing(widget.icon);
|
|
1241
|
+
if (icon) |resolved| {
|
|
1242
|
+
const icon_extent = widget_metrics.widgetBadgeIconExtent(widget, tokens);
|
|
1243
|
+
const icon_y = widget.frame.y + (widget.frame.height - icon_extent) * 0.5;
|
|
1244
|
+
if (widget.text.len == 0) {
|
|
1245
|
+
const icon_frame = geometry.RectF.init(
|
|
1246
|
+
widget.frame.x + (widget.frame.width - icon_extent) * 0.5,
|
|
1247
|
+
icon_y,
|
|
1248
|
+
icon_extent,
|
|
1249
|
+
icon_extent,
|
|
1250
|
+
);
|
|
1251
|
+
try widget_render_controls.emitVectorIcon(builder, widget.id, 4, icon_frame, content_color, resolved);
|
|
1252
|
+
return;
|
|
1253
|
+
}
|
|
1254
|
+
const icon_frame = geometry.RectF.init(widget.frame.x + text_inset, icon_y, icon_extent, icon_extent);
|
|
1255
|
+
try widget_render_controls.emitVectorIcon(builder, widget.id, 4, icon_frame, content_color, resolved);
|
|
1256
|
+
const shift = icon_extent + widget_metrics.widgetBadgeIconGap(widget, tokens);
|
|
1257
|
+
const text_frame = geometry.RectF.init(
|
|
1258
|
+
widget.frame.x + shift,
|
|
1259
|
+
widget.frame.y,
|
|
1260
|
+
@max(1, widget.frame.width - shift),
|
|
1261
|
+
widget.frame.height,
|
|
1262
|
+
);
|
|
1263
|
+
try builder.drawText(.{
|
|
1264
|
+
.id = widgetPartId(widget.id, 3),
|
|
1265
|
+
.font_id = tokens.typography.font_id,
|
|
1266
|
+
.size = text_size,
|
|
1267
|
+
.origin = pixelSnapTextPoint(tokens, boundedTextOrigin(text_frame, text_size, text_inset)),
|
|
1268
|
+
.color = content_color,
|
|
1269
|
+
.text = widget.text,
|
|
1270
|
+
.text_layout = boundedTextLayout(text_frame, text_size, text_inset, .center, .none, tokens),
|
|
1271
|
+
});
|
|
1272
|
+
return;
|
|
1273
|
+
}
|
|
1274
|
+
if (widget.text.len > 0) {
|
|
1275
|
+
try builder.drawText(.{
|
|
1276
|
+
.id = widgetPartId(widget.id, 3),
|
|
1277
|
+
.font_id = tokens.typography.font_id,
|
|
1278
|
+
.size = text_size,
|
|
1279
|
+
.origin = pixelSnapTextPoint(tokens, boundedTextOrigin(widget.frame, text_size, text_inset)),
|
|
1280
|
+
.color = content_color,
|
|
1281
|
+
.text = widget.text,
|
|
1282
|
+
.text_layout = boundedTextLayout(widget.frame, text_size, text_inset, .center, .none, tokens),
|
|
1283
|
+
});
|
|
1284
|
+
}
|
|
1285
|
+
}
|
|
1286
|
+
|
|
1287
|
+
fn emitSeparatorWidget(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!void {
|
|
1288
|
+
const visual = componentControlVisualTokens(widget, tokens);
|
|
1289
|
+
const normalized = widget.frame.normalized();
|
|
1290
|
+
if (normalized.isEmpty()) return;
|
|
1291
|
+
const thickness = controlStrokeWidth(widget, visual, tokens.stroke.hairline);
|
|
1292
|
+
const line_rect = if (normalized.width >= normalized.height)
|
|
1293
|
+
geometry.RectF.init(normalized.x, normalized.y + (normalized.height - thickness) * 0.5, normalized.width, thickness)
|
|
1294
|
+
else
|
|
1295
|
+
geometry.RectF.init(normalized.x + (normalized.width - thickness) * 0.5, normalized.y, thickness, normalized.height);
|
|
1296
|
+
try builder.fillRect(.{
|
|
1297
|
+
.id = widgetPartId(widget.id, 1),
|
|
1298
|
+
.rect = pixelSnapGeometryRect(tokens, line_rect),
|
|
1299
|
+
.fill = colorFill(widgetBackgroundColor(widget, visual.background orelse visual.border orelse tokens.colors.border)),
|
|
1300
|
+
});
|
|
1301
|
+
}
|
|
1302
|
+
|
|
1303
|
+
/// The split's drag handle: a centered vertical hairline in the divider
|
|
1304
|
+
/// band. Hover/press tint the line with the accent color (the band is
|
|
1305
|
+
/// the hit target, so the affordance appears as the pointer reaches
|
|
1306
|
+
/// it); keyboard focus draws the standard focus ring around the band.
|
|
1307
|
+
fn emitSplitDividerWidget(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!void {
|
|
1308
|
+
const visual = componentControlVisualTokens(widget, tokens);
|
|
1309
|
+
const normalized = widget.frame.normalized();
|
|
1310
|
+
if (normalized.isEmpty()) return;
|
|
1311
|
+
const active = widget.state.hovered or widget.state.pressed;
|
|
1312
|
+
const thickness = if (active)
|
|
1313
|
+
@max(2, controlStrokeWidth(widget, visual, tokens.stroke.hairline))
|
|
1314
|
+
else
|
|
1315
|
+
controlStrokeWidth(widget, visual, tokens.stroke.hairline);
|
|
1316
|
+
const line_rect = geometry.RectF.init(
|
|
1317
|
+
normalized.x + (normalized.width - thickness) * 0.5,
|
|
1318
|
+
normalized.y,
|
|
1319
|
+
thickness,
|
|
1320
|
+
normalized.height,
|
|
1321
|
+
);
|
|
1322
|
+
const line_color = if (active)
|
|
1323
|
+
widgetAccentColor(widget, tokens.colors.accent)
|
|
1324
|
+
else
|
|
1325
|
+
widgetBorderColor(widget, visual.border orelse tokens.colors.border);
|
|
1326
|
+
try builder.fillRect(.{
|
|
1327
|
+
.id = widgetPartId(widget.id, 1),
|
|
1328
|
+
.rect = pixelSnapGeometryRect(tokens, line_rect),
|
|
1329
|
+
.fill = colorFill(line_color),
|
|
1330
|
+
});
|
|
1331
|
+
if (widget.state.focused) {
|
|
1332
|
+
try builder.strokeRect(.{
|
|
1333
|
+
.id = widgetPartId(widget.id, 2),
|
|
1334
|
+
.rect = pixelSnapGeometryRect(tokens, normalized),
|
|
1335
|
+
.radius = Radius.all(tokens.radius.sm),
|
|
1336
|
+
.stroke = .{
|
|
1337
|
+
.fill = widget_render_style.widgetFocusRingFill(widget, tokens),
|
|
1338
|
+
.width = tokens.stroke.focus,
|
|
1339
|
+
},
|
|
1340
|
+
});
|
|
1341
|
+
}
|
|
1342
|
+
}
|
|
1343
|
+
|
|
1344
|
+
fn emitStatusBarWidget(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!void {
|
|
1345
|
+
const frame = widget.frame.normalized();
|
|
1346
|
+
if (frame.isEmpty()) return;
|
|
1347
|
+
|
|
1348
|
+
try builder.fillRect(.{
|
|
1349
|
+
.id = widgetPartId(widget.id, 1),
|
|
1350
|
+
.rect = pixelSnapGeometryRect(tokens, frame),
|
|
1351
|
+
.fill = colorFill(widgetBackgroundColor(widget, tokens.colors.surface)),
|
|
1352
|
+
});
|
|
1353
|
+
|
|
1354
|
+
const separator_height = @max(tokens.stroke.hairline, widget.style.stroke_width orelse tokens.stroke.hairline);
|
|
1355
|
+
try builder.fillRect(.{
|
|
1356
|
+
.id = widgetPartId(widget.id, 2),
|
|
1357
|
+
.rect = pixelSnapGeometryRect(tokens, geometry.RectF.init(frame.x, frame.y, frame.width, separator_height)),
|
|
1358
|
+
.fill = widgetBorderFill(widget, tokens.colors.border),
|
|
1359
|
+
});
|
|
1360
|
+
|
|
1361
|
+
if (widget.text.len == 0) return;
|
|
1362
|
+
|
|
1363
|
+
const text_size = widgetBodyTextSize(widget, tokens);
|
|
1364
|
+
const padding = widgetStatusBarPadding(widget);
|
|
1365
|
+
const content = frame.inset(padding).normalized();
|
|
1366
|
+
if (content.isEmpty()) return;
|
|
1367
|
+
const line_height = text_size * 1.25;
|
|
1368
|
+
const text_frame = geometry.RectF.init(
|
|
1369
|
+
content.x,
|
|
1370
|
+
frame.y + @max(0, (frame.height - line_height) * 0.5),
|
|
1371
|
+
content.width,
|
|
1372
|
+
@min(content.height, line_height),
|
|
1373
|
+
);
|
|
1374
|
+
try builder.drawText(.{
|
|
1375
|
+
.id = widgetPartId(widget.id, 3),
|
|
1376
|
+
.font_id = tokens.typography.font_id,
|
|
1377
|
+
.size = text_size,
|
|
1378
|
+
.origin = pixelSnapTextPoint(tokens, textOrigin(text_frame, text_size, 0)),
|
|
1379
|
+
.color = widgetForegroundColor(widget, tokens, tokens.colors.text),
|
|
1380
|
+
.text = widget.text,
|
|
1381
|
+
.text_layout = .{
|
|
1382
|
+
.max_width = text_frame.width,
|
|
1383
|
+
.line_height = line_height,
|
|
1384
|
+
.wrap = .none,
|
|
1385
|
+
.alignment = widget.text_alignment,
|
|
1386
|
+
.overflow = widget.text_overflow,
|
|
1387
|
+
.measure = tokens.text_measure,
|
|
1388
|
+
},
|
|
1389
|
+
});
|
|
1390
|
+
}
|
|
1391
|
+
|
|
1392
|
+
pub fn widgetStatusBarPadding(widget: Widget) geometry.InsetsF {
|
|
1393
|
+
const padding = widget.layout.padding;
|
|
1394
|
+
if (padding.top == 0 and padding.right == 0 and padding.bottom == 0 and padding.left == 0) {
|
|
1395
|
+
return geometry.InsetsF.symmetric(7, 14);
|
|
1396
|
+
}
|
|
1397
|
+
return padding;
|
|
1398
|
+
}
|
|
1399
|
+
|
|
1400
|
+
/// The command id of a skeleton's placeholder fill — the target of the
|
|
1401
|
+
/// runtime's looping pulse animation, published so the animation and
|
|
1402
|
+
/// the emitter can never drift apart.
|
|
1403
|
+
pub fn skeletonWidgetFillCommandId(id: ObjectId) ObjectId {
|
|
1404
|
+
return widgetPartId(id, 1);
|
|
1405
|
+
}
|
|
1406
|
+
|
|
1407
|
+
fn emitSkeletonWidget(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!void {
|
|
1408
|
+
const visual = componentControlVisualTokens(widget, tokens);
|
|
1409
|
+
try builder.fillRoundedRect(.{
|
|
1410
|
+
.id = widgetPartId(widget.id, 1),
|
|
1411
|
+
.rect = widget.frame,
|
|
1412
|
+
.radius = controlRadius(widget, visual, tokens.radius.md),
|
|
1413
|
+
.fill = colorFill(widgetBackgroundColor(widget, visual.background orelse tokens.colors.surface_subtle)),
|
|
1414
|
+
});
|
|
1415
|
+
}
|
|
1416
|
+
|
|
1417
|
+
/// A row's own state wash: hover and selection paint the FULL row band
|
|
1418
|
+
/// edge to edge (the table register's row hover), square-cornered so
|
|
1419
|
+
/// adjacent rows tile. Rows at rest draw nothing.
|
|
1420
|
+
fn emitDataRowWidgetWash(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!void {
|
|
1421
|
+
const fill = widget_render_style.listItemFillColor(widget, tokens, widget.state);
|
|
1422
|
+
if (fill.a <= 0) return;
|
|
1423
|
+
try builder.fillRect(.{
|
|
1424
|
+
.id = widgetPartId(widget.id, 1),
|
|
1425
|
+
.rect = widget.frame,
|
|
1426
|
+
.fill = colorFill(fill),
|
|
1427
|
+
});
|
|
1428
|
+
}
|
|
1429
|
+
|
|
1430
|
+
/// The table's chrome: a hairline separator under every row but the
|
|
1431
|
+
/// last — never an outer box, never per-cell gridlines. The separator
|
|
1432
|
+
/// is a part of the ROW above it (stable command id per row), drawn by
|
|
1433
|
+
/// the table so the last row can stay open-edged.
|
|
1434
|
+
fn emitTableRowSeparators(builder: *Builder, children: []const Widget, tokens: DesignTokens) Error!void {
|
|
1435
|
+
var last_row_index: ?usize = null;
|
|
1436
|
+
for (children, 0..) |child, index| {
|
|
1437
|
+
if (child.kind == .data_row and !child.semantics.hidden) last_row_index = index;
|
|
1438
|
+
}
|
|
1439
|
+
for (children, 0..) |child, index| {
|
|
1440
|
+
if (child.kind != .data_row or child.semantics.hidden) continue;
|
|
1441
|
+
if (last_row_index != null and index == last_row_index.?) continue;
|
|
1442
|
+
try emitTableRowSeparatorLine(builder, child.id, child.frame, tokens);
|
|
1443
|
+
}
|
|
1444
|
+
}
|
|
1445
|
+
|
|
1446
|
+
fn emitTableRowSeparatorsLayout(builder: *Builder, layout: anytype, table_index: usize, tokens: DesignTokens, table: Widget, clip_to_table: bool) Error!void {
|
|
1447
|
+
if (clip_to_table) try builder.pushClip(.{ .id = widgetPartId(table.id, 9), .rect = table.frame });
|
|
1448
|
+
var last_row_index: ?usize = null;
|
|
1449
|
+
for (layout.nodes, 0..) |node, index| {
|
|
1450
|
+
if (node.parent_index != table_index) continue;
|
|
1451
|
+
if (node.widget.kind == .data_row and !node.widget.semantics.hidden) last_row_index = index;
|
|
1452
|
+
}
|
|
1453
|
+
for (layout.nodes, 0..) |node, index| {
|
|
1454
|
+
if (node.parent_index != table_index) continue;
|
|
1455
|
+
if (node.widget.kind != .data_row or node.widget.semantics.hidden) continue;
|
|
1456
|
+
if (last_row_index != null and index == last_row_index.?) continue;
|
|
1457
|
+
try emitTableRowSeparatorLine(builder, node.widget.id, node.frame, tokens);
|
|
1458
|
+
}
|
|
1459
|
+
if (clip_to_table) try builder.popClip();
|
|
1460
|
+
}
|
|
1461
|
+
|
|
1462
|
+
fn emitTableRowSeparatorLine(builder: *Builder, row_id: ObjectId, row_frame: geometry.RectF, tokens: DesignTokens) Error!void {
|
|
1463
|
+
const frame = row_frame.normalized();
|
|
1464
|
+
if (frame.isEmpty()) return;
|
|
1465
|
+
const y = frame.maxY();
|
|
1466
|
+
try builder.drawLine(.{
|
|
1467
|
+
.id = widgetPartId(row_id, 2),
|
|
1468
|
+
.from = pixelSnapGeometryPoint(tokens, geometry.PointF.init(frame.x, y)),
|
|
1469
|
+
.to = pixelSnapGeometryPoint(tokens, geometry.PointF.init(frame.maxX(), y)),
|
|
1470
|
+
.stroke = .{
|
|
1471
|
+
.fill = colorFill(tokens.colors.border),
|
|
1472
|
+
.width = tokens.stroke.hairline,
|
|
1473
|
+
},
|
|
1474
|
+
});
|
|
1475
|
+
}
|
|
1476
|
+
|
|
1477
|
+
/// Sweep of the arc register's stroked segment, in degrees: the box
|
|
1478
|
+
/// leaves a 72-degree mouth open, so the shape reads as a broken ring
|
|
1479
|
+
/// even when a static render freezes it.
|
|
1480
|
+
const spinner_arc_sweep_degrees: f32 = 288;
|
|
1481
|
+
/// Arc centerline radius as a fraction of the box extent — the icon
|
|
1482
|
+
/// register's inset circle (a radius-9 circle in a 24 box), so the
|
|
1483
|
+
/// glyph breathes inside its frame instead of bleeding to the edge.
|
|
1484
|
+
const spinner_arc_radius_ratio: f32 = 9.0 / 24.0;
|
|
1485
|
+
/// Arc stroke as a fraction of the box extent (a 2-unit stroke in the
|
|
1486
|
+
/// 24 box): the stroke scales with the size rung, before per-widget and
|
|
1487
|
+
/// theme overrides.
|
|
1488
|
+
const spinner_arc_stroke_ratio: f32 = 2.0 / 24.0;
|
|
1489
|
+
|
|
1490
|
+
/// Draw a `.spinner` widget. Emission is deterministic: the pose is a
|
|
1491
|
+
/// pure function of `widget.value` (fractions of a cycle from twelve
|
|
1492
|
+
/// o'clock), so static renders — docs previews, screenshots — pose it
|
|
1493
|
+
/// reproducibly. The LIVE motion is not emitted here; the runtime arms
|
|
1494
|
+
/// looping render animations on the emitted command ids instead of
|
|
1495
|
+
/// re-emitting the display list. Two structural registers, chosen by
|
|
1496
|
+
/// `metrics.spinner_style` (structure is a pack signature — see the
|
|
1497
|
+
/// token's comment — so the emitter never asks which pack is active):
|
|
1498
|
+
///
|
|
1499
|
+
/// - `.arc`: one stroked 288-degree arc in the widget's ink, no track;
|
|
1500
|
+
/// the runtime spins it about `spinnerWidgetRotationCenter` via a
|
|
1501
|
+
/// `.wrap` rotation on `spinnerWidgetArcCommandId`.
|
|
1502
|
+
/// - `.segmented`: a dial of radial pill segments at fixed angles, one
|
|
1503
|
+
/// `fillPath` per segment (`spinnerWidgetSegmentCommandId`) so the
|
|
1504
|
+
/// runtime can stagger a `.wrap` opacity loop per segment — the
|
|
1505
|
+
/// bright head steps around the dial while each pill fades in place.
|
|
1506
|
+
/// Animated frames emit every pill at full ink (the OVERRIDE channel
|
|
1507
|
+
/// multiplies emitted alpha, so a baked fade would double-darken);
|
|
1508
|
+
/// under reduced motion no loop ever arms, so the fade IS baked and
|
|
1509
|
+
/// the static pose shows the head-to-tail trail.
|
|
1510
|
+
fn emitSpinnerWidget(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!void {
|
|
1511
|
+
const visual = componentControlVisualTokens(widget, tokens);
|
|
1512
|
+
const normalized = widget.frame.normalized();
|
|
1513
|
+
if (normalized.isEmpty()) return;
|
|
1514
|
+
const size = @min(normalized.width, normalized.height);
|
|
1515
|
+
if (size <= 0) return;
|
|
1516
|
+
const center = geometry.PointF.init(normalized.x + normalized.width * 0.5, normalized.y + normalized.height * 0.5);
|
|
1517
|
+
const ink = widgetForegroundColor(widget, tokens, visual.foreground orelse tokens.colors.text);
|
|
1518
|
+
|
|
1519
|
+
switch (tokens.metrics.spinner_style) {
|
|
1520
|
+
.arc => try emitSpinnerArc(builder, widget, visual, center, size, ink),
|
|
1521
|
+
.segmented => try emitSpinnerSegments(builder, widget, tokens, center, size, ink),
|
|
1522
|
+
}
|
|
1523
|
+
}
|
|
1524
|
+
|
|
1525
|
+
/// The arc register: a single stroked arc whose start angle carries the
|
|
1526
|
+
/// deterministic pose. Split into <=90-degree cubic segments (the
|
|
1527
|
+
/// circle-from-cubics constant generalized per segment angle), accurate
|
|
1528
|
+
/// to sub-pixel error at control sizes.
|
|
1529
|
+
fn emitSpinnerArc(builder: *Builder, widget: Widget, visual: ControlVisualTokens, center: geometry.PointF, size: f32, ink: Color) Error!void {
|
|
1530
|
+
const stroke_width = controlStrokeWidth(widget, visual, size * spinner_arc_stroke_ratio);
|
|
1531
|
+
const radius = size * spinner_arc_radius_ratio;
|
|
1532
|
+
if (radius <= 0) return;
|
|
1533
|
+
|
|
1534
|
+
const start_degrees = -90 + std.math.clamp(widget.value, 0, 1) * 360;
|
|
1535
|
+
const segment_total: usize = @intFromFloat(@ceil(spinner_arc_sweep_degrees / 90.0));
|
|
1536
|
+
const delta_degrees = spinner_arc_sweep_degrees / @as(f32, @floatFromInt(segment_total));
|
|
1537
|
+
const kappa = (4.0 / 3.0) * @tan(std.math.degreesToRadians(delta_degrees) * 0.25) * radius;
|
|
1538
|
+
|
|
1539
|
+
const elements = try allocFramePathElements(1 + segment_total);
|
|
1540
|
+
const start_radians = std.math.degreesToRadians(start_degrees);
|
|
1541
|
+
elements[0] = .{ .verb = .move_to, .points = .{
|
|
1542
|
+
geometry.PointF.init(center.x + radius * @cos(start_radians), center.y + radius * @sin(start_radians)),
|
|
1543
|
+
geometry.PointF.zero(),
|
|
1544
|
+
geometry.PointF.zero(),
|
|
1545
|
+
} };
|
|
1546
|
+
for (0..segment_total) |segment| {
|
|
1547
|
+
const a0 = std.math.degreesToRadians(start_degrees + delta_degrees * @as(f32, @floatFromInt(segment)));
|
|
1548
|
+
const a1 = std.math.degreesToRadians(start_degrees + delta_degrees * @as(f32, @floatFromInt(segment + 1)));
|
|
1549
|
+
const from = geometry.PointF.init(center.x + radius * @cos(a0), center.y + radius * @sin(a0));
|
|
1550
|
+
const to = geometry.PointF.init(center.x + radius * @cos(a1), center.y + radius * @sin(a1));
|
|
1551
|
+
elements[1 + segment] = .{ .verb = .cubic_to, .points = .{
|
|
1552
|
+
geometry.PointF.init(from.x - kappa * @sin(a0), from.y + kappa * @cos(a0)),
|
|
1553
|
+
geometry.PointF.init(to.x + kappa * @sin(a1), to.y - kappa * @cos(a1)),
|
|
1554
|
+
to,
|
|
1555
|
+
} };
|
|
1556
|
+
}
|
|
1557
|
+
try builder.strokePath(.{
|
|
1558
|
+
.id = spinnerWidgetArcCommandId(widget.id),
|
|
1559
|
+
.elements = elements,
|
|
1560
|
+
.stroke = .{
|
|
1561
|
+
.fill = colorFill(ink),
|
|
1562
|
+
.width = stroke_width,
|
|
1563
|
+
},
|
|
1564
|
+
// The measured reference arc ends in semicircles, not squared-off
|
|
1565
|
+
// butt ends: the register reads as a drawn stroke chasing its
|
|
1566
|
+
// tail, so the caps are part of the shape, not a rasterizer
|
|
1567
|
+
// default.
|
|
1568
|
+
.cap = .round,
|
|
1569
|
+
});
|
|
1570
|
+
}
|
|
1571
|
+
|
|
1572
|
+
/// The segmented register: `n` pill segments pointing outward at fixed
|
|
1573
|
+
/// angles, segment 0 at twelve o'clock and the rest stepping clockwise.
|
|
1574
|
+
/// Each pill is a filled stadium path (two straight edges, two
|
|
1575
|
+
/// two-cubic semicircle caps) so it stays a pill at any angle —
|
|
1576
|
+
/// rounded-rect commands are axis-aligned and cannot rotate.
|
|
1577
|
+
fn emitSpinnerSegments(builder: *Builder, widget: Widget, tokens: DesignTokens, center: geometry.PointF, size: f32, ink: Color) Error!void {
|
|
1578
|
+
const count = spinnerWidgetSegmentCount(tokens);
|
|
1579
|
+
const length = size * @max(0, tokens.metrics.spinner_segment_length_ratio);
|
|
1580
|
+
const thickness = size * @max(0, tokens.metrics.spinner_segment_thickness_ratio);
|
|
1581
|
+
const orbit = size * @max(0, tokens.metrics.spinner_segment_radius_ratio);
|
|
1582
|
+
if (length <= 0 or thickness <= 0) return;
|
|
1583
|
+
const tail = std.math.clamp(tokens.metrics.spinner_tail_opacity, 0, 1);
|
|
1584
|
+
// Reduced motion is the one world where the runtime never arms the
|
|
1585
|
+
// per-segment opacity loops, so the trail must be baked into the
|
|
1586
|
+
// emitted inks for the register to read as an indicator at all.
|
|
1587
|
+
// Animated worlds bake nothing: overrides MULTIPLY emitted alpha,
|
|
1588
|
+
// and a baked trail under an animated trail would double-darken.
|
|
1589
|
+
const reduce_motion = tokens.motion.durationMs(.slow) == 0;
|
|
1590
|
+
const value = std.math.clamp(widget.value, 0, 1);
|
|
1591
|
+
|
|
1592
|
+
const cap = thickness * 0.5;
|
|
1593
|
+
const half = @max(length * 0.5 - cap, 0);
|
|
1594
|
+
const cap_kappa: f32 = 0.5522847498 * cap;
|
|
1595
|
+
for (0..count) |segment| {
|
|
1596
|
+
const angle = std.math.degreesToRadians(-90 + 360 * @as(f32, @floatFromInt(segment)) / @as(f32, @floatFromInt(count)));
|
|
1597
|
+
// Radial and tangential unit vectors: pills point outward along
|
|
1598
|
+
// `u`, caps bulge along `u`, straight edges run offset by `v`.
|
|
1599
|
+
const u = geometry.PointF.init(@cos(angle), @sin(angle));
|
|
1600
|
+
const v = geometry.PointF.init(-@sin(angle), @cos(angle));
|
|
1601
|
+
const pill_center = geometry.PointF.init(center.x + orbit * u.x, center.y + orbit * u.y);
|
|
1602
|
+
const inner = geometry.PointF.init(pill_center.x - half * u.x, pill_center.y - half * u.y);
|
|
1603
|
+
const outer = geometry.PointF.init(pill_center.x + half * u.x, pill_center.y + half * u.y);
|
|
1604
|
+
|
|
1605
|
+
var opacity: f32 = 1;
|
|
1606
|
+
if (reduce_motion) {
|
|
1607
|
+
// The frozen pose: the head sits `value` turns past twelve
|
|
1608
|
+
// o'clock, and each step CLOCKWISE ahead of it is one cycle
|
|
1609
|
+
// fraction older — the same linear head-to-tail ramp the
|
|
1610
|
+
// staggered loops trace live.
|
|
1611
|
+
var distance = @as(f32, @floatFromInt(segment)) / @as(f32, @floatFromInt(count)) - value;
|
|
1612
|
+
distance -= @floor(distance);
|
|
1613
|
+
var age = 1 - distance;
|
|
1614
|
+
if (age >= 1) age = 0;
|
|
1615
|
+
opacity = 1 - (1 - tail) * age;
|
|
1616
|
+
}
|
|
1617
|
+
|
|
1618
|
+
const a = geometry.PointF.init(inner.x + cap * v.x, inner.y + cap * v.y);
|
|
1619
|
+
const b = geometry.PointF.init(outer.x + cap * v.x, outer.y + cap * v.y);
|
|
1620
|
+
const outer_mid = geometry.PointF.init(outer.x + cap * u.x, outer.y + cap * u.y);
|
|
1621
|
+
const e = geometry.PointF.init(outer.x - cap * v.x, outer.y - cap * v.y);
|
|
1622
|
+
const f = geometry.PointF.init(inner.x - cap * v.x, inner.y - cap * v.y);
|
|
1623
|
+
const inner_mid = geometry.PointF.init(inner.x - cap * u.x, inner.y - cap * u.y);
|
|
1624
|
+
|
|
1625
|
+
const elements = try allocFramePathElements(8);
|
|
1626
|
+
elements[0] = .{ .verb = .move_to, .points = .{ a, geometry.PointF.zero(), geometry.PointF.zero() } };
|
|
1627
|
+
elements[1] = .{ .verb = .line_to, .points = .{ b, geometry.PointF.zero(), geometry.PointF.zero() } };
|
|
1628
|
+
elements[2] = .{ .verb = .cubic_to, .points = .{
|
|
1629
|
+
geometry.PointF.init(b.x + cap_kappa * u.x, b.y + cap_kappa * u.y),
|
|
1630
|
+
geometry.PointF.init(outer_mid.x + cap_kappa * v.x, outer_mid.y + cap_kappa * v.y),
|
|
1631
|
+
outer_mid,
|
|
1632
|
+
} };
|
|
1633
|
+
elements[3] = .{ .verb = .cubic_to, .points = .{
|
|
1634
|
+
geometry.PointF.init(outer_mid.x - cap_kappa * v.x, outer_mid.y - cap_kappa * v.y),
|
|
1635
|
+
geometry.PointF.init(e.x + cap_kappa * u.x, e.y + cap_kappa * u.y),
|
|
1636
|
+
e,
|
|
1637
|
+
} };
|
|
1638
|
+
elements[4] = .{ .verb = .line_to, .points = .{ f, geometry.PointF.zero(), geometry.PointF.zero() } };
|
|
1639
|
+
elements[5] = .{ .verb = .cubic_to, .points = .{
|
|
1640
|
+
geometry.PointF.init(f.x - cap_kappa * u.x, f.y - cap_kappa * u.y),
|
|
1641
|
+
geometry.PointF.init(inner_mid.x - cap_kappa * v.x, inner_mid.y - cap_kappa * v.y),
|
|
1642
|
+
inner_mid,
|
|
1643
|
+
} };
|
|
1644
|
+
elements[6] = .{ .verb = .cubic_to, .points = .{
|
|
1645
|
+
geometry.PointF.init(inner_mid.x + cap_kappa * v.x, inner_mid.y + cap_kappa * v.y),
|
|
1646
|
+
geometry.PointF.init(a.x - cap_kappa * u.x, a.y - cap_kappa * u.y),
|
|
1647
|
+
a,
|
|
1648
|
+
} };
|
|
1649
|
+
elements[7] = .{ .verb = .close };
|
|
1650
|
+
try builder.fillPath(.{
|
|
1651
|
+
.id = spinnerWidgetSegmentCommandId(widget.id, segment),
|
|
1652
|
+
.elements = elements,
|
|
1653
|
+
.fill = colorFill(colorWithAlpha(ink, ink.a * opacity)),
|
|
1654
|
+
});
|
|
1655
|
+
}
|
|
1656
|
+
}
|
|
1657
|
+
|
|
1658
|
+
/// The command id of a spinner's accent arc segment — the part slot
|
|
1659
|
+
/// `emitSpinnerWidget` draws it under — so the runtime can target the
|
|
1660
|
+
/// arc with a looping rotation render animation.
|
|
1661
|
+
pub fn spinnerWidgetArcCommandId(id: ObjectId) ObjectId {
|
|
1662
|
+
return widgetPartId(id, 2);
|
|
1663
|
+
}
|
|
1664
|
+
|
|
1665
|
+
/// The point the spinner's rotation animation must spin about: the
|
|
1666
|
+
/// center of the PAINTED frame (pixel-snapped exactly like emission),
|
|
1667
|
+
/// so the sampled rotation never wobbles against the emitted geometry.
|
|
1668
|
+
pub fn spinnerWidgetRotationCenter(widget: Widget, tokens: DesignTokens) geometry.PointF {
|
|
1669
|
+
const normalized = pixelSnapGeometryRect(tokens, widget.frame).normalized();
|
|
1670
|
+
return geometry.PointF.init(normalized.x + normalized.width * 0.5, normalized.y + normalized.height * 0.5);
|
|
1671
|
+
}
|
|
1672
|
+
|
|
1673
|
+
/// The command id of segment `index` of a segmented-register spinner —
|
|
1674
|
+
/// the part slot `emitSpinnerSegments` fills it under — so the runtime
|
|
1675
|
+
/// can stagger a looping opacity animation per segment.
|
|
1676
|
+
pub fn spinnerWidgetSegmentCommandId(id: ObjectId, index: usize) ObjectId {
|
|
1677
|
+
return widgetPartId(id, @intCast(1 + index));
|
|
1678
|
+
}
|
|
1679
|
+
|
|
1680
|
+
/// How many segments a segmented-register spinner draws: the token
|
|
1681
|
+
/// count clamped to the widget part-id space (16 slots per widget, one
|
|
1682
|
+
/// reserved so slot arithmetic never rolls into the next widget's id
|
|
1683
|
+
/// range). Emitter and runtime both resolve the count through here, so
|
|
1684
|
+
/// the armed opacity loops always match the emitted commands one-to-one.
|
|
1685
|
+
pub fn spinnerWidgetSegmentCount(tokens: DesignTokens) usize {
|
|
1686
|
+
return @intCast(std.math.clamp(tokens.metrics.spinner_segment_count, 3, 15));
|
|
1687
|
+
}
|
|
1688
|
+
|
|
1689
|
+
// ------------------------------------------------------------------ chart
|
|
1690
|
+
|
|
1691
|
+
/// Draw a `.chart` widget: token-hairline gridlines and baseline first,
|
|
1692
|
+
/// then opt-in axis tick labels in the muted text register, then each
|
|
1693
|
+
/// series oldest-to-newest through the vector path pipeline — lines as
|
|
1694
|
+
/// one `strokePath` (plus an optional translucent baseline-fill
|
|
1695
|
+
/// `fillPath`), bands as one closed envelope `fillPath`, bars as one
|
|
1696
|
+
/// pixel-snapped `fillRoundedRect` per value. Series colors resolve from
|
|
1697
|
+
/// design tokens at emit time, so charts retheme with the palette.
|
|
1698
|
+
/// Deterministic by construction: geometry is a pure function of the
|
|
1699
|
+
/// series, the domain, and the frame; axis labels reserve gutters
|
|
1700
|
+
/// (`chartWidgetPlotRect`) only when opted in, so unlabeled charts
|
|
1701
|
+
/// render byte-identically to before.
|
|
1702
|
+
fn emitChartWidget(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!void {
|
|
1703
|
+
const data = widget.chart;
|
|
1704
|
+
const plot = chartWidgetPlotRect(widget, tokens);
|
|
1705
|
+
if (plot.isEmpty() or plot.width <= 0 or plot.height <= 0) return;
|
|
1706
|
+
const domain = chart_model.chartDomain(data);
|
|
1707
|
+
|
|
1708
|
+
const hairline = @max(1, tokens.stroke.hairline);
|
|
1709
|
+
if (data.grid_lines > 0 and data.y_labels) {
|
|
1710
|
+
// A LABELED chart's gridlines ride the nice tick lattice (the
|
|
1711
|
+
// labels are exact at those values, so grid and text can never
|
|
1712
|
+
// disagree); `grid_lines` becomes the density hint. Interior
|
|
1713
|
+
// ticks only — the plot edges and the baseline carry the ends.
|
|
1714
|
+
const lattice = chart_model.chartTickLattice(domain, @as(usize, data.grid_lines) + 1);
|
|
1715
|
+
for (0..lattice.count) |index| {
|
|
1716
|
+
const value = lattice.value(index);
|
|
1717
|
+
if (value <= domain.min or value >= domain.max) continue;
|
|
1718
|
+
const y = chartMapY(value, domain, plot, 0);
|
|
1719
|
+
try builder.fillRect(.{
|
|
1720
|
+
.id = chartCommandId(widget.id, chart_grid_seed, 0, index),
|
|
1721
|
+
.rect = pixelSnapGeometryRect(tokens, geometry.RectF.init(plot.x, y - hairline * 0.5, plot.width, hairline)),
|
|
1722
|
+
.fill = colorFill(tokens.colors.border),
|
|
1723
|
+
});
|
|
1724
|
+
}
|
|
1725
|
+
} else if (data.grid_lines > 0) {
|
|
1726
|
+
const divisions: f32 = @floatFromInt(@as(usize, data.grid_lines) + 1);
|
|
1727
|
+
for (0..data.grid_lines) |index| {
|
|
1728
|
+
const y = plot.y + plot.height * @as(f32, @floatFromInt(index + 1)) / divisions;
|
|
1729
|
+
try builder.fillRect(.{
|
|
1730
|
+
.id = chartCommandId(widget.id, chart_grid_seed, 0, index),
|
|
1731
|
+
.rect = pixelSnapGeometryRect(tokens, geometry.RectF.init(plot.x, y - hairline * 0.5, plot.width, hairline)),
|
|
1732
|
+
.fill = colorFill(tokens.colors.border),
|
|
1733
|
+
});
|
|
1734
|
+
}
|
|
1735
|
+
}
|
|
1736
|
+
if (data.baseline) {
|
|
1737
|
+
const y = chartMapY(chartBaselineValue(domain), domain, plot, 0);
|
|
1738
|
+
try builder.fillRect(.{
|
|
1739
|
+
.id = chartCommandId(widget.id, chart_baseline_seed, 0, 0),
|
|
1740
|
+
.rect = pixelSnapGeometryRect(tokens, geometry.RectF.init(plot.x, y - hairline * 0.5, plot.width, hairline)),
|
|
1741
|
+
.fill = colorFill(tokens.colors.border),
|
|
1742
|
+
});
|
|
1743
|
+
}
|
|
1744
|
+
try emitChartAxisLabels(builder, widget, tokens, plot, domain);
|
|
1745
|
+
|
|
1746
|
+
for (data.series, 0..) |series, series_index| {
|
|
1747
|
+
if (series.values.len == 0) continue;
|
|
1748
|
+
const color = text_spans_model.textSpanColorValue(tokens.colors, series.color);
|
|
1749
|
+
switch (series.kind) {
|
|
1750
|
+
.bar => try emitChartBars(builder, widget, tokens, plot, domain, series, series_index, color),
|
|
1751
|
+
.line => try emitChartLine(builder, widget, plot, domain, series, series_index, color),
|
|
1752
|
+
.band => try emitChartBand(builder, widget, plot, domain, series, series_index, color),
|
|
1753
|
+
}
|
|
1754
|
+
}
|
|
1755
|
+
}
|
|
1756
|
+
|
|
1757
|
+
// ------------------------------------------------------ chart axis labels
|
|
1758
|
+
|
|
1759
|
+
/// Tick-label type size: two rungs under the label register (13 -> 11
|
|
1760
|
+
/// with house tokens), floored at 9 so dense themes stay legible. Axis
|
|
1761
|
+
/// text is secondary chrome — it must never outweigh the data ink.
|
|
1762
|
+
fn chartTickTextSize(tokens: DesignTokens) f32 {
|
|
1763
|
+
return @max(9, tokens.typography.label_size - 2);
|
|
1764
|
+
}
|
|
1765
|
+
|
|
1766
|
+
/// Gap between the plot edge and its tick labels (the reference-grade
|
|
1767
|
+
/// breathing room that keeps labels from touching the data ink).
|
|
1768
|
+
const chart_axis_label_gap: f32 = 6;
|
|
1769
|
+
/// Minimum clear space between adjacent x labels before thinning kicks
|
|
1770
|
+
/// in (every Nth label draws).
|
|
1771
|
+
const chart_x_label_min_gap: f32 = 12;
|
|
1772
|
+
|
|
1773
|
+
/// The rect the data plots into: the padded frame minus the gutters the
|
|
1774
|
+
/// opted-in axis labels reserve (a line below for x labels, a measured
|
|
1775
|
+
/// column at the left for y labels). Pure over the widget and tokens —
|
|
1776
|
+
/// the runtime's hover hit logic and the renderer share it, so the
|
|
1777
|
+
/// cursor snaps exactly where the ink is. Without labels this is the
|
|
1778
|
+
/// padded frame, byte-identical to the pre-label contract.
|
|
1779
|
+
pub fn chartWidgetPlotRect(widget: Widget, tokens: DesignTokens) geometry.RectF {
|
|
1780
|
+
const data = widget.chart;
|
|
1781
|
+
var plot = widget.frame.inset(widget.layout.padding).normalized();
|
|
1782
|
+
if (data.x_labels.len > 0) {
|
|
1783
|
+
const gutter = chartTickTextSize(tokens) * 1.25 + chart_axis_label_gap;
|
|
1784
|
+
plot.height = @max(0, plot.height - gutter);
|
|
1785
|
+
}
|
|
1786
|
+
if (data.y_labels) {
|
|
1787
|
+
const gutter = chartYLabelGutterWidth(data, tokens);
|
|
1788
|
+
plot.x += gutter;
|
|
1789
|
+
plot.width = @max(0, plot.width - gutter);
|
|
1790
|
+
}
|
|
1791
|
+
return plot;
|
|
1792
|
+
}
|
|
1793
|
+
|
|
1794
|
+
/// The y tick lattice a labeled chart rides: the nice-step lattice
|
|
1795
|
+
/// (values exact at their precision), density-hinted by `grid_lines`
|
|
1796
|
+
/// so labels and gridlines share positions.
|
|
1797
|
+
fn chartYTickLattice(data: chart_model.ChartData, domain: chart_model.ChartDomain) chart_model.ChartTickLattice {
|
|
1798
|
+
return chart_model.chartTickLattice(domain, @as(usize, data.grid_lines) + 1);
|
|
1799
|
+
}
|
|
1800
|
+
|
|
1801
|
+
/// Width of the y-label gutter: the widest formatted tick plus the
|
|
1802
|
+
/// axis gap, measured through the same seam drawn text uses so the
|
|
1803
|
+
/// reserved column always fits the ink.
|
|
1804
|
+
fn chartYLabelGutterWidth(data: chart_model.ChartData, tokens: DesignTokens) f32 {
|
|
1805
|
+
const domain = chart_model.chartDomain(data);
|
|
1806
|
+
const lattice = chartYTickLattice(data, domain);
|
|
1807
|
+
const size = chartTickTextSize(tokens);
|
|
1808
|
+
var widest: f32 = 0;
|
|
1809
|
+
var buffer: [chart_model.max_chart_value_label_bytes]u8 = undefined;
|
|
1810
|
+
for (0..lattice.count) |ordinal| {
|
|
1811
|
+
const text = chart_model.formatChartValue(&buffer, lattice.value(ordinal), lattice.decimals);
|
|
1812
|
+
widest = @max(widest, measureTextWidthForFont(tokens.text_measure, tokens.typography.font_id, text, size));
|
|
1813
|
+
}
|
|
1814
|
+
return @ceil(widest) + chart_axis_label_gap;
|
|
1815
|
+
}
|
|
1816
|
+
|
|
1817
|
+
/// Emit the opted-in tick labels: y values right-aligned into the left
|
|
1818
|
+
/// gutter (each vertically centered on its lattice line, clamped inside
|
|
1819
|
+
/// the padded frame so edge labels never ink outside the widget), and x
|
|
1820
|
+
/// category labels centered under their sample columns, deterministically
|
|
1821
|
+
/// thinned to every Nth so they never collide. Muted register — labels
|
|
1822
|
+
/// are chrome, not data.
|
|
1823
|
+
fn emitChartAxisLabels(builder: *Builder, widget: Widget, tokens: DesignTokens, plot: geometry.RectF, domain: chart_model.ChartDomain) Error!void {
|
|
1824
|
+
const data = widget.chart;
|
|
1825
|
+
const size = chartTickTextSize(tokens);
|
|
1826
|
+
const line_height = size * 1.25;
|
|
1827
|
+
const content = widget.frame.inset(widget.layout.padding).normalized();
|
|
1828
|
+
|
|
1829
|
+
if (data.y_labels) {
|
|
1830
|
+
const lattice = chartYTickLattice(data, domain);
|
|
1831
|
+
var buffer: [chart_model.max_chart_value_label_bytes]u8 = undefined;
|
|
1832
|
+
for (0..lattice.count) |ordinal| {
|
|
1833
|
+
const value = lattice.value(ordinal);
|
|
1834
|
+
const formatted = chart_model.formatChartValue(&buffer, value, lattice.decimals);
|
|
1835
|
+
const text = try allocFrameLabelBytes(formatted);
|
|
1836
|
+
const width = measureTextWidthForFont(tokens.text_measure, tokens.typography.font_id, text, size);
|
|
1837
|
+
const line_y = chartMapY(value, domain, plot, 0);
|
|
1838
|
+
const top = std.math.clamp(line_y - line_height * 0.5, content.y, @max(content.y, content.maxY() - line_height));
|
|
1839
|
+
try builder.drawText(.{
|
|
1840
|
+
.id = chartCommandId(widget.id, chart_tick_seed, 0, ordinal),
|
|
1841
|
+
.font_id = tokens.typography.font_id,
|
|
1842
|
+
.size = size,
|
|
1843
|
+
.origin = pixelSnapTextPoint(tokens, geometry.PointF.init(plot.x - chart_axis_label_gap - width, top + size)),
|
|
1844
|
+
.color = tokens.colors.text_muted,
|
|
1845
|
+
.text = text,
|
|
1846
|
+
});
|
|
1847
|
+
}
|
|
1848
|
+
}
|
|
1849
|
+
|
|
1850
|
+
if (data.x_labels.len > 0) {
|
|
1851
|
+
const count = @max(chart_model.chartPointCount(data), data.x_labels.len);
|
|
1852
|
+
// Thinning: the widest label plus the minimum gap defines the
|
|
1853
|
+
// space one label needs; every Nth label draws so neighbors
|
|
1854
|
+
// never touch. Pure over the labels and the plot width.
|
|
1855
|
+
var widest: f32 = 0;
|
|
1856
|
+
for (data.x_labels) |label| {
|
|
1857
|
+
widest = @max(widest, measureTextWidthForFont(tokens.text_measure, tokens.typography.font_id, label, size));
|
|
1858
|
+
}
|
|
1859
|
+
const spacing = @max(1, widest + chart_x_label_min_gap);
|
|
1860
|
+
const fit: usize = @max(1, @as(usize, @intFromFloat(plot.width / spacing)));
|
|
1861
|
+
const stride = (data.x_labels.len + fit - 1) / fit;
|
|
1862
|
+
const baseline = @min(plot.maxY() + chart_axis_label_gap + size, content.maxY());
|
|
1863
|
+
var ordinal: usize = 0;
|
|
1864
|
+
while (ordinal < data.x_labels.len) : (ordinal += @max(1, stride)) {
|
|
1865
|
+
const label = data.x_labels[ordinal];
|
|
1866
|
+
if (label.len == 0) continue;
|
|
1867
|
+
const width = measureTextWidthForFont(tokens.text_measure, tokens.typography.font_id, label, size);
|
|
1868
|
+
const center_x = chartSampleX(data, count, ordinal, plot);
|
|
1869
|
+
const x = std.math.clamp(center_x - width * 0.5, content.x, @max(content.x, content.maxX() - width));
|
|
1870
|
+
try builder.drawText(.{
|
|
1871
|
+
.id = chartCommandId(widget.id, chart_tick_seed, 1, ordinal),
|
|
1872
|
+
.font_id = tokens.typography.font_id,
|
|
1873
|
+
.size = size,
|
|
1874
|
+
.origin = pixelSnapTextPoint(tokens, geometry.PointF.init(x, baseline)),
|
|
1875
|
+
.color = tokens.colors.text_muted,
|
|
1876
|
+
.text = label,
|
|
1877
|
+
});
|
|
1878
|
+
}
|
|
1879
|
+
}
|
|
1880
|
+
}
|
|
1881
|
+
|
|
1882
|
+
/// The x a sample index renders at: bars-only charts center samples in
|
|
1883
|
+
/// equal-width slots, everything else sits on the point lattice — the
|
|
1884
|
+
/// same split `chartHoverIndex` inverts, so labels, cursor, and dots
|
|
1885
|
+
/// all agree on where a sample lives.
|
|
1886
|
+
fn chartSampleX(data: chart_model.ChartData, count: usize, index: usize, plot: geometry.RectF) f32 {
|
|
1887
|
+
var bars_only = true;
|
|
1888
|
+
for (data.series) |series| {
|
|
1889
|
+
if (series.values.len > 0 and series.kind != .bar) bars_only = false;
|
|
1890
|
+
}
|
|
1891
|
+
if (bars_only and count > 0) {
|
|
1892
|
+
const slot = plot.width / @as(f32, @floatFromInt(count));
|
|
1893
|
+
return plot.x + slot * (@as(f32, @floatFromInt(index)) + 0.5);
|
|
1894
|
+
}
|
|
1895
|
+
return chartMapX(index, count, plot, 0);
|
|
1896
|
+
}
|
|
1897
|
+
|
|
1898
|
+
/// Where fills and bars anchor: zero when the domain includes it, else
|
|
1899
|
+
/// the nearer domain edge (an all-positive auto domain fills to the plot
|
|
1900
|
+
/// floor, matching what the data shows).
|
|
1901
|
+
fn chartBaselineValue(domain: chart_model.ChartDomain) f32 {
|
|
1902
|
+
return std.math.clamp(0, domain.min, domain.max);
|
|
1903
|
+
}
|
|
1904
|
+
|
|
1905
|
+
/// Map a value into plot-space y, top-down, with an optional symmetric
|
|
1906
|
+
/// vertical inset (line strokes inset by half their width so peak ink
|
|
1907
|
+
/// stays inside the widget frame and its dirty bounds).
|
|
1908
|
+
fn chartMapY(value: f32, domain: chart_model.ChartDomain, plot: geometry.RectF, inset: f32) f32 {
|
|
1909
|
+
const fraction = std.math.clamp((value - domain.min) / domain.span(), 0, 1);
|
|
1910
|
+
const height = @max(0, plot.height - inset * 2);
|
|
1911
|
+
return plot.maxY() - inset - fraction * height;
|
|
1912
|
+
}
|
|
1913
|
+
|
|
1914
|
+
fn chartMapX(index: usize, count: usize, plot: geometry.RectF, inset: f32) f32 {
|
|
1915
|
+
const width = @max(0, plot.width - inset * 2);
|
|
1916
|
+
if (count <= 1) return plot.x + inset + width * 0.5;
|
|
1917
|
+
return plot.x + inset + width * @as(f32, @floatFromInt(index)) / @as(f32, @floatFromInt(count - 1));
|
|
1918
|
+
}
|
|
1919
|
+
|
|
1920
|
+
const chart_stroke_default: f32 = 1.5;
|
|
1921
|
+
const chart_line_fill_alpha: f32 = 0.18;
|
|
1922
|
+
const chart_band_fill_alpha: f32 = 0.25;
|
|
1923
|
+
|
|
1924
|
+
fn chartStrokeWidth(widget: Widget) f32 {
|
|
1925
|
+
const explicit = widget.style.stroke_width orelse chart_stroke_default;
|
|
1926
|
+
return if (std.math.isFinite(explicit) and explicit > 0) explicit else chart_stroke_default;
|
|
1927
|
+
}
|
|
1928
|
+
|
|
1929
|
+
fn emitChartBars(
|
|
1930
|
+
builder: *Builder,
|
|
1931
|
+
widget: Widget,
|
|
1932
|
+
tokens: DesignTokens,
|
|
1933
|
+
plot: geometry.RectF,
|
|
1934
|
+
domain: chart_model.ChartDomain,
|
|
1935
|
+
series: chart_model.ChartSeries,
|
|
1936
|
+
series_index: usize,
|
|
1937
|
+
color: drawing_model.Color,
|
|
1938
|
+
) Error!void {
|
|
1939
|
+
const count = series.values.len;
|
|
1940
|
+
const slot = plot.width / @as(f32, @floatFromInt(count));
|
|
1941
|
+
const gap = if (count > 1) std.math.clamp(slot * 0.25, 0.5, 4) else 0;
|
|
1942
|
+
const bar_width = @max(1, slot - gap);
|
|
1943
|
+
const base_value = chartBaselineValue(domain);
|
|
1944
|
+
const base_y = chartMapY(base_value, domain, plot, 0);
|
|
1945
|
+
for (series.values, 0..) |value, index| {
|
|
1946
|
+
if (!std.math.isFinite(value)) continue;
|
|
1947
|
+
if (value == base_value) continue;
|
|
1948
|
+
const x = plot.x + slot * @as(f32, @floatFromInt(index)) + (slot - bar_width) * 0.5;
|
|
1949
|
+
const value_y = chartMapY(value, domain, plot, 0);
|
|
1950
|
+
const top = @min(base_y, value_y);
|
|
1951
|
+
// A visible tick for near-baseline values: zero draws nothing
|
|
1952
|
+
// (zero looks like zero), anything else is at least a hairline.
|
|
1953
|
+
const height = @max(1, @abs(base_y - value_y));
|
|
1954
|
+
try builder.fillRoundedRect(.{
|
|
1955
|
+
.id = chartCommandId(widget.id, chart_bar_seed, series_index, index),
|
|
1956
|
+
.rect = pixelSnapGeometryRect(tokens, geometry.RectF.init(x, if (value >= base_value) top else base_y, bar_width, height)),
|
|
1957
|
+
.radius = Radius.all(@min(1, bar_width * 0.5)),
|
|
1958
|
+
.fill = colorFill(color),
|
|
1959
|
+
});
|
|
1960
|
+
}
|
|
1961
|
+
}
|
|
1962
|
+
|
|
1963
|
+
fn emitChartLine(
|
|
1964
|
+
builder: *Builder,
|
|
1965
|
+
widget: Widget,
|
|
1966
|
+
plot: geometry.RectF,
|
|
1967
|
+
domain: chart_model.ChartDomain,
|
|
1968
|
+
series: chart_model.ChartSeries,
|
|
1969
|
+
series_index: usize,
|
|
1970
|
+
color: drawing_model.Color,
|
|
1971
|
+
) Error!void {
|
|
1972
|
+
const stroke_width = chartStrokeWidth(widget);
|
|
1973
|
+
const inset = stroke_width * 0.5;
|
|
1974
|
+
const points = try chartPolylinePoints(series.values, domain, plot, inset);
|
|
1975
|
+
if (points.len == 0) return;
|
|
1976
|
+
if (points.len == 1) {
|
|
1977
|
+
// A single sample has no line: draw a dot at the point.
|
|
1978
|
+
const extent = @max(2, stroke_width * 2);
|
|
1979
|
+
try builder.fillRoundedRect(.{
|
|
1980
|
+
.id = chartCommandId(widget.id, chart_line_seed, series_index, 0),
|
|
1981
|
+
.rect = geometry.RectF.init(points[0].x - extent * 0.5, points[0].y - extent * 0.5, extent, extent),
|
|
1982
|
+
.radius = Radius.all(extent * 0.5),
|
|
1983
|
+
.fill = colorFill(color),
|
|
1984
|
+
});
|
|
1985
|
+
return;
|
|
1986
|
+
}
|
|
1987
|
+
|
|
1988
|
+
if (series.fill) {
|
|
1989
|
+
const base_y = chartMapY(chartBaselineValue(domain), domain, plot, 0);
|
|
1990
|
+
const elements = try allocFramePathElements(points.len + 3);
|
|
1991
|
+
for (points, 0..) |point, index| {
|
|
1992
|
+
elements[index] = .{
|
|
1993
|
+
.verb = if (index == 0) .move_to else .line_to,
|
|
1994
|
+
.points = .{ point, geometry.PointF.zero(), geometry.PointF.zero() },
|
|
1995
|
+
};
|
|
1996
|
+
}
|
|
1997
|
+
elements[points.len] = .{ .verb = .line_to, .points = .{ geometry.PointF.init(points[points.len - 1].x, base_y), geometry.PointF.zero(), geometry.PointF.zero() } };
|
|
1998
|
+
elements[points.len + 1] = .{ .verb = .line_to, .points = .{ geometry.PointF.init(points[0].x, base_y), geometry.PointF.zero(), geometry.PointF.zero() } };
|
|
1999
|
+
elements[points.len + 2] = .{ .verb = .close };
|
|
2000
|
+
try builder.fillPath(.{
|
|
2001
|
+
.id = chartCommandId(widget.id, chart_fill_seed, series_index, 0),
|
|
2002
|
+
.elements = elements,
|
|
2003
|
+
.fill = colorFill(colorWithAlpha(color, chart_line_fill_alpha)),
|
|
2004
|
+
});
|
|
2005
|
+
}
|
|
2006
|
+
|
|
2007
|
+
const elements = try allocFramePathElements(points.len);
|
|
2008
|
+
for (points, 0..) |point, index| {
|
|
2009
|
+
elements[index] = .{
|
|
2010
|
+
.verb = if (index == 0) .move_to else .line_to,
|
|
2011
|
+
.points = .{ point, geometry.PointF.zero(), geometry.PointF.zero() },
|
|
2012
|
+
};
|
|
2013
|
+
}
|
|
2014
|
+
try builder.strokePath(.{
|
|
2015
|
+
.id = chartCommandId(widget.id, chart_line_seed, series_index, 0),
|
|
2016
|
+
.elements = elements,
|
|
2017
|
+
.stroke = .{
|
|
2018
|
+
.fill = colorFill(color),
|
|
2019
|
+
.width = stroke_width,
|
|
2020
|
+
},
|
|
2021
|
+
});
|
|
2022
|
+
}
|
|
2023
|
+
|
|
2024
|
+
fn emitChartBand(
|
|
2025
|
+
builder: *Builder,
|
|
2026
|
+
widget: Widget,
|
|
2027
|
+
plot: geometry.RectF,
|
|
2028
|
+
domain: chart_model.ChartDomain,
|
|
2029
|
+
series: chart_model.ChartSeries,
|
|
2030
|
+
series_index: usize,
|
|
2031
|
+
color: drawing_model.Color,
|
|
2032
|
+
) Error!void {
|
|
2033
|
+
const upper = try chartPolylinePoints(series.values, domain, plot, 0);
|
|
2034
|
+
if (upper.len < 2) return;
|
|
2035
|
+
const base_y = chartMapY(chartBaselineValue(domain), domain, plot, 0);
|
|
2036
|
+
const pair_count = @min(series.values.len, series.low.len);
|
|
2037
|
+
const lower_count = if (pair_count >= 2) pair_count else 2;
|
|
2038
|
+
const elements = try allocFramePathElements(upper.len + lower_count + 1);
|
|
2039
|
+
for (upper, 0..) |point, index| {
|
|
2040
|
+
elements[index] = .{
|
|
2041
|
+
.verb = if (index == 0) .move_to else .line_to,
|
|
2042
|
+
.points = .{ point, geometry.PointF.zero(), geometry.PointF.zero() },
|
|
2043
|
+
};
|
|
2044
|
+
}
|
|
2045
|
+
var cursor = upper.len;
|
|
2046
|
+
if (pair_count >= 2) {
|
|
2047
|
+
// Walk the lower edge back (newest to oldest) to close the
|
|
2048
|
+
// envelope. Non-finite lower values clamp to the baseline.
|
|
2049
|
+
var index = pair_count;
|
|
2050
|
+
while (index > 0) {
|
|
2051
|
+
index -= 1;
|
|
2052
|
+
const raw = series.low[index];
|
|
2053
|
+
const value = if (std.math.isFinite(raw)) raw else chartBaselineValue(domain);
|
|
2054
|
+
elements[cursor] = .{ .verb = .line_to, .points = .{
|
|
2055
|
+
geometry.PointF.init(chartMapX(index, series.values.len, plot, 0), chartMapY(value, domain, plot, 0)),
|
|
2056
|
+
geometry.PointF.zero(),
|
|
2057
|
+
geometry.PointF.zero(),
|
|
2058
|
+
} };
|
|
2059
|
+
cursor += 1;
|
|
2060
|
+
}
|
|
2061
|
+
} else {
|
|
2062
|
+
// No lower edge: fill down to the baseline (a stroke-less
|
|
2063
|
+
// line-with-fill).
|
|
2064
|
+
elements[cursor] = .{ .verb = .line_to, .points = .{ geometry.PointF.init(upper[upper.len - 1].x, base_y), geometry.PointF.zero(), geometry.PointF.zero() } };
|
|
2065
|
+
elements[cursor + 1] = .{ .verb = .line_to, .points = .{ geometry.PointF.init(upper[0].x, base_y), geometry.PointF.zero(), geometry.PointF.zero() } };
|
|
2066
|
+
cursor += 2;
|
|
2067
|
+
}
|
|
2068
|
+
elements[cursor] = .{ .verb = .close };
|
|
2069
|
+
try builder.fillPath(.{
|
|
2070
|
+
.id = chartCommandId(widget.id, chart_band_seed, series_index, 0),
|
|
2071
|
+
.elements = elements,
|
|
2072
|
+
.fill = colorFill(colorWithAlpha(color, chart_band_fill_alpha)),
|
|
2073
|
+
});
|
|
2074
|
+
}
|
|
2075
|
+
|
|
2076
|
+
/// Map a series into plot-space points, skipping non-finite values.
|
|
2077
|
+
/// Returned points live in a threadlocal scratch valid until the next
|
|
2078
|
+
/// series maps (each emitter consumes them before returning).
|
|
2079
|
+
threadlocal var chart_polyline_points: [chart_model.max_chart_points_per_series]geometry.PointF = undefined;
|
|
2080
|
+
|
|
2081
|
+
fn chartPolylinePoints(
|
|
2082
|
+
values: []const f32,
|
|
2083
|
+
domain: chart_model.ChartDomain,
|
|
2084
|
+
plot: geometry.RectF,
|
|
2085
|
+
inset: f32,
|
|
2086
|
+
) Error![]const geometry.PointF {
|
|
2087
|
+
const count = @min(values.len, chart_polyline_points.len);
|
|
2088
|
+
var len: usize = 0;
|
|
2089
|
+
for (values[0..count], 0..) |value, index| {
|
|
2090
|
+
if (!std.math.isFinite(value)) continue;
|
|
2091
|
+
chart_polyline_points[len] = geometry.PointF.init(
|
|
2092
|
+
chartMapX(index, count, plot, inset),
|
|
2093
|
+
chartMapY(value, domain, plot, inset),
|
|
2094
|
+
);
|
|
2095
|
+
len += 1;
|
|
2096
|
+
}
|
|
2097
|
+
return chart_polyline_points[0..len];
|
|
2098
|
+
}
|
|
2099
|
+
|
|
2100
|
+
const chart_grid_seed: u64 = 0x5eed_c4a8_0000_0001;
|
|
2101
|
+
const chart_baseline_seed: u64 = 0x5eed_c4a8_0000_0002;
|
|
2102
|
+
const chart_line_seed: u64 = 0x5eed_c4a8_0000_0003;
|
|
2103
|
+
const chart_fill_seed: u64 = 0x5eed_c4a8_0000_0004;
|
|
2104
|
+
const chart_band_seed: u64 = 0x5eed_c4a8_0000_0005;
|
|
2105
|
+
const chart_bar_seed: u64 = 0x5eed_c4a8_0000_0006;
|
|
2106
|
+
const chart_tick_seed: u64 = 0x5eed_c4a8_0000_0007;
|
|
2107
|
+
const chart_hover_seed: u64 = 0x5eed_c4a8_0000_0008;
|
|
2108
|
+
const chart_hover_dot_seed: u64 = 0x5eed_c4a8_0000_0009;
|
|
2109
|
+
const chart_hover_row_seed: u64 = 0x5eed_c4a8_0000_000a;
|
|
2110
|
+
|
|
2111
|
+
// ---------------------------------------------------- chart hover details
|
|
2112
|
+
|
|
2113
|
+
/// Detail-card type size: one rung under the label register (13 -> 12
|
|
2114
|
+
/// with house tokens) — denser than control labels, a step above the
|
|
2115
|
+
/// tick chrome, floored for dense themes.
|
|
2116
|
+
fn chartDetailTextSize(tokens: DesignTokens) f32 {
|
|
2117
|
+
return @max(10, tokens.typography.label_size - 1);
|
|
2118
|
+
}
|
|
2119
|
+
|
|
2120
|
+
const chart_detail_pad_h: f32 = 10;
|
|
2121
|
+
const chart_detail_pad_v: f32 = 8;
|
|
2122
|
+
const chart_detail_row_gap: f32 = 2;
|
|
2123
|
+
const chart_detail_swatch: f32 = 8;
|
|
2124
|
+
const chart_detail_swatch_gap: f32 = 6;
|
|
2125
|
+
const chart_detail_column_gap: f32 = 16;
|
|
2126
|
+
const chart_detail_anchor_gap: f32 = 12;
|
|
2127
|
+
const chart_detail_edge_margin: f32 = 4;
|
|
2128
|
+
|
|
2129
|
+
/// Resolved hover-detail geometry: which sample the pointer snapped to
|
|
2130
|
+
/// and where the floating card lands. Pure over the widget, tokens,
|
|
2131
|
+
/// pointer point, and the window bounds the card clamps into — the
|
|
2132
|
+
/// emitter and the invalidation path share it, so the repainted region
|
|
2133
|
+
/// always covers the painted chrome.
|
|
2134
|
+
pub const ChartHoverDetail = struct {
|
|
2135
|
+
index: usize,
|
|
2136
|
+
plot: geometry.RectF,
|
|
2137
|
+
/// The x the hovered sample renders at (cursor line and dots).
|
|
2138
|
+
sample_x: f32,
|
|
2139
|
+
card: geometry.RectF,
|
|
2140
|
+
};
|
|
2141
|
+
|
|
2142
|
+
/// Value formatting for detail rows: two orders of magnitude below the
|
|
2143
|
+
/// domain span, so a 0..1 chart reads "0.42" and a 0..500 chart reads
|
|
2144
|
+
/// "237" — resolution that matches what the plot can show.
|
|
2145
|
+
fn chartDetailDecimals(domain: chart_model.ChartDomain) u8 {
|
|
2146
|
+
return chart_model.chartTickDecimals(domain.span() / 100);
|
|
2147
|
+
}
|
|
2148
|
+
|
|
2149
|
+
fn chartDetailRowName(series: chart_model.ChartSeries) []const u8 {
|
|
2150
|
+
return if (series.label.len > 0) series.label else @tagName(series.kind);
|
|
2151
|
+
}
|
|
2152
|
+
|
|
2153
|
+
/// Compute the hover-detail geometry for a pointer over a chart, or
|
|
2154
|
+
/// null when there is no sample to snap to. The card prefers the right
|
|
2155
|
+
/// side of the hovered sample and flips left when the window edge is
|
|
2156
|
+
/// closer than the card is wide; vertically it centers on the plot —
|
|
2157
|
+
/// position depends only on the snapped index, never the raw pointer,
|
|
2158
|
+
/// so a pointer gliding within one sample repaints nothing.
|
|
2159
|
+
pub fn chartWidgetHoverDetail(widget: Widget, tokens: DesignTokens, point: geometry.PointF, bounds: geometry.RectF) ?ChartHoverDetail {
|
|
2160
|
+
if (widget.kind != .chart or !widget.chart.hover_details) return null;
|
|
2161
|
+
const data = widget.chart;
|
|
2162
|
+
const plot = chartWidgetPlotRect(widget, tokens);
|
|
2163
|
+
if (plot.isEmpty() or plot.width <= 0 or plot.height <= 0) return null;
|
|
2164
|
+
const count = chart_model.chartPointCount(data);
|
|
2165
|
+
const index = chart_model.chartHoverIndex(data, (point.x - plot.x) / plot.width) orelse return null;
|
|
2166
|
+
const domain = chart_model.chartDomain(data);
|
|
2167
|
+
const decimals = chartDetailDecimals(domain);
|
|
2168
|
+
const size = chartDetailTextSize(tokens);
|
|
2169
|
+
const line_height = size * 1.25;
|
|
2170
|
+
|
|
2171
|
+
// Measure the card: title line (the sample's category label, or its
|
|
2172
|
+
// index) over one row per series that has this sample.
|
|
2173
|
+
var buffer: [chart_model.max_chart_value_label_bytes]u8 = undefined;
|
|
2174
|
+
const title = chartHoverDetailTitle(data, index, &buffer);
|
|
2175
|
+
var content_width = measureTextWidthForFont(tokens.text_measure, tokens.typography.font_id, title, size);
|
|
2176
|
+
var rows: usize = 0;
|
|
2177
|
+
for (data.series) |series| {
|
|
2178
|
+
if (index >= series.values.len) continue;
|
|
2179
|
+
rows += 1;
|
|
2180
|
+
var value_buffer: [chart_model.max_chart_value_label_bytes]u8 = undefined;
|
|
2181
|
+
const name_width = measureTextWidthForFont(tokens.text_measure, tokens.typography.font_id, chartDetailRowName(series), size);
|
|
2182
|
+
const value_text = chart_model.formatChartValue(&value_buffer, series.values[index], decimals);
|
|
2183
|
+
const value_width = measureTextWidthForFont(tokens.text_measure, tokens.typography.font_id, value_text, size);
|
|
2184
|
+
content_width = @max(content_width, chart_detail_swatch + chart_detail_swatch_gap + name_width + chart_detail_column_gap + value_width);
|
|
2185
|
+
}
|
|
2186
|
+
if (rows == 0) return null;
|
|
2187
|
+
|
|
2188
|
+
const card_width = @ceil(content_width) + chart_detail_pad_h * 2;
|
|
2189
|
+
const card_height = chart_detail_pad_v * 2 + line_height * @as(f32, @floatFromInt(rows + 1)) + chart_detail_row_gap * @as(f32, @floatFromInt(rows));
|
|
2190
|
+
const sample_x = chartSampleX(data, count, index, plot);
|
|
2191
|
+
var card_x = sample_x + chart_detail_anchor_gap;
|
|
2192
|
+
if (card_x + card_width > bounds.maxX() - chart_detail_edge_margin) {
|
|
2193
|
+
card_x = sample_x - chart_detail_anchor_gap - card_width;
|
|
2194
|
+
}
|
|
2195
|
+
card_x = std.math.clamp(card_x, bounds.x + chart_detail_edge_margin, @max(bounds.x + chart_detail_edge_margin, bounds.maxX() - card_width - chart_detail_edge_margin));
|
|
2196
|
+
const card_y = std.math.clamp(plot.y + (plot.height - card_height) * 0.5, bounds.y + chart_detail_edge_margin, @max(bounds.y + chart_detail_edge_margin, bounds.maxY() - card_height - chart_detail_edge_margin));
|
|
2197
|
+
|
|
2198
|
+
return .{
|
|
2199
|
+
.index = index,
|
|
2200
|
+
.plot = plot,
|
|
2201
|
+
.sample_x = sample_x,
|
|
2202
|
+
.card = geometry.RectF.init(card_x, card_y, card_width, card_height),
|
|
2203
|
+
};
|
|
2204
|
+
}
|
|
2205
|
+
|
|
2206
|
+
/// The sample index a pointer over a hover-details chart snaps to, or
|
|
2207
|
+
/// null when the widget is not a hover-details chart (or has no data).
|
|
2208
|
+
/// The runtime's interaction path uses this to gate repaints: a pointer
|
|
2209
|
+
/// gliding within one sample changes nothing, so nothing repaints.
|
|
2210
|
+
pub fn chartWidgetHoverIndex(widget: Widget, tokens: DesignTokens, point: geometry.PointF) ?usize {
|
|
2211
|
+
if (widget.kind != .chart or !widget.chart.hover_details) return null;
|
|
2212
|
+
const plot = chartWidgetPlotRect(widget, tokens);
|
|
2213
|
+
if (plot.isEmpty() or plot.width <= 0 or plot.height <= 0) return null;
|
|
2214
|
+
return chart_model.chartHoverIndex(widget.chart, (point.x - plot.x) / plot.width);
|
|
2215
|
+
}
|
|
2216
|
+
|
|
2217
|
+
/// The card's title: the hovered sample's category label when the chart
|
|
2218
|
+
/// carries x labels, else the sample index — never invented text.
|
|
2219
|
+
fn chartHoverDetailTitle(data: chart_model.ChartData, index: usize, buffer: *[chart_model.max_chart_value_label_bytes]u8) []const u8 {
|
|
2220
|
+
if (index < data.x_labels.len and data.x_labels[index].len > 0) return data.x_labels[index];
|
|
2221
|
+
return chart_model.formatChartValue(buffer, @floatFromInt(index), 0);
|
|
2222
|
+
}
|
|
2223
|
+
|
|
2224
|
+
/// The region hover-detail chrome inks for a render state, for dirty
|
|
2225
|
+
/// invalidation: the chart's frame (cursor line and dots live inside
|
|
2226
|
+
/// it) unioned with the floating card. Null when the state paints no
|
|
2227
|
+
/// hover chrome.
|
|
2228
|
+
pub fn chartHoverDetailDirtyBounds(layout: anytype, state: WidgetRenderState, tokens: DesignTokens) ?geometry.RectF {
|
|
2229
|
+
const node_index = chartHoverDetailNodeIndex(layout, state) orelse return null;
|
|
2230
|
+
const point = state.hover_point orelse return null;
|
|
2231
|
+
const node = layout.nodes[node_index];
|
|
2232
|
+
const widget = widgetWithFrame(node.widget, node.frame);
|
|
2233
|
+
const bounds = widgetLayoutRootBounds(layout) orelse widget.frame.normalized();
|
|
2234
|
+
const detail = chartWidgetHoverDetail(widget, tokens, point, bounds) orelse return null;
|
|
2235
|
+
return geometry.RectF.unionWith(widget.frame.normalized(), detail.card);
|
|
2236
|
+
}
|
|
2237
|
+
|
|
2238
|
+
/// The layout node the state's hover chrome belongs to: the hovered
|
|
2239
|
+
/// widget when it is a hover-details chart that is actually visible.
|
|
2240
|
+
fn chartHoverDetailNodeIndex(layout: anytype, state: WidgetRenderState) ?usize {
|
|
2241
|
+
const hovered_id = state.hovered_id orelse return null;
|
|
2242
|
+
if (hovered_id == 0 or state.hover_point == null) return null;
|
|
2243
|
+
for (layout.nodes, 0..) |node, index| {
|
|
2244
|
+
if (node.widget.id != hovered_id) continue;
|
|
2245
|
+
if (node.widget.kind != .chart or !node.widget.chart.hover_details) return null;
|
|
2246
|
+
if (widget_tree.isWidgetHiddenInAncestors(layout, index)) return null;
|
|
2247
|
+
return index;
|
|
2248
|
+
}
|
|
2249
|
+
return null;
|
|
2250
|
+
}
|
|
2251
|
+
|
|
2252
|
+
/// The hover-detail z-pass: runs after the anchored-surface pass, so
|
|
2253
|
+
/// the cursor, point dots, and floating card paint above everything —
|
|
2254
|
+
/// the same clip-escaping contract tooltips have. Interaction-only by
|
|
2255
|
+
/// construction: static trees never carry a `hover_point`, so goldens
|
|
2256
|
+
/// and docs tiles stay byte-identical.
|
|
2257
|
+
fn emitWidgetLayoutChartHoverDetails(builder: *Builder, layout: anytype, tokens: DesignTokens, state: WidgetRenderState) Error!void {
|
|
2258
|
+
const node_index = chartHoverDetailNodeIndex(layout, state) orelse return;
|
|
2259
|
+
const point = state.hover_point orelse return;
|
|
2260
|
+
const node = layout.nodes[node_index];
|
|
2261
|
+
const widget = widgetWithFrame(node.widget, pixelSnapGeometryRect(tokens, node.frame));
|
|
2262
|
+
const bounds = widgetLayoutRootBounds(layout) orelse widget.frame.normalized();
|
|
2263
|
+
const detail = chartWidgetHoverDetail(widget, tokens, point, bounds) orelse return;
|
|
2264
|
+
try emitChartHoverDetail(builder, widget, tokens, detail);
|
|
2265
|
+
}
|
|
2266
|
+
|
|
2267
|
+
/// Draw the hover chrome: a hairline cursor at the hovered sample, a
|
|
2268
|
+
/// dot on every line series' hovered point, then the floating card —
|
|
2269
|
+
/// popover-grade chrome (surface fill, hairline border, small shadow)
|
|
2270
|
+
/// holding the sample's title over swatch/name/value rows. Values
|
|
2271
|
+
/// format deterministically into the frame label scratch.
|
|
2272
|
+
fn emitChartHoverDetail(builder: *Builder, widget: Widget, tokens: DesignTokens, detail: ChartHoverDetail) Error!void {
|
|
2273
|
+
const data = widget.chart;
|
|
2274
|
+
const domain = chart_model.chartDomain(data);
|
|
2275
|
+
const decimals = chartDetailDecimals(domain);
|
|
2276
|
+
const hairline = @max(1, tokens.stroke.hairline);
|
|
2277
|
+
|
|
2278
|
+
// Cursor: the vertical reading line the eye follows to the axis.
|
|
2279
|
+
try builder.fillRect(.{
|
|
2280
|
+
.id = chartCommandId(widget.id, chart_hover_seed, 0, 0),
|
|
2281
|
+
.rect = pixelSnapGeometryRect(tokens, geometry.RectF.init(detail.sample_x - hairline * 0.5, detail.plot.y, hairline, detail.plot.height)),
|
|
2282
|
+
.fill = colorFill(tokens.colors.border),
|
|
2283
|
+
});
|
|
2284
|
+
|
|
2285
|
+
// Point dots on line series (bars read fine under the cursor line;
|
|
2286
|
+
// bands are ranges, not points).
|
|
2287
|
+
const stroke_inset = chartStrokeWidth(widget) * 0.5;
|
|
2288
|
+
for (data.series, 0..) |series, series_index| {
|
|
2289
|
+
if (series.kind != .line or detail.index >= series.values.len) continue;
|
|
2290
|
+
const value = series.values[detail.index];
|
|
2291
|
+
if (!std.math.isFinite(value)) continue;
|
|
2292
|
+
const dot_extent: f32 = 6;
|
|
2293
|
+
const dot_x = chartMapX(detail.index, series.values.len, detail.plot, stroke_inset);
|
|
2294
|
+
const dot_y = chartMapY(value, domain, detail.plot, stroke_inset);
|
|
2295
|
+
try builder.fillRoundedRect(.{
|
|
2296
|
+
.id = chartCommandId(widget.id, chart_hover_dot_seed, series_index, 0),
|
|
2297
|
+
.rect = geometry.RectF.init(dot_x - dot_extent * 0.5, dot_y - dot_extent * 0.5, dot_extent, dot_extent),
|
|
2298
|
+
.radius = Radius.all(dot_extent * 0.5),
|
|
2299
|
+
.fill = colorFill(text_spans_model.textSpanColorValue(tokens.colors, series.color)),
|
|
2300
|
+
});
|
|
2301
|
+
}
|
|
2302
|
+
|
|
2303
|
+
// Card chrome: the popover register (surface, hairline border, the
|
|
2304
|
+
// small shadow step) — floating detail, not a modal surface.
|
|
2305
|
+
const card = pixelSnapGeometryRect(tokens, detail.card);
|
|
2306
|
+
const radius = Radius.all(tokens.radius.md);
|
|
2307
|
+
const shadow_token = tokens.shadow.sm;
|
|
2308
|
+
if (shadow_token.y != 0 or shadow_token.blur != 0 or shadow_token.spread != 0) {
|
|
2309
|
+
try builder.shadow(.{
|
|
2310
|
+
.id = chartCommandId(widget.id, chart_hover_seed, 0, 1),
|
|
2311
|
+
.rect = card,
|
|
2312
|
+
.radius = radius,
|
|
2313
|
+
.offset = .{ .dx = 0, .dy = shadow_token.y },
|
|
2314
|
+
.blur = shadow_token.blur,
|
|
2315
|
+
.spread = shadow_token.spread,
|
|
2316
|
+
.color = tokens.colors.shadow,
|
|
2317
|
+
});
|
|
2318
|
+
}
|
|
2319
|
+
try builder.fillRoundedRect(.{
|
|
2320
|
+
.id = chartCommandId(widget.id, chart_hover_seed, 0, 2),
|
|
2321
|
+
.rect = card,
|
|
2322
|
+
.radius = radius,
|
|
2323
|
+
.fill = colorFill(tokens.colors.surface),
|
|
2324
|
+
});
|
|
2325
|
+
try builder.strokeRect(.{
|
|
2326
|
+
.id = chartCommandId(widget.id, chart_hover_seed, 0, 3),
|
|
2327
|
+
.rect = card,
|
|
2328
|
+
.radius = radius,
|
|
2329
|
+
.stroke = .{ .fill = colorFill(tokens.colors.border), .width = hairline },
|
|
2330
|
+
});
|
|
2331
|
+
|
|
2332
|
+
// Title line, then one swatch/name/value row per series holding
|
|
2333
|
+
// this sample. Values right-align on the card's inner edge so a
|
|
2334
|
+
// column of numbers reads as one.
|
|
2335
|
+
const size = chartDetailTextSize(tokens);
|
|
2336
|
+
const line_height = size * 1.25;
|
|
2337
|
+
var title_buffer: [chart_model.max_chart_value_label_bytes]u8 = undefined;
|
|
2338
|
+
const title = chartHoverDetailTitle(data, detail.index, &title_buffer);
|
|
2339
|
+
const title_text = try allocFrameLabelBytes(title);
|
|
2340
|
+
var row_y = card.y + chart_detail_pad_v;
|
|
2341
|
+
try builder.drawText(.{
|
|
2342
|
+
.id = chartCommandId(widget.id, chart_hover_seed, 0, 4),
|
|
2343
|
+
.font_id = tokens.typography.font_id,
|
|
2344
|
+
.size = size,
|
|
2345
|
+
.origin = pixelSnapTextPoint(tokens, geometry.PointF.init(card.x + chart_detail_pad_h, row_y + size)),
|
|
2346
|
+
.color = tokens.colors.text,
|
|
2347
|
+
.text = title_text,
|
|
2348
|
+
});
|
|
2349
|
+
row_y += line_height;
|
|
2350
|
+
for (data.series, 0..) |series, series_index| {
|
|
2351
|
+
if (detail.index >= series.values.len) continue;
|
|
2352
|
+
row_y += chart_detail_row_gap;
|
|
2353
|
+
const swatch_y = row_y + (line_height - chart_detail_swatch) * 0.5;
|
|
2354
|
+
try builder.fillRoundedRect(.{
|
|
2355
|
+
.id = chartCommandId(widget.id, chart_hover_row_seed, series_index, 0),
|
|
2356
|
+
.rect = pixelSnapGeometryRect(tokens, geometry.RectF.init(card.x + chart_detail_pad_h, swatch_y, chart_detail_swatch, chart_detail_swatch)),
|
|
2357
|
+
.radius = Radius.all(2),
|
|
2358
|
+
.fill = colorFill(text_spans_model.textSpanColorValue(tokens.colors, series.color)),
|
|
2359
|
+
});
|
|
2360
|
+
try builder.drawText(.{
|
|
2361
|
+
.id = chartCommandId(widget.id, chart_hover_row_seed, series_index, 1),
|
|
2362
|
+
.font_id = tokens.typography.font_id,
|
|
2363
|
+
.size = size,
|
|
2364
|
+
.origin = pixelSnapTextPoint(tokens, geometry.PointF.init(card.x + chart_detail_pad_h + chart_detail_swatch + chart_detail_swatch_gap, row_y + size)),
|
|
2365
|
+
.color = tokens.colors.text_muted,
|
|
2366
|
+
.text = chartDetailRowName(series),
|
|
2367
|
+
});
|
|
2368
|
+
var value_buffer: [chart_model.max_chart_value_label_bytes]u8 = undefined;
|
|
2369
|
+
const value_text = try allocFrameLabelBytes(chart_model.formatChartValue(&value_buffer, series.values[detail.index], decimals));
|
|
2370
|
+
const value_width = measureTextWidthForFont(tokens.text_measure, tokens.typography.font_id, value_text, size);
|
|
2371
|
+
try builder.drawText(.{
|
|
2372
|
+
.id = chartCommandId(widget.id, chart_hover_row_seed, series_index, 2),
|
|
2373
|
+
.font_id = tokens.typography.font_id,
|
|
2374
|
+
.size = size,
|
|
2375
|
+
.origin = pixelSnapTextPoint(tokens, geometry.PointF.init(card.maxX() - chart_detail_pad_h - value_width, row_y + size)),
|
|
2376
|
+
.color = tokens.colors.text,
|
|
2377
|
+
.text = value_text,
|
|
2378
|
+
});
|
|
2379
|
+
row_y += line_height;
|
|
2380
|
+
}
|
|
2381
|
+
}
|
|
2382
|
+
|
|
2383
|
+
/// Stable hashed command ids per (family, series, ordinal), same scheme
|
|
2384
|
+
/// as span runs, so retained diffing tracks chart commands across frames.
|
|
2385
|
+
fn chartCommandId(widget_id: ObjectId, seed: u64, series_index: usize, ordinal: usize) ObjectId {
|
|
2386
|
+
var hasher = std.hash.Wyhash.init(seed);
|
|
2387
|
+
hasher.update(std.mem.asBytes(&widget_id));
|
|
2388
|
+
hasher.update(std.mem.asBytes(&@as(u64, series_index)));
|
|
2389
|
+
hasher.update(std.mem.asBytes(&@as(u64, ordinal)));
|
|
2390
|
+
const value = hasher.final();
|
|
2391
|
+
return if (value == 0) 1 else value;
|
|
2392
|
+
}
|
|
2393
|
+
|
|
2394
|
+
pub fn toggleWidgetKnobCommandId(id: ObjectId) ObjectId {
|
|
2395
|
+
return widgetPartId(id, 3);
|
|
2396
|
+
}
|
|
2397
|
+
|
|
2398
|
+
/// The command id of an editable text widget's caret line — the part
|
|
2399
|
+
/// slot `emitTextFieldWidget` / `emitSearchFieldWidget` draw it under —
|
|
2400
|
+
/// so the runtime can target the caret with a blink render animation.
|
|
2401
|
+
/// 0 for kinds that never draw a caret.
|
|
2402
|
+
pub fn textCaretCommandId(kind: WidgetKind, id: ObjectId) ObjectId {
|
|
2403
|
+
return switch (kind) {
|
|
2404
|
+
.input, .text_field, .textarea => widgetPartId(id, 6),
|
|
2405
|
+
.search_field, .combobox => widgetPartId(id, 11),
|
|
2406
|
+
else => 0,
|
|
2407
|
+
};
|
|
2408
|
+
}
|
|
2409
|
+
|
|
2410
|
+
pub fn toggleWidgetKnobTravel(widget: Widget, tokens: DesignTokens) f32 {
|
|
2411
|
+
if (!widgetSwitchControlKind(widget.kind)) return 0;
|
|
2412
|
+
// Shares the renderer's track/inset metrics (44x24 track, 2px thumb
|
|
2413
|
+
// inset, both size- and density-scaled) so animated travel lands on
|
|
2414
|
+
// exactly the painted on/off thumb positions.
|
|
2415
|
+
const knob_inset = widget_metrics.widgetSizedDensityValue(widget, tokens, 2);
|
|
2416
|
+
const track = widget_render_controls.toggleWidgetTrackRect(widget, tokens);
|
|
2417
|
+
const knob_size = @max(0, track.height - knob_inset * 2);
|
|
2418
|
+
const off_knob = pixelSnapGeometryRect(tokens, geometry.RectF.init(track.x + knob_inset, track.y + knob_inset, knob_size, knob_size));
|
|
2419
|
+
const on_knob = pixelSnapGeometryRect(tokens, geometry.RectF.init(
|
|
2420
|
+
track.x + track.width - knob_size - knob_inset,
|
|
2421
|
+
track.y + knob_inset,
|
|
2422
|
+
knob_size,
|
|
2423
|
+
knob_size,
|
|
2424
|
+
));
|
|
2425
|
+
return on_knob.x - off_knob.x;
|
|
2426
|
+
}
|
|
2427
|
+
|
|
2428
|
+
fn widgetSwitchControlKind(kind: WidgetKind) bool {
|
|
2429
|
+
return kind == .switch_control;
|
|
2430
|
+
}
|
|
2431
|
+
|
|
2432
|
+
pub fn widgetPartId(id: ObjectId, slot: ObjectId) ObjectId {
|
|
2433
|
+
if (id == 0) return 0;
|
|
2434
|
+
const base = id *% 16;
|
|
2435
|
+
const part = base +% slot;
|
|
2436
|
+
return if (part == 0) id else part;
|
|
2437
|
+
}
|
|
2438
|
+
|
|
2439
|
+
fn textOrigin(frame: geometry.RectF, size: f32, inset: f32) geometry.PointF {
|
|
2440
|
+
const line_height = size * 1.25;
|
|
2441
|
+
return geometry.PointF.init(
|
|
2442
|
+
frame.x + inset,
|
|
2443
|
+
frame.y + @max(size, (frame.height - line_height) * 0.5 + size),
|
|
2444
|
+
);
|
|
2445
|
+
}
|
|
2446
|
+
|
|
2447
|
+
fn boundedTextOrigin(frame: geometry.RectF, size: f32, inset: f32) geometry.PointF {
|
|
2448
|
+
return geometry.PointF.init(frame.x + inset, textOrigin(frame, size, 0).y);
|
|
2449
|
+
}
|
|
2450
|
+
|
|
2451
|
+
fn boundedTextLayout(frame: geometry.RectF, size: f32, inset: f32, alignment: TextAlign, wrap: TextWrap, tokens: DesignTokens) TextLayoutOptions {
|
|
2452
|
+
return .{
|
|
2453
|
+
.max_width = @max(1, frame.width - inset * 2),
|
|
2454
|
+
.line_height = size * 1.25,
|
|
2455
|
+
.wrap = wrap,
|
|
2456
|
+
.alignment = alignment,
|
|
2457
|
+
.measure = tokens.text_measure,
|
|
2458
|
+
};
|
|
2459
|
+
}
|
|
2460
|
+
|
|
2461
|
+
fn centeredTextOrigin(frame: geometry.RectF, text: []const u8, size: f32, tokens: DesignTokens) geometry.PointF {
|
|
2462
|
+
return alignedTextOrigin(frame, text, size, 0, .center, tokens);
|
|
2463
|
+
}
|
|
2464
|
+
|
|
2465
|
+
fn alignedTextOrigin(frame: geometry.RectF, text: []const u8, size: f32, inset: f32, alignment: TextAlign, tokens: DesignTokens) geometry.PointF {
|
|
2466
|
+
const width = if (tokens.text_measure) |measure|
|
|
2467
|
+
measure.measureWidth(tokens.typography.font_id, size, text)
|
|
2468
|
+
else
|
|
2469
|
+
estimateTextWidth(text, size);
|
|
2470
|
+
const available_width = @max(0, frame.width - inset * 2);
|
|
2471
|
+
const offset = switch (alignment) {
|
|
2472
|
+
.start => 0,
|
|
2473
|
+
.center => @max(0, (available_width - width) * 0.5),
|
|
2474
|
+
.end => @max(0, available_width - width),
|
|
2475
|
+
};
|
|
2476
|
+
const line_height = size * 1.25;
|
|
2477
|
+
return geometry.PointF.init(
|
|
2478
|
+
frame.x + inset + offset,
|
|
2479
|
+
frame.y + @max(size, (frame.height - line_height) * 0.5 + size),
|
|
2480
|
+
);
|
|
2481
|
+
}
|
|
2482
|
+
|
|
2483
|
+
fn iconGlyphSize(widget: Widget, tokens: DesignTokens) f32 {
|
|
2484
|
+
const min_size = widgetSizedDensityValue(widget, tokens, 12);
|
|
2485
|
+
if (widget.frame.height > 0) return @min(@max(min_size, widget.frame.height * widgetIconGlyphScale(widget)), @max(min_size, widgetTypographySize(widget, tokens.typography.title_size)));
|
|
2486
|
+
return widgetButtonTextSize(widget, tokens);
|
|
2487
|
+
}
|
|
2488
|
+
|
|
2489
|
+
fn widgetIconGlyphScale(widget: Widget) f32 {
|
|
2490
|
+
return switch (widget.size) {
|
|
2491
|
+
.sm => 0.44,
|
|
2492
|
+
// heading/display are text-leaf typography rungs; icon glyphs
|
|
2493
|
+
// keep the default control proportion.
|
|
2494
|
+
.default, .icon, .heading, .display => 0.48,
|
|
2495
|
+
.lg => 0.52,
|
|
2496
|
+
};
|
|
2497
|
+
}
|
|
2498
|
+
|
|
2499
|
+
fn widgetWithFrame(widget: Widget, frame: geometry.RectF) Widget {
|
|
2500
|
+
var copy = widget;
|
|
2501
|
+
copy.frame = frame;
|
|
2502
|
+
return copy;
|
|
2503
|
+
}
|
|
2504
|
+
|
|
2505
|
+
fn widgetWithRenderState(widget: Widget, state: WidgetRenderState) Widget {
|
|
2506
|
+
var copy = widget;
|
|
2507
|
+
if (state.focused_id != null or state.focus_visible_id != null) {
|
|
2508
|
+
copy.state.focused = if (state.focus_visible_id) |focus_visible_id|
|
|
2509
|
+
copy.id != 0 and copy.id == focus_visible_id
|
|
2510
|
+
else
|
|
2511
|
+
false;
|
|
2512
|
+
}
|
|
2513
|
+
if (state.hovered_id) |hovered_id| {
|
|
2514
|
+
copy.state.hovered = copy.id != 0 and copy.id == hovered_id;
|
|
2515
|
+
}
|
|
2516
|
+
if (state.pressed_id) |pressed_id| {
|
|
2517
|
+
copy.state.pressed = copy.id != 0 and copy.id == pressed_id;
|
|
2518
|
+
}
|
|
2519
|
+
return copy;
|
|
2520
|
+
}
|
|
2521
|
+
|
|
2522
|
+
fn accordionChildrenVisible(widget: Widget) bool {
|
|
2523
|
+
return widget.kind != .accordion or booleanControlSelected(widget);
|
|
2524
|
+
}
|
|
2525
|
+
|
|
2526
|
+
fn accordionContentFrame(widget: Widget, content: geometry.RectF, tokens: DesignTokens) geometry.RectF {
|
|
2527
|
+
const header_height = widgetControlHeight(widget, tokens, tokens.sizes.control_md);
|
|
2528
|
+
const gap = nonNegative(widget.layout.gap);
|
|
2529
|
+
return geometry.RectF.init(content.x, content.y + header_height + gap, content.width, @max(0, content.height - header_height - gap));
|
|
2530
|
+
}
|
|
2531
|
+
|
|
2532
|
+
fn nonNegative(value: f32) f32 {
|
|
2533
|
+
return @max(0, value);
|
|
2534
|
+
}
|