@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,1563 @@
|
|
|
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 token_model = @import("tokens.zig");
|
|
7
|
+
const widget_model = @import("widgets.zig");
|
|
8
|
+
const widget_access = @import("widget_access.zig");
|
|
9
|
+
const widget_metrics = @import("widget_metrics.zig");
|
|
10
|
+
const widget_text_input = @import("widget_text_input.zig");
|
|
11
|
+
const widget_render_style = @import("widget_render_style.zig");
|
|
12
|
+
const icon_model = @import("icons.zig");
|
|
13
|
+
const svg_icon_model = @import("svg_icon.zig");
|
|
14
|
+
|
|
15
|
+
const Error = canvas.Error;
|
|
16
|
+
const ObjectId = canvas.ObjectId;
|
|
17
|
+
const Builder = canvas.Builder;
|
|
18
|
+
const Affine = drawing_model.Affine;
|
|
19
|
+
const Color = drawing_model.Color;
|
|
20
|
+
const Radius = drawing_model.Radius;
|
|
21
|
+
const Stroke = drawing_model.Stroke;
|
|
22
|
+
const DrawText = text_model.DrawText;
|
|
23
|
+
const TextWrap = text_model.TextWrap;
|
|
24
|
+
const TextOverflow = text_model.TextOverflow;
|
|
25
|
+
const TextAlign = text_model.TextAlign;
|
|
26
|
+
const TextLayoutOptions = text_model.TextLayoutOptions;
|
|
27
|
+
const TextRange = text_model.TextRange;
|
|
28
|
+
const TextSelectionRect = text_model.TextSelectionRect;
|
|
29
|
+
const DesignTokens = token_model.DesignTokens;
|
|
30
|
+
const ControlVisualTokens = token_model.ControlVisualTokens;
|
|
31
|
+
const Widget = widget_model.Widget;
|
|
32
|
+
|
|
33
|
+
const booleanControlSelected = widget_access.booleanControlSelected;
|
|
34
|
+
const widgetTextSelectionRange = widget_access.widgetTextSelectionRange;
|
|
35
|
+
const widgetTextCompositionRange = widget_access.widgetTextCompositionRange;
|
|
36
|
+
const widgetPlaceholder = widget_text_input.widgetPlaceholder;
|
|
37
|
+
const widgetTextInputSize = widget_text_input.widgetTextInputSize;
|
|
38
|
+
const widgetTextInputLayoutOptions = widget_text_input.widgetTextInputLayoutOptions;
|
|
39
|
+
const widgetTextInputOrigin = widget_text_input.widgetTextInputOrigin;
|
|
40
|
+
const widgetTextInputClipRect = widget_text_input.widgetTextInputClipRect;
|
|
41
|
+
const widgetTextInputDrawText = widget_text_input.widgetTextInputDrawText;
|
|
42
|
+
const widgetTextInputInset = widget_text_input.widgetTextInputInset;
|
|
43
|
+
const textInputClearButtonRect = widget_text_input.textInputClearButtonRect;
|
|
44
|
+
const widgetButtonTextSize = widget_metrics.widgetButtonTextSize;
|
|
45
|
+
const widgetBodyTextSize = widget_metrics.widgetBodyTextSize;
|
|
46
|
+
const widgetLabelTextSize = widget_metrics.widgetLabelTextSize;
|
|
47
|
+
const widgetTypographySize = widget_metrics.widgetTypographySize;
|
|
48
|
+
const widgetButtonInset = widget_metrics.widgetButtonInset;
|
|
49
|
+
const widgetControlInset = widget_metrics.widgetControlInset;
|
|
50
|
+
const widgetSizedDensityValue = widget_metrics.widgetSizedDensityValue;
|
|
51
|
+
const widgetButtonIconExtent = widget_metrics.widgetButtonIconExtent;
|
|
52
|
+
const widgetRowIconExtent = widget_metrics.widgetRowIconExtent;
|
|
53
|
+
const widgetRowIconGap = widget_metrics.widgetRowIconGap;
|
|
54
|
+
const widgetButtonIconGap = widget_metrics.widgetButtonIconGap;
|
|
55
|
+
const estimateTextWidth = text_model.estimateTextWidth;
|
|
56
|
+
const measureTextWidthForFont = text_model.measureTextWidthForFont;
|
|
57
|
+
const layoutTextCaretRect = text_model.layoutTextCaretRect;
|
|
58
|
+
const layoutTextSelectionRects = text_model.layoutTextSelectionRects;
|
|
59
|
+
const textEditingInkColor = widget_render_style.textEditingInkColor;
|
|
60
|
+
const textSelectionFillColor = widget_render_style.textSelectionFillColor;
|
|
61
|
+
const textSelectionTextColor = widget_render_style.textSelectionTextColor;
|
|
62
|
+
const colorFill = widget_render_style.colorFill;
|
|
63
|
+
const widgetBackgroundFill = widget_render_style.widgetBackgroundFill;
|
|
64
|
+
const widgetAccentFill = widget_render_style.widgetAccentFill;
|
|
65
|
+
const widgetBorderFill = widget_render_style.widgetBorderFill;
|
|
66
|
+
const widgetFocusRingFill = widget_render_style.widgetFocusRingFill;
|
|
67
|
+
const widgetBackgroundColor = widget_render_style.widgetBackgroundColor;
|
|
68
|
+
const widgetAccentColor = widget_render_style.widgetAccentColor;
|
|
69
|
+
const widgetBorderColor = widget_render_style.widgetBorderColor;
|
|
70
|
+
const widgetForegroundColor = widget_render_style.widgetForegroundColor;
|
|
71
|
+
const widgetAccentForegroundColor = widget_render_style.widgetAccentForegroundColor;
|
|
72
|
+
const widgetRadius = widget_render_style.widgetRadius;
|
|
73
|
+
const controlRadius = widget_render_style.controlRadius;
|
|
74
|
+
const buttonControlRadius = widget_render_style.buttonControlRadius;
|
|
75
|
+
const widgetSizedRadiusValue = widget_render_style.widgetSizedRadiusValue;
|
|
76
|
+
const controlStrokeWidth = widget_render_style.controlStrokeWidth;
|
|
77
|
+
const buttonFill = widget_render_style.buttonFill;
|
|
78
|
+
const buttonTextColorForWidget = widget_render_style.buttonTextColorForWidget;
|
|
79
|
+
const buttonBorderFill = widget_render_style.buttonBorderFill;
|
|
80
|
+
const buttonControlVisualTokens = widget_render_style.buttonControlVisualTokens;
|
|
81
|
+
const selectControlVisualTokens = widget_render_style.selectControlVisualTokens;
|
|
82
|
+
const buttonStateBackground = widget_render_style.buttonStateBackground;
|
|
83
|
+
const textInputControlVisualTokens = widget_render_style.textInputControlVisualTokens;
|
|
84
|
+
const textInputFill = widget_render_style.textInputFill;
|
|
85
|
+
const textInputBorderFill = widget_render_style.textInputBorderFill;
|
|
86
|
+
const listItemControlVisualTokens = widget_render_style.listItemControlVisualTokens;
|
|
87
|
+
const selectionControlVisualTokens = widget_render_style.selectionControlVisualTokens;
|
|
88
|
+
const surfaceControlVisualTokens = widget_render_style.surfaceControlVisualTokens;
|
|
89
|
+
const buttonStrokeWidth = widget_render_style.buttonStrokeWidth;
|
|
90
|
+
const listItemFillColor = widget_render_style.listItemFillColor;
|
|
91
|
+
const disabledWash = widget_render_style.disabledWash;
|
|
92
|
+
const washHovered = widget_render_style.washHovered;
|
|
93
|
+
|
|
94
|
+
const max_widget_text_range_rects: usize = 4;
|
|
95
|
+
|
|
96
|
+
fn pixelSnapScale(tokens: DesignTokens) ?f32 {
|
|
97
|
+
const scale = tokens.pixel_snap.scale;
|
|
98
|
+
if (!std.math.isFinite(scale) or scale <= 0) return null;
|
|
99
|
+
return scale;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
fn pixelSnapValueWithScale(value: f32, scale: f32) f32 {
|
|
103
|
+
return @round(value * scale) / scale;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
fn pixelSnapGeometryRect(tokens: DesignTokens, rect: geometry.RectF) geometry.RectF {
|
|
107
|
+
if (!tokens.pixel_snap.geometry) return rect;
|
|
108
|
+
const scale = pixelSnapScale(tokens) orelse return rect;
|
|
109
|
+
const normalized = rect.normalized();
|
|
110
|
+
const x0 = pixelSnapValueWithScale(normalized.x, scale);
|
|
111
|
+
const y0 = pixelSnapValueWithScale(normalized.y, scale);
|
|
112
|
+
const x1 = pixelSnapValueWithScale(normalized.maxX(), scale);
|
|
113
|
+
const y1 = pixelSnapValueWithScale(normalized.maxY(), scale);
|
|
114
|
+
return geometry.RectF.init(x0, y0, @max(0, x1 - x0), @max(0, y1 - y0));
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
fn pixelSnapGeometryPoint(tokens: DesignTokens, point: geometry.PointF) geometry.PointF {
|
|
118
|
+
if (!tokens.pixel_snap.geometry) return point;
|
|
119
|
+
const scale = pixelSnapScale(tokens) orelse return point;
|
|
120
|
+
return geometry.PointF.init(
|
|
121
|
+
pixelSnapValueWithScale(point.x, scale),
|
|
122
|
+
pixelSnapValueWithScale(point.y, scale),
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
fn pixelSnapTextPoint(tokens: DesignTokens, point: geometry.PointF) geometry.PointF {
|
|
127
|
+
if (!tokens.pixel_snap.text) return point;
|
|
128
|
+
const scale = pixelSnapScale(tokens) orelse return point;
|
|
129
|
+
return geometry.PointF.init(
|
|
130
|
+
pixelSnapValueWithScale(point.x, scale),
|
|
131
|
+
pixelSnapValueWithScale(point.y, scale),
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
pub fn emitButtonWidget(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!void {
|
|
136
|
+
const visual = buttonControlVisualTokens(widget, tokens);
|
|
137
|
+
const radius = buttonGroupSegmentRadius(widget, visual, tokens);
|
|
138
|
+
const text_size = widgetButtonTextSize(widget, tokens);
|
|
139
|
+
const text_inset = widgetButtonInset(widget, tokens);
|
|
140
|
+
try builder.fillRoundedRect(.{
|
|
141
|
+
.id = widgetPartId(widget.id, 1),
|
|
142
|
+
.rect = widget.frame,
|
|
143
|
+
.radius = radius,
|
|
144
|
+
.fill = buttonFill(widget, tokens),
|
|
145
|
+
});
|
|
146
|
+
try emitButtonBorder(builder, widget, tokens, radius);
|
|
147
|
+
if (widget.state.focused) try emitWidgetFocusRingForRect(builder, widget, tokens, 3, widget.frame, radius);
|
|
148
|
+
const content_color = buttonTextColorForWidget(widget, tokens);
|
|
149
|
+
const icon = icon_model.resolveOrMissing(widget.icon);
|
|
150
|
+
if (icon) |resolved| {
|
|
151
|
+
// Icon-in-button: icon (and optional label) are the button's own
|
|
152
|
+
// commands — one hit target, one tint that follows the button's
|
|
153
|
+
// enabled/disabled/variant state. A name that resolves nowhere
|
|
154
|
+
// draws the missing-icon fallback (never a silent gap).
|
|
155
|
+
const icon_extent = widgetButtonIconExtent(widget, tokens);
|
|
156
|
+
const icon_y = widget.frame.y + (widget.frame.height - icon_extent) * 0.5;
|
|
157
|
+
if (widget.text.len == 0) {
|
|
158
|
+
const icon_frame = geometry.RectF.init(
|
|
159
|
+
widget.frame.x + (widget.frame.width - icon_extent) * 0.5,
|
|
160
|
+
icon_y,
|
|
161
|
+
icon_extent,
|
|
162
|
+
icon_extent,
|
|
163
|
+
);
|
|
164
|
+
try emitVectorIcon(builder, widget.id, 5, icon_frame, content_color, resolved);
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
const gap = widgetButtonIconGap(widget, tokens);
|
|
168
|
+
const text_width = measureTextWidthForFont(tokens.text_measure, tokens.typography.buttonFontId(), widget.text, text_size);
|
|
169
|
+
const available = @max(0, widget.frame.width - text_inset * 2);
|
|
170
|
+
const content_width = @min(available, icon_extent + gap + text_width);
|
|
171
|
+
const start_x = widget.frame.x + text_inset + @max(0, (available - content_width) * 0.5);
|
|
172
|
+
// Icon slot side: leading puts the glyph before the label,
|
|
173
|
+
// trailing after it (the next-page chevron) — same centered
|
|
174
|
+
// icon+label block either way.
|
|
175
|
+
const icon_x = if (widget.icon_placement == .trailing)
|
|
176
|
+
start_x + (content_width - icon_extent)
|
|
177
|
+
else
|
|
178
|
+
start_x;
|
|
179
|
+
const text_x = if (widget.icon_placement == .trailing)
|
|
180
|
+
start_x
|
|
181
|
+
else
|
|
182
|
+
start_x + icon_extent + gap;
|
|
183
|
+
const text_max_x = if (widget.icon_placement == .trailing)
|
|
184
|
+
icon_x - gap
|
|
185
|
+
else
|
|
186
|
+
widget.frame.maxX() - text_inset;
|
|
187
|
+
const icon_frame = geometry.RectF.init(icon_x, icon_y, icon_extent, icon_extent);
|
|
188
|
+
try emitVectorIcon(builder, widget.id, 5, icon_frame, content_color, resolved);
|
|
189
|
+
const text_frame = geometry.RectF.init(
|
|
190
|
+
text_x,
|
|
191
|
+
widget.frame.y,
|
|
192
|
+
@max(1, text_max_x - text_x),
|
|
193
|
+
widget.frame.height,
|
|
194
|
+
);
|
|
195
|
+
try builder.drawText(.{
|
|
196
|
+
.id = widgetPartId(widget.id, 4),
|
|
197
|
+
// The button-label face: medium ink so the label reads as a
|
|
198
|
+
// command, not a caption (layout measured with the same id).
|
|
199
|
+
.font_id = tokens.typography.buttonFontId(),
|
|
200
|
+
.size = text_size,
|
|
201
|
+
.origin = pixelSnapTextPoint(tokens, boundedTextOrigin(text_frame, text_size, 0)),
|
|
202
|
+
.color = content_color,
|
|
203
|
+
.text = widget.text,
|
|
204
|
+
.text_layout = boundedTextLayout(text_frame, text_size, 0, .start, .none, widget.text_overflow, tokens),
|
|
205
|
+
});
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
try builder.drawText(.{
|
|
209
|
+
.id = widgetPartId(widget.id, 4),
|
|
210
|
+
// The button-label face: medium ink so the label reads as a
|
|
211
|
+
// command, not a caption (layout measured with the same id).
|
|
212
|
+
.font_id = tokens.typography.buttonFontId(),
|
|
213
|
+
.size = text_size,
|
|
214
|
+
.origin = pixelSnapTextPoint(tokens, boundedTextOrigin(widget.frame, text_size, text_inset)),
|
|
215
|
+
.color = content_color,
|
|
216
|
+
.text = widget.text,
|
|
217
|
+
.text_layout = boundedTextLayout(widget.frame, text_size, text_inset, .center, .none, widget.text_overflow, tokens),
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
pub fn emitIconButtonWidget(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!void {
|
|
222
|
+
const visual = buttonControlVisualTokens(widget, tokens);
|
|
223
|
+
const radius = buttonGroupSegmentRadius(widget, visual, tokens);
|
|
224
|
+
try builder.fillRoundedRect(.{
|
|
225
|
+
.id = widgetPartId(widget.id, 1),
|
|
226
|
+
.rect = widget.frame,
|
|
227
|
+
.radius = radius,
|
|
228
|
+
.fill = buttonFill(widget, tokens),
|
|
229
|
+
});
|
|
230
|
+
try emitButtonBorder(builder, widget, tokens, radius);
|
|
231
|
+
if (widget.state.focused) try emitWidgetFocusRingForRect(builder, widget, tokens, 15, widget.frame, radius);
|
|
232
|
+
// Real vector icons: `widget.icon` first (the explicit channel,
|
|
233
|
+
// falling back to the missing-icon glyph so a broken name shows),
|
|
234
|
+
// then an icon-name `text` (so `el(.icon_button, .{ .text = "play" })`
|
|
235
|
+
// upgrades from glyph to vector); any other text keeps the historical
|
|
236
|
+
// glyph rendering.
|
|
237
|
+
const icon = if (widget.icon.len > 0)
|
|
238
|
+
icon_model.resolveOrMissing(widget.icon)
|
|
239
|
+
else if (widget.text.len > 0)
|
|
240
|
+
icon_model.resolve(widget.text)
|
|
241
|
+
else
|
|
242
|
+
null;
|
|
243
|
+
if (icon) |resolved| {
|
|
244
|
+
const size = iconGlyphSize(widget, tokens);
|
|
245
|
+
const icon_frame = geometry.RectF.init(
|
|
246
|
+
widget.frame.x + (widget.frame.width - size) * 0.5,
|
|
247
|
+
widget.frame.y + (widget.frame.height - size) * 0.5,
|
|
248
|
+
size,
|
|
249
|
+
size,
|
|
250
|
+
);
|
|
251
|
+
try emitVectorIcon(builder, widget.id, 3, icon_frame, buttonTextColorForWidget(widget, tokens), resolved);
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
if (widget.text.len > 0) {
|
|
255
|
+
const size = iconGlyphSize(widget, tokens);
|
|
256
|
+
try builder.drawText(.{
|
|
257
|
+
.id = widgetPartId(widget.id, 3),
|
|
258
|
+
.font_id = tokens.typography.font_id,
|
|
259
|
+
.size = size,
|
|
260
|
+
.origin = pixelSnapTextPoint(tokens, centeredTextOrigin(widget.frame, widget.text, size, tokens)),
|
|
261
|
+
.color = buttonTextColorForWidget(widget, tokens),
|
|
262
|
+
.text = widget.text,
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/// The button's corner radius shaped by its group register. Segmented
|
|
268
|
+
/// (house) members collapse by position: the first segment keeps only
|
|
269
|
+
/// its leading pair, the last only its trailing pair, middles square
|
|
270
|
+
/// off, and an ungrouped button keeps all four — what makes a flush
|
|
271
|
+
/// group read as ONE bar with one corner language instead of three
|
|
272
|
+
/// chips pressed together. Detached members are exactly those chips:
|
|
273
|
+
/// each keeps all four corners.
|
|
274
|
+
fn buttonGroupSegmentRadius(widget: Widget, visual: ControlVisualTokens, tokens: DesignTokens) Radius {
|
|
275
|
+
const radius = buttonControlRadius(widget, visual, tokens);
|
|
276
|
+
if (widget_render_style.buttonInDetachedGroup(widget, tokens)) return radius;
|
|
277
|
+
return switch (widget.group_segment) {
|
|
278
|
+
.none => radius,
|
|
279
|
+
.first => .{ .top_left = radius.top_left, .bottom_left = radius.bottom_left },
|
|
280
|
+
.middle => .{},
|
|
281
|
+
.last => .{ .top_right = radius.top_right, .bottom_right = radius.bottom_right },
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/// A button's border stroke, honoring the flush-group seam rule: every
|
|
286
|
+
/// non-first segment CLIPS AWAY its left border band so each interior
|
|
287
|
+
/// boundary is painted by exactly one stroke (the left neighbor's right
|
|
288
|
+
/// edge). Overlapping the two would double-composite the translucent
|
|
289
|
+
/// dark-scheme hairline into a brighter seam. The clip starts half a
|
|
290
|
+
/// stroke inside the frame — the stroke straddles the edge — and
|
|
291
|
+
/// extends a full stroke beyond the other three sides so their outer
|
|
292
|
+
/// halves survive; the clipped top-left/bottom-left stubs sit exactly
|
|
293
|
+
/// under the neighbor's stroke band, so no gap can open. Slot 0 was
|
|
294
|
+
/// freed by the retired button shadow.
|
|
295
|
+
fn emitButtonBorder(builder: *Builder, widget: Widget, tokens: DesignTokens, radius: Radius) Error!void {
|
|
296
|
+
const stroke_width = buttonStrokeWidth(widget, tokens);
|
|
297
|
+
// Seams exist only in the segmented register — a detached chip has
|
|
298
|
+
// no shared boundary to collapse.
|
|
299
|
+
const drop_left_border = !widget_render_style.buttonInDetachedGroup(widget, tokens) and
|
|
300
|
+
(widget.group_segment == .middle or widget.group_segment == .last);
|
|
301
|
+
if (drop_left_border) {
|
|
302
|
+
try builder.pushClip(.{
|
|
303
|
+
.id = widgetPartId(widget.id, 0),
|
|
304
|
+
.rect = geometry.RectF.init(
|
|
305
|
+
widget.frame.x + stroke_width * 0.5,
|
|
306
|
+
widget.frame.y - stroke_width,
|
|
307
|
+
@max(0, widget.frame.width + stroke_width * 0.5),
|
|
308
|
+
widget.frame.height + stroke_width * 2,
|
|
309
|
+
),
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
try builder.strokeRect(.{
|
|
313
|
+
.id = widgetPartId(widget.id, 2),
|
|
314
|
+
.rect = widget.frame,
|
|
315
|
+
.radius = radius,
|
|
316
|
+
.stroke = .{
|
|
317
|
+
.fill = buttonBorderFill(widget, tokens),
|
|
318
|
+
.width = stroke_width,
|
|
319
|
+
},
|
|
320
|
+
});
|
|
321
|
+
if (drop_left_border) try builder.popClip();
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/// Draw a parsed vector icon fitted (contain, centered) into `rect`: a
|
|
325
|
+
/// transform pair maps viewBox units to device space so the parsed
|
|
326
|
+
/// elements are emitted as-is (static lifetime, packet-representable),
|
|
327
|
+
/// stroke widths scale with the icon size, and `currentColor` resolves
|
|
328
|
+
/// to `color`. Command ids are widget part slots from `first_slot` (two
|
|
329
|
+
/// per shape), so callers pick a slot range clear of their own parts.
|
|
330
|
+
pub fn emitVectorIcon(builder: *Builder, widget_id: ObjectId, first_slot: ObjectId, rect: geometry.RectF, color: Color, icon: *const svg_icon_model.Icon) Error!void {
|
|
331
|
+
const frame = rect.normalized();
|
|
332
|
+
if (frame.isEmpty()) return;
|
|
333
|
+
const box = icon.view_box;
|
|
334
|
+
const scale = @min(frame.width / box.width, frame.height / box.height);
|
|
335
|
+
if (!(scale > 0)) return;
|
|
336
|
+
const transform = Affine{
|
|
337
|
+
.a = scale,
|
|
338
|
+
.b = 0,
|
|
339
|
+
.c = 0,
|
|
340
|
+
.d = scale,
|
|
341
|
+
.tx = frame.x + (frame.width - box.width * scale) * 0.5 - box.x * scale,
|
|
342
|
+
.ty = frame.y + (frame.height - box.height * scale) * 0.5 - box.y * scale,
|
|
343
|
+
};
|
|
344
|
+
const inverse = transform.inverse() orelse return;
|
|
345
|
+
|
|
346
|
+
try builder.transform(transform);
|
|
347
|
+
for (icon.shapes, 0..) |shape, index| {
|
|
348
|
+
const elements = icon.elements[shape.start .. shape.start + shape.len];
|
|
349
|
+
if (iconPaintColor(shape.style.fill, color)) |fill_color| {
|
|
350
|
+
try builder.fillPath(.{
|
|
351
|
+
.id = widgetPartId(widget_id, first_slot + index * 2),
|
|
352
|
+
.elements = elements,
|
|
353
|
+
.fill = colorFill(fill_color),
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
if (shape.style.stroke_width > 0) {
|
|
357
|
+
if (iconPaintColor(shape.style.stroke, color)) |stroke_color| {
|
|
358
|
+
try builder.strokePath(.{
|
|
359
|
+
.id = widgetPartId(widget_id, first_slot + 1 + index * 2),
|
|
360
|
+
.elements = elements,
|
|
361
|
+
.stroke = .{ .fill = colorFill(stroke_color), .width = shape.style.stroke_width },
|
|
362
|
+
// The authored cap, not a fixed choice: the stroke
|
|
363
|
+
// icon dialect declares round caps per shape, and
|
|
364
|
+
// honoring the source keeps a butt-cap icon honest.
|
|
365
|
+
.cap = shape.style.linecap,
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
try builder.transform(inverse);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
fn iconPaintColor(paint: svg_icon_model.Paint, current: Color) ?Color {
|
|
374
|
+
return switch (paint) {
|
|
375
|
+
.none => null,
|
|
376
|
+
.current_color => current,
|
|
377
|
+
.color => |value| value,
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
pub fn emitSelectWidget(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!void {
|
|
382
|
+
const visual = selectControlVisualTokens(tokens);
|
|
383
|
+
const radius = controlRadius(widget, visual, tokens.radius.md);
|
|
384
|
+
const text_size = widgetBodyTextSize(widget, tokens);
|
|
385
|
+
const inset = widgetControlInset(widget, tokens, tokens.spacing.md);
|
|
386
|
+
// The registry chevron at the shared row-icon extent: the trigger's
|
|
387
|
+
// open-below affordance matches every other icon in the control
|
|
388
|
+
// family instead of a hand-drawn two-line glyph.
|
|
389
|
+
const chevron_size = widgetRowIconExtent(widget, tokens);
|
|
390
|
+
const chevron_extent = chevron_size + inset;
|
|
391
|
+
const text_frame = geometry.RectF.init(
|
|
392
|
+
widget.frame.x + inset,
|
|
393
|
+
widget.frame.y,
|
|
394
|
+
@max(1, widget.frame.width - inset * 2 - chevron_extent),
|
|
395
|
+
widget.frame.height,
|
|
396
|
+
);
|
|
397
|
+
const placeholder = widgetPlaceholder(widget);
|
|
398
|
+
const visible_text = if (widget.text.len > 0) widget.text else placeholder;
|
|
399
|
+
const is_placeholder = widget.text.len == 0 and placeholder.len > 0;
|
|
400
|
+
|
|
401
|
+
try builder.fillRoundedRect(.{
|
|
402
|
+
.id = widgetPartId(widget.id, 1),
|
|
403
|
+
.rect = widget.frame,
|
|
404
|
+
.radius = radius,
|
|
405
|
+
.fill = colorFill(widgetBackgroundColor(widget, buttonStateBackground(visual, widget.state.pressed, washHovered(widget), tokens.colors.surface))),
|
|
406
|
+
});
|
|
407
|
+
try builder.strokeRect(.{
|
|
408
|
+
.id = widgetPartId(widget.id, 2),
|
|
409
|
+
.rect = widget.frame,
|
|
410
|
+
.radius = radius,
|
|
411
|
+
.stroke = .{
|
|
412
|
+
.fill = widgetBorderFill(widget, visual.border orelse tokens.colors.border),
|
|
413
|
+
.width = controlStrokeWidth(widget, visual, tokens.stroke.regular),
|
|
414
|
+
},
|
|
415
|
+
});
|
|
416
|
+
if (widget.state.focused) try emitWidgetFocusRingForRect(builder, widget, tokens, 6, widget.frame, radius);
|
|
417
|
+
if (visible_text.len > 0) {
|
|
418
|
+
const text_color = if (is_placeholder)
|
|
419
|
+
widgetForegroundColor(widget, tokens, tokens.colors.text_muted)
|
|
420
|
+
else
|
|
421
|
+
widgetForegroundColor(widget, tokens, visual.foreground orelse tokens.colors.text);
|
|
422
|
+
try builder.drawText(.{
|
|
423
|
+
.id = widgetPartId(widget.id, 3),
|
|
424
|
+
.font_id = tokens.typography.font_id,
|
|
425
|
+
.size = text_size,
|
|
426
|
+
.origin = pixelSnapTextPoint(tokens, boundedTextOrigin(text_frame, text_size, 0)),
|
|
427
|
+
.color = text_color,
|
|
428
|
+
.text = visible_text,
|
|
429
|
+
.text_layout = boundedTextLayout(text_frame, text_size, 0, .start, .none, widget.text_overflow, tokens),
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
try emitSelectChevron(builder, widget, tokens, visual, inset, chevron_size);
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
fn emitSelectChevron(builder: *Builder, widget: Widget, tokens: DesignTokens, visual: ControlVisualTokens, inset: f32, chevron_size: f32) Error!void {
|
|
436
|
+
const icon = icon_model.resolve("chevron-down") orelse return;
|
|
437
|
+
const icon_frame = geometry.RectF.init(
|
|
438
|
+
widget.frame.x + widget.frame.width - inset - chevron_size,
|
|
439
|
+
widget.frame.y + (widget.frame.height - chevron_size) * 0.5,
|
|
440
|
+
chevron_size,
|
|
441
|
+
chevron_size,
|
|
442
|
+
);
|
|
443
|
+
// Muted, like the trigger's placeholder register: the chevron is an
|
|
444
|
+
// affordance, not content, so it never outweighs the chosen label.
|
|
445
|
+
const color = widgetForegroundColor(widget, tokens, visual.foreground orelse tokens.colors.text_muted);
|
|
446
|
+
try emitVectorIcon(builder, widget.id, 4, icon_frame, color, icon);
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
pub fn emitTextFieldWidget(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!void {
|
|
450
|
+
const visual = textInputControlVisualTokens(widget, tokens);
|
|
451
|
+
const radius = controlRadius(widget, visual, tokens.radius.md);
|
|
452
|
+
const text_size = widgetTextInputSize(widget, tokens);
|
|
453
|
+
const text_inset = widgetTextInputInset(widget, tokens);
|
|
454
|
+
const layout_options = widgetTextInputLayoutOptions(widget, tokens, text_size, text_inset);
|
|
455
|
+
const clip_rect = widgetTextInputClipRect(widget, tokens, text_size, text_inset, layout_options);
|
|
456
|
+
const origin = widgetTextInputOrigin(widget, tokens, text_size, text_inset, layout_options);
|
|
457
|
+
const text_color = widgetForegroundColor(widget, tokens, visual.foreground orelse tokens.colors.text);
|
|
458
|
+
const draw_text = widgetTextInputDrawText(widget, tokens, text_size, origin, text_color, layout_options);
|
|
459
|
+
const selection_range = widgetTextSelectionRange(widget);
|
|
460
|
+
const composition_range = widgetTextCompositionRange(widget);
|
|
461
|
+
const has_text_affordances = selection_range != null or composition_range != null;
|
|
462
|
+
const clips_text = widget.kind == .textarea;
|
|
463
|
+
|
|
464
|
+
try builder.fillRoundedRect(.{
|
|
465
|
+
.id = widgetPartId(widget.id, 1),
|
|
466
|
+
.rect = widget.frame,
|
|
467
|
+
.radius = radius,
|
|
468
|
+
.fill = textInputFill(widget, tokens, visual),
|
|
469
|
+
});
|
|
470
|
+
try builder.strokeRect(.{
|
|
471
|
+
.id = widgetPartId(widget.id, 2),
|
|
472
|
+
.rect = widget.frame,
|
|
473
|
+
.radius = radius,
|
|
474
|
+
.stroke = .{
|
|
475
|
+
.fill = textInputBorderFill(widget, visual, tokens.colors.border),
|
|
476
|
+
.width = controlStrokeWidth(widget, visual, tokens.stroke.regular),
|
|
477
|
+
},
|
|
478
|
+
});
|
|
479
|
+
if (widget.state.focused) try emitWidgetFocusRingForRect(builder, widget, tokens, 7, widget.frame, radius);
|
|
480
|
+
if (clips_text) try builder.pushClip(.{ .id = widgetPartId(widget.id, 16), .rect = clip_rect, .radius = radius });
|
|
481
|
+
if (selection_range) |range| {
|
|
482
|
+
if (!range.isCollapsed(widget.text.len)) {
|
|
483
|
+
try emitWidgetTextSelectionRects(builder, widget, draw_text, layout_options, range, 3, 13, max_widget_text_range_rects, tokens);
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
const placeholder = widgetPlaceholder(widget);
|
|
487
|
+
const visible_text = if (widget.text.len > 0) widget.text else placeholder;
|
|
488
|
+
if (visible_text.len > 0) {
|
|
489
|
+
var command = draw_text;
|
|
490
|
+
command.id = widgetPartId(widget.id, if (has_text_affordances) 4 else 3);
|
|
491
|
+
command.text = visible_text;
|
|
492
|
+
if (widget.text.len == 0) {
|
|
493
|
+
command.color = widgetForegroundColor(widget, tokens, tokens.colors.text_muted);
|
|
494
|
+
}
|
|
495
|
+
try builder.drawText(command);
|
|
496
|
+
}
|
|
497
|
+
if (selection_range) |range| {
|
|
498
|
+
if (!range.isCollapsed(widget.text.len)) {
|
|
499
|
+
try emitWidgetTextSelectedGlyphs(builder, widget, draw_text, layout_options, range, max_widget_text_range_rects, tokens);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
if (composition_range) |range| {
|
|
503
|
+
if (!range.isCollapsed(widget.text.len)) {
|
|
504
|
+
try emitWidgetTextCompositionLines(builder, widget, draw_text, layout_options, range, 5, 10, max_widget_text_range_rects, tokens);
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
if (widget.state.focused) {
|
|
508
|
+
if (selection_range) |range| {
|
|
509
|
+
if (range.isCollapsed(widget.text.len)) {
|
|
510
|
+
try emitWidgetTextCaret(builder, widget, draw_text, layout_options, range.start, 6, tokens);
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
if (clips_text) try builder.popClip();
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
/// The grouped input's field chrome: text-input fill and border on the
|
|
518
|
+
/// GROUP's own frame, plus the focus ring while `state.focused` — for
|
|
519
|
+
/// this kind that flag is FOCUS-WITHIN, derived by the render walk from
|
|
520
|
+
/// the focused descendant, so keyboard focus anywhere inside the group
|
|
521
|
+
/// rings the whole field. Children (the chrome-dissolved entry and the
|
|
522
|
+
/// accessory row) flow on top through the ordinary child pass.
|
|
523
|
+
pub fn emitInputGroupWidget(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!void {
|
|
524
|
+
const visual = textInputControlVisualTokens(widget, tokens);
|
|
525
|
+
const radius = controlRadius(widget, visual, tokens.radius.md);
|
|
526
|
+
try builder.fillRoundedRect(.{
|
|
527
|
+
.id = widgetPartId(widget.id, 1),
|
|
528
|
+
.rect = widget.frame,
|
|
529
|
+
.radius = radius,
|
|
530
|
+
.fill = textInputFill(widget, tokens, visual),
|
|
531
|
+
});
|
|
532
|
+
try builder.strokeRect(.{
|
|
533
|
+
.id = widgetPartId(widget.id, 2),
|
|
534
|
+
.rect = widget.frame,
|
|
535
|
+
.radius = radius,
|
|
536
|
+
.stroke = .{
|
|
537
|
+
.fill = textInputBorderFill(widget, visual, tokens.colors.border),
|
|
538
|
+
.width = controlStrokeWidth(widget, visual, tokens.stroke.regular),
|
|
539
|
+
},
|
|
540
|
+
});
|
|
541
|
+
if (widget.state.focused) try emitWidgetFocusRingForRect(builder, widget, tokens, 3, widget.frame, radius);
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
pub fn emitSearchFieldWidget(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!void {
|
|
545
|
+
const visual = textInputControlVisualTokens(widget, tokens);
|
|
546
|
+
const radius = controlRadius(widget, visual, tokens.radius.md);
|
|
547
|
+
const text_size = widgetTextInputSize(widget, tokens);
|
|
548
|
+
const icon_size = @max(8, text_size - 2);
|
|
549
|
+
const text_inset = widgetTextInputInset(widget, tokens);
|
|
550
|
+
const layout_options = widgetTextInputLayoutOptions(widget, tokens, text_size, text_inset);
|
|
551
|
+
const origin = widgetTextInputOrigin(widget, tokens, text_size, text_inset, layout_options);
|
|
552
|
+
const selection_range = widgetTextSelectionRange(widget);
|
|
553
|
+
const composition_range = widgetTextCompositionRange(widget);
|
|
554
|
+
const text_color = widgetForegroundColor(widget, tokens, visual.foreground orelse tokens.colors.text);
|
|
555
|
+
const draw_text = widgetTextInputDrawText(widget, tokens, text_size, origin, text_color, layout_options);
|
|
556
|
+
|
|
557
|
+
try builder.fillRoundedRect(.{
|
|
558
|
+
.id = widgetPartId(widget.id, 1),
|
|
559
|
+
.rect = widget.frame,
|
|
560
|
+
.radius = radius,
|
|
561
|
+
.fill = textInputFill(widget, tokens, visual),
|
|
562
|
+
});
|
|
563
|
+
try builder.strokeRect(.{
|
|
564
|
+
.id = widgetPartId(widget.id, 2),
|
|
565
|
+
.rect = widget.frame,
|
|
566
|
+
.radius = radius,
|
|
567
|
+
.stroke = .{
|
|
568
|
+
.fill = textInputBorderFill(widget, visual, tokens.colors.border),
|
|
569
|
+
.width = controlStrokeWidth(widget, visual, tokens.stroke.regular),
|
|
570
|
+
},
|
|
571
|
+
});
|
|
572
|
+
if (widget.state.focused) try emitWidgetFocusRingForRect(builder, widget, tokens, 14, widget.frame, radius);
|
|
573
|
+
try emitSearchFieldIcon(builder, widget, tokens, icon_size);
|
|
574
|
+
if (selection_range) |range| {
|
|
575
|
+
if (!range.isCollapsed(widget.text.len)) {
|
|
576
|
+
try emitWidgetTextSelectionRects(builder, widget, draw_text, layout_options, range, 8, 0, 1, tokens);
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
const placeholder = widgetPlaceholder(widget);
|
|
580
|
+
const visible_text = if (widget.text.len > 0) widget.text else placeholder;
|
|
581
|
+
if (visible_text.len > 0) {
|
|
582
|
+
var command = draw_text;
|
|
583
|
+
command.id = widgetPartId(widget.id, 9);
|
|
584
|
+
command.text = visible_text;
|
|
585
|
+
command.color = if (widget.text.len > 0) text_color else widgetForegroundColor(widget, tokens, visual.foreground orelse tokens.colors.text_muted);
|
|
586
|
+
try builder.drawText(command);
|
|
587
|
+
}
|
|
588
|
+
if (selection_range) |range| {
|
|
589
|
+
if (!range.isCollapsed(widget.text.len)) {
|
|
590
|
+
try emitWidgetTextSelectedGlyphs(builder, widget, draw_text, layout_options, range, 1, tokens);
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
if (composition_range) |range| {
|
|
594
|
+
if (!range.isCollapsed(widget.text.len)) {
|
|
595
|
+
try emitWidgetTextCompositionLines(builder, widget, draw_text, layout_options, range, 10, 0, 1, tokens);
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
if (widget.state.focused) {
|
|
599
|
+
if (selection_range) |range| {
|
|
600
|
+
if (range.isCollapsed(widget.text.len)) {
|
|
601
|
+
try emitWidgetTextCaret(builder, widget, draw_text, layout_options, range.start, 11, tokens);
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
if (widget.kind == .combobox) {
|
|
606
|
+
try emitComboboxChevron(builder, widget, tokens, visual);
|
|
607
|
+
}
|
|
608
|
+
try emitSearchFieldClearButton(builder, widget, tokens, visual);
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
/// The built-in trailing clear affordance: a small x over the trailing
|
|
612
|
+
/// inset whenever a search field holds text. Geometry comes from
|
|
613
|
+
/// `textInputClearButtonRect`, the same rect the runtime hit-tests, so
|
|
614
|
+
/// the drawn glyph and the press target can never drift apart.
|
|
615
|
+
fn emitSearchFieldClearButton(builder: *Builder, widget: Widget, tokens: DesignTokens, visual: ControlVisualTokens) Error!void {
|
|
616
|
+
const icon_frame = textInputClearButtonRect(widget, tokens) orelse return;
|
|
617
|
+
const icon = icon_model.resolve("x") orelse return;
|
|
618
|
+
const color = widgetForegroundColor(widget, tokens, visual.foreground orelse tokens.colors.text_muted);
|
|
619
|
+
try emitVectorIcon(builder, widget.id, 15, icon_frame, color, icon);
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
/// The combobox trigger's open-below affordance: the registry
|
|
623
|
+
/// `chevron-down` icon at the shared row-icon extent, the same
|
|
624
|
+
/// treatment the select trigger draws — one icon register across the
|
|
625
|
+
/// control family instead of a hand-drawn two-line glyph. Muted, like
|
|
626
|
+
/// the placeholder register: the chevron is an affordance, not
|
|
627
|
+
/// content, so it never outweighs the entered text. Slot 12 starts the
|
|
628
|
+
/// icon's shape range (fill/stroke pair), clear of the field chrome
|
|
629
|
+
/// (1..11), the focus ring (14), and the clear affordance (15).
|
|
630
|
+
fn emitComboboxChevron(builder: *Builder, widget: Widget, tokens: DesignTokens, visual: ControlVisualTokens) Error!void {
|
|
631
|
+
const icon = icon_model.resolve("chevron-down") orelse return;
|
|
632
|
+
const inset = widgetControlInset(widget, tokens, tokens.spacing.md);
|
|
633
|
+
const chevron_size = widgetRowIconExtent(widget, tokens);
|
|
634
|
+
const icon_frame = geometry.RectF.init(
|
|
635
|
+
widget.frame.x + widget.frame.width - inset - chevron_size,
|
|
636
|
+
widget.frame.y + (widget.frame.height - chevron_size) * 0.5,
|
|
637
|
+
chevron_size,
|
|
638
|
+
chevron_size,
|
|
639
|
+
);
|
|
640
|
+
const color = widgetForegroundColor(widget, tokens, visual.foreground orelse tokens.colors.text_muted);
|
|
641
|
+
try emitVectorIcon(builder, widget.id, 12, icon_frame, color, icon);
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
fn emitSearchFieldIcon(builder: *Builder, widget: Widget, tokens: DesignTokens, icon_size: f32) Error!void {
|
|
645
|
+
// The registry `search` icon (a true circle lowered to kappa cubics
|
|
646
|
+
// plus a handle), not a hand-drawn line box: the glass stays round at
|
|
647
|
+
// every size because the circle flattens in viewBox units before the
|
|
648
|
+
// icon transform scales it down, so 12-14px fields keep real arcs.
|
|
649
|
+
const icon = icon_model.resolve("search") orelse return;
|
|
650
|
+
const left = widget.frame.x + widgetControlInset(widget, tokens, tokens.spacing.md);
|
|
651
|
+
const top = widget.frame.y + @max(0, (widget.frame.height - icon_size) * 0.5);
|
|
652
|
+
const icon_frame = geometry.RectF.init(left, top, icon_size, icon_size);
|
|
653
|
+
const visual = textInputControlVisualTokens(widget, tokens);
|
|
654
|
+
const color = widgetForegroundColor(widget, tokens, visual.foreground orelse tokens.colors.text_muted);
|
|
655
|
+
try emitVectorIcon(builder, widget.id, 3, icon_frame, color, icon);
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
pub fn emitTooltipWidget(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!void {
|
|
659
|
+
const visual = surfaceControlVisualTokens(widget, tokens);
|
|
660
|
+
const radius = controlRadius(widget, visual, tokens.radius.md);
|
|
661
|
+
const shadow_token = tokens.shadow.sm;
|
|
662
|
+
if (shadow_token.y != 0 or shadow_token.blur != 0 or shadow_token.spread != 0) {
|
|
663
|
+
try builder.shadow(.{
|
|
664
|
+
.id = widgetPartId(widget.id, 1),
|
|
665
|
+
.rect = widget.frame,
|
|
666
|
+
.radius = radius,
|
|
667
|
+
.offset = .{ .dx = 0, .dy = shadow_token.y },
|
|
668
|
+
.blur = shadow_token.blur,
|
|
669
|
+
.spread = shadow_token.spread,
|
|
670
|
+
.color = tokens.colors.shadow,
|
|
671
|
+
});
|
|
672
|
+
}
|
|
673
|
+
try builder.fillRoundedRect(.{
|
|
674
|
+
.id = widgetPartId(widget.id, 2),
|
|
675
|
+
.rect = widget.frame,
|
|
676
|
+
.radius = radius,
|
|
677
|
+
.fill = widgetAccentFill(widget, buttonStateBackground(visual, widget.state.pressed or widget.state.selected, washHovered(widget), tokens.colors.accent)),
|
|
678
|
+
});
|
|
679
|
+
if (widget.text.len > 0) {
|
|
680
|
+
const text_size = widgetLabelTextSize(widget, tokens);
|
|
681
|
+
const text_inset = widgetControlInset(widget, tokens, tokens.spacing.sm);
|
|
682
|
+
try builder.drawText(.{
|
|
683
|
+
.id = widgetPartId(widget.id, 3),
|
|
684
|
+
.font_id = tokens.typography.font_id,
|
|
685
|
+
.size = text_size,
|
|
686
|
+
.origin = pixelSnapTextPoint(tokens, boundedTextOrigin(widget.frame, text_size, text_inset)),
|
|
687
|
+
.color = widgetAccentForegroundColor(widget, tokens, visual.foreground orelse tokens.colors.accent_text),
|
|
688
|
+
.text = widget.text,
|
|
689
|
+
.text_layout = boundedTextLayout(widget.frame, text_size, text_inset, .start, .none, widget.text_overflow, tokens),
|
|
690
|
+
});
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
/// The open menu's option row. Deliberately NOT the list-item emitter:
|
|
695
|
+
/// a menu row never draws a focus outline — while the menu is open, the
|
|
696
|
+
/// keyboard's position paints the same full-row wash hover does, and
|
|
697
|
+
/// the row the app has committed carries a trailing checkmark instead
|
|
698
|
+
/// of a wash. Highlight (where the keyboard is) and checkmark (what is
|
|
699
|
+
/// committed) stay independent: arrowing away from the committed row
|
|
700
|
+
/// moves the wash while its checkmark stays put.
|
|
701
|
+
pub fn emitMenuItemWidget(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!void {
|
|
702
|
+
const visual = listItemControlVisualTokens(widget, tokens);
|
|
703
|
+
const radius = controlRadius(widget, visual, tokens.radius.sm);
|
|
704
|
+
const wash = menuItemWashColor(widget, tokens, visual);
|
|
705
|
+
if (wash.a > 0) {
|
|
706
|
+
try builder.fillRoundedRect(.{
|
|
707
|
+
.id = widgetPartId(widget.id, 1),
|
|
708
|
+
.rect = widget.frame,
|
|
709
|
+
.radius = radius,
|
|
710
|
+
.fill = widgetBackgroundFill(widget, wash),
|
|
711
|
+
});
|
|
712
|
+
}
|
|
713
|
+
const text_size = widgetBodyTextSize(widget, tokens);
|
|
714
|
+
const text_inset = widgetControlInset(widget, tokens, tokens.spacing.md);
|
|
715
|
+
const content_color = widgetForegroundColor(widget, tokens, visual.foreground orelse tokens.colors.text);
|
|
716
|
+
// EVERY row reserves the trailing checkmark slot, committed or not,
|
|
717
|
+
// so labels measure and elide identically and moving the commit
|
|
718
|
+
// never reflows a row's text.
|
|
719
|
+
const check_extent = widgetRowIconExtent(widget, tokens);
|
|
720
|
+
const check_gap = widgetRowIconGap(widget, tokens);
|
|
721
|
+
var text_frame = geometry.RectF.init(
|
|
722
|
+
widget.frame.x,
|
|
723
|
+
widget.frame.y,
|
|
724
|
+
@max(1, widget.frame.width - check_extent - check_gap),
|
|
725
|
+
widget.frame.height,
|
|
726
|
+
);
|
|
727
|
+
const icon = icon_model.resolveOrMissing(widget.icon);
|
|
728
|
+
if (icon) |resolved| {
|
|
729
|
+
// Leading icon slot: shared row metrics, one tint with the
|
|
730
|
+
// label — the same contract list rows draw with.
|
|
731
|
+
const icon_extent = widgetRowIconExtent(widget, tokens);
|
|
732
|
+
const icon_frame = geometry.RectF.init(
|
|
733
|
+
widget.frame.x + text_inset,
|
|
734
|
+
widget.frame.y + (widget.frame.height - icon_extent) * 0.5,
|
|
735
|
+
icon_extent,
|
|
736
|
+
icon_extent,
|
|
737
|
+
);
|
|
738
|
+
try emitVectorIcon(builder, widget.id, 4, icon_frame, content_color, resolved);
|
|
739
|
+
const shift = icon_extent + widgetRowIconGap(widget, tokens);
|
|
740
|
+
text_frame = geometry.RectF.init(
|
|
741
|
+
text_frame.x + shift,
|
|
742
|
+
text_frame.y,
|
|
743
|
+
@max(1, text_frame.width - shift),
|
|
744
|
+
text_frame.height,
|
|
745
|
+
);
|
|
746
|
+
}
|
|
747
|
+
try builder.drawText(.{
|
|
748
|
+
.id = widgetPartId(widget.id, 3),
|
|
749
|
+
.font_id = tokens.typography.font_id,
|
|
750
|
+
.size = text_size,
|
|
751
|
+
.origin = pixelSnapTextPoint(tokens, boundedTextOrigin(text_frame, text_size, text_inset)),
|
|
752
|
+
.color = content_color,
|
|
753
|
+
.text = widget.text,
|
|
754
|
+
.text_layout = boundedTextLayout(text_frame, text_size, text_inset, .start, .none, widget.text_overflow, tokens),
|
|
755
|
+
});
|
|
756
|
+
if (widget.state.selected) {
|
|
757
|
+
if (icon_model.resolve("check")) |check_icon| {
|
|
758
|
+
// The commit marker: right-aligned inside the reserved slot,
|
|
759
|
+
// in the row's own content tint. Slots 12/13 sit clear of
|
|
760
|
+
// the leading icon's shape range (4..11).
|
|
761
|
+
const check_frame = geometry.RectF.init(
|
|
762
|
+
widget.frame.maxX() - text_inset - check_extent,
|
|
763
|
+
widget.frame.y + (widget.frame.height - check_extent) * 0.5,
|
|
764
|
+
check_extent,
|
|
765
|
+
check_extent,
|
|
766
|
+
);
|
|
767
|
+
try emitVectorIcon(builder, widget.id, 12, check_frame, content_color, check_icon);
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
/// Menu rows tint by ATTENTION, never by commit: the keyboard's active
|
|
773
|
+
/// row and the hovered row share the hover wash, a press deepens it,
|
|
774
|
+
/// and the committed row stays untinted (its marker is the trailing
|
|
775
|
+
/// checkmark). `selected` deliberately does not reach the fill, and no
|
|
776
|
+
/// state draws a focus ring. The quiet-surface knob silences only the
|
|
777
|
+
/// pointer half of the attention wash — the keyboard's active row still
|
|
778
|
+
/// washes, because inside a menu that wash IS the keyboard affordance.
|
|
779
|
+
fn menuItemWashColor(widget: Widget, tokens: DesignTokens, visual: ControlVisualTokens) Color {
|
|
780
|
+
if (widget.state.pressed) return widget_render_style.controlStateBackground(visual, true, true, false, tokens.colors.surface_pressed);
|
|
781
|
+
if (widget.state.focused or washHovered(widget)) return buttonStateBackground(visual, false, true, tokens.colors.surface_subtle);
|
|
782
|
+
return widget_render_style.transparentColor();
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
pub fn emitListItemWidget(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!void {
|
|
786
|
+
const visual = listItemControlVisualTokens(widget, tokens);
|
|
787
|
+
const radius = controlRadius(widget, visual, tokens.radius.md);
|
|
788
|
+
const fill = listItemFillColor(widget, tokens, widget.state);
|
|
789
|
+
if (fill.a > 0) {
|
|
790
|
+
try builder.fillRoundedRect(.{
|
|
791
|
+
.id = widgetPartId(widget.id, 1),
|
|
792
|
+
.rect = widget.frame,
|
|
793
|
+
.radius = radius,
|
|
794
|
+
.fill = widgetBackgroundFill(widget, fill),
|
|
795
|
+
});
|
|
796
|
+
}
|
|
797
|
+
if (widget.state.focused) try emitWidgetFocusRing(builder, widget, tokens, 2);
|
|
798
|
+
const text_size = widgetBodyTextSize(widget, tokens);
|
|
799
|
+
const text_inset = widgetControlInset(widget, tokens, tokens.spacing.md);
|
|
800
|
+
const content_color = widgetForegroundColor(widget, tokens, visual.foreground orelse tokens.colors.text);
|
|
801
|
+
// Leading icon slot: drawn as part of the row's own rendering
|
|
802
|
+
// so icon + label are one hit target with one tint, mirroring the
|
|
803
|
+
// button's inline icon. The label shifts right by the shared metric
|
|
804
|
+
// the intrinsic size also accounts for.
|
|
805
|
+
var text_frame = widget.frame;
|
|
806
|
+
const icon = icon_model.resolveOrMissing(widget.icon);
|
|
807
|
+
if (icon) |resolved| {
|
|
808
|
+
const icon_extent = widgetRowIconExtent(widget, tokens);
|
|
809
|
+
const icon_frame = geometry.RectF.init(
|
|
810
|
+
widget.frame.x + text_inset,
|
|
811
|
+
widget.frame.y + (widget.frame.height - icon_extent) * 0.5,
|
|
812
|
+
icon_extent,
|
|
813
|
+
icon_extent,
|
|
814
|
+
);
|
|
815
|
+
try emitVectorIcon(builder, widget.id, 4, icon_frame, content_color, resolved);
|
|
816
|
+
const shift = icon_extent + widgetRowIconGap(widget, tokens);
|
|
817
|
+
text_frame = geometry.RectF.init(
|
|
818
|
+
widget.frame.x + shift,
|
|
819
|
+
widget.frame.y,
|
|
820
|
+
@max(1, widget.frame.width - shift),
|
|
821
|
+
widget.frame.height,
|
|
822
|
+
);
|
|
823
|
+
}
|
|
824
|
+
try builder.drawText(.{
|
|
825
|
+
.id = widgetPartId(widget.id, 3),
|
|
826
|
+
.font_id = tokens.typography.font_id,
|
|
827
|
+
.size = text_size,
|
|
828
|
+
.origin = pixelSnapTextPoint(tokens, boundedTextOrigin(text_frame, text_size, text_inset)),
|
|
829
|
+
.color = content_color,
|
|
830
|
+
.text = widget.text,
|
|
831
|
+
.text_layout = boundedTextLayout(text_frame, text_size, text_inset, .start, .none, widget.text_overflow, tokens),
|
|
832
|
+
});
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
pub fn emitDataCellWidget(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!void {
|
|
836
|
+
const visual = try emitDataCellWidgetChrome(builder, widget, tokens);
|
|
837
|
+
if (widget.text.len > 0) {
|
|
838
|
+
const text_size = widgetBodyTextSize(widget, tokens);
|
|
839
|
+
// Tight cell padding on the comfortable row band — the table
|
|
840
|
+
// register — and the cell honors its authored alignment, so
|
|
841
|
+
// numeric columns right-align with `text-alignment="end"`.
|
|
842
|
+
const text_inset = widgetControlInset(widget, tokens, tokens.spacing.sm);
|
|
843
|
+
try builder.drawText(.{
|
|
844
|
+
.id = widgetPartId(widget.id, 4),
|
|
845
|
+
.font_id = tokens.typography.font_id,
|
|
846
|
+
.size = text_size,
|
|
847
|
+
.origin = pixelSnapTextPoint(tokens, boundedTextOrigin(widget.frame, text_size, text_inset)),
|
|
848
|
+
.color = widgetForegroundColor(widget, tokens, visual.foreground orelse tokens.colors.text),
|
|
849
|
+
.text = widget.text,
|
|
850
|
+
.text_layout = boundedTextLayout(widget.frame, text_size, text_inset, widget.text_alignment, .none, widget.text_overflow, tokens),
|
|
851
|
+
});
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
/// The cell's fill, border, and focus ring — shared between the classic
|
|
856
|
+
/// single-line cell and span-carrying cells (whose runs the span
|
|
857
|
+
/// paragraph emitter draws). Returns the visual tokens so callers can
|
|
858
|
+
/// reuse the resolved foreground.
|
|
859
|
+
pub fn emitDataCellWidgetChrome(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!ControlVisualTokens {
|
|
860
|
+
const visual = listItemControlVisualTokens(widget, tokens);
|
|
861
|
+
const state_fill = listItemFillColor(widget, tokens, widget.state);
|
|
862
|
+
if (state_fill.a > 0) {
|
|
863
|
+
try builder.fillRect(.{
|
|
864
|
+
.id = widgetPartId(widget.id, 1),
|
|
865
|
+
.rect = widget.frame,
|
|
866
|
+
.fill = widgetBackgroundFill(widget, state_fill),
|
|
867
|
+
});
|
|
868
|
+
}
|
|
869
|
+
// Borderless by default: the table's chrome is its hairline ROW
|
|
870
|
+
// separators, never a grid of cell boxes. A theme or per-widget
|
|
871
|
+
// border/stroke opts a cell back into an edge.
|
|
872
|
+
const wants_stroke = widget.style.border != null or visual.border != null or widget.style.stroke_width != null or visual.stroke_width != null;
|
|
873
|
+
if (wants_stroke) {
|
|
874
|
+
try builder.strokeRect(.{
|
|
875
|
+
.id = widgetPartId(widget.id, 2),
|
|
876
|
+
.rect = widget.frame,
|
|
877
|
+
.stroke = .{
|
|
878
|
+
.fill = widgetBorderFill(widget, visual.border orelse tokens.colors.border),
|
|
879
|
+
.width = controlStrokeWidth(widget, visual, tokens.stroke.hairline),
|
|
880
|
+
},
|
|
881
|
+
});
|
|
882
|
+
}
|
|
883
|
+
if (widget.state.focused) try emitWidgetFocusRing(builder, widget, tokens, 3);
|
|
884
|
+
return visual;
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
/// The radius for a segmented trigger. Triggers sit `tabs_list_inset`
|
|
888
|
+
/// inside the TabsList container, so a corner that hugs the container's
|
|
889
|
+
/// curve needs radius = container radius − inset; reusing a full-size
|
|
890
|
+
/// control radius makes the selected segment's corners bulge past the
|
|
891
|
+
/// container's rounding. An explicit style or themed trigger radius
|
|
892
|
+
/// still wins over the concentric default.
|
|
893
|
+
fn segmentedTriggerRadius(widget: Widget, visual: ControlVisualTokens, tokens: DesignTokens) Radius {
|
|
894
|
+
if (widget.style.radius) |radius| return Radius.all(@max(0, radius));
|
|
895
|
+
if (visual.radius) |radius| return Radius.all(@max(0, widgetSizedRadiusValue(widget, radius)));
|
|
896
|
+
const container = tokens.controls.tabs.radius orelse tokens.radius.lg;
|
|
897
|
+
return Radius.all(@max(0, widgetSizedRadiusValue(widget, container) - widget_model.tabs_list_inset));
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
/// The selected-tab bar for the `.underline` tab register: a short
|
|
901
|
+
/// filled rect hugging the trigger's label (measured width plus a 2px
|
|
902
|
+
/// shoulder each side — the label's own breathing room, mirroring the
|
|
903
|
+
/// house reference's tab padding), sunk to the BOTTOM of the TabsList
|
|
904
|
+
/// container. The trigger sits `tabs_list_inset` above the container's
|
|
905
|
+
/// edge, so the bar extends past the trigger frame by exactly that
|
|
906
|
+
/// inset and covers the strip hairline — the underline and the track
|
|
907
|
+
/// line meet, which is the register's signature. Null in the `.pill`
|
|
908
|
+
/// register; shared with invalidation so damage covers the overhang.
|
|
909
|
+
pub fn segmentedControlUnderlineRect(widget: Widget, tokens: DesignTokens) ?geometry.RectF {
|
|
910
|
+
if (tokens.controls.tabs_indicator != .underline) return null;
|
|
911
|
+
const frame = widget.frame.normalized();
|
|
912
|
+
if (frame.isEmpty()) return null;
|
|
913
|
+
const thickness = @min(frame.height, widgetSizedDensityValue(widget, tokens, tokens.metrics.tabs_indicator_thickness));
|
|
914
|
+
const text_size = widgetLabelTextSize(widget, tokens);
|
|
915
|
+
const text_width = measureTextWidthForFont(tokens.text_measure, tokens.typography.font_id, widget.text, text_size);
|
|
916
|
+
// An icon-only or empty trigger underlines its full width — there
|
|
917
|
+
// is no label to hug.
|
|
918
|
+
const bar_width = if (text_width > 0) @min(frame.width, text_width + 4) else frame.width;
|
|
919
|
+
return pixelSnapGeometryRect(tokens, geometry.RectF.init(
|
|
920
|
+
frame.x + (frame.width - bar_width) * 0.5,
|
|
921
|
+
frame.maxY() + widget_model.tabs_list_inset - thickness,
|
|
922
|
+
bar_width,
|
|
923
|
+
thickness,
|
|
924
|
+
));
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
pub fn emitSegmentedControlWidget(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!void {
|
|
928
|
+
const selected = widget.state.selected or widget.value >= 0.5;
|
|
929
|
+
const visual = selectionControlVisualTokens(widget, tokens);
|
|
930
|
+
const radius = segmentedTriggerRadius(widget, visual, tokens);
|
|
931
|
+
const text_size = widgetLabelTextSize(widget, tokens);
|
|
932
|
+
const text_inset = widgetControlInset(widget, tokens, tokens.spacing.md);
|
|
933
|
+
switch (tokens.controls.tabs_indicator) {
|
|
934
|
+
// The house tab-trigger treatment: the active segment lifts to
|
|
935
|
+
// the page surface with a hairline border; inactive segments
|
|
936
|
+
// stay TRANSPARENT with muted text, so the muted TabsList
|
|
937
|
+
// container behind them (`emitTabsListWidgetChrome`) provides
|
|
938
|
+
// the wash — selection reads by elevation, not by an accent
|
|
939
|
+
// fill.
|
|
940
|
+
.pill => {
|
|
941
|
+
if (selected) {
|
|
942
|
+
try builder.fillRoundedRect(.{
|
|
943
|
+
.id = widgetPartId(widget.id, 1),
|
|
944
|
+
.rect = widget.frame,
|
|
945
|
+
.radius = radius,
|
|
946
|
+
.fill = colorFill(widgetAccentColor(widget, visual.active_background orelse tokens.colors.surface)),
|
|
947
|
+
});
|
|
948
|
+
} else if (widget.style.background orelse visual.background) |background| {
|
|
949
|
+
try builder.fillRoundedRect(.{
|
|
950
|
+
.id = widgetPartId(widget.id, 1),
|
|
951
|
+
.rect = widget.frame,
|
|
952
|
+
.radius = radius,
|
|
953
|
+
.fill = colorFill(widgetBackgroundColor(widget, buttonStateBackground(visual, false, washHovered(widget), background))),
|
|
954
|
+
});
|
|
955
|
+
}
|
|
956
|
+
if (selected) {
|
|
957
|
+
try builder.strokeRect(.{
|
|
958
|
+
.id = widgetPartId(widget.id, 2),
|
|
959
|
+
.rect = widget.frame,
|
|
960
|
+
.radius = radius,
|
|
961
|
+
.stroke = .{
|
|
962
|
+
.fill = widgetBorderFill(widget, visual.border orelse tokens.colors.border),
|
|
963
|
+
.width = controlStrokeWidth(widget, visual, tokens.stroke.regular),
|
|
964
|
+
},
|
|
965
|
+
});
|
|
966
|
+
}
|
|
967
|
+
},
|
|
968
|
+
// The underline treatment: triggers are bare text — no pill, no
|
|
969
|
+
// border — and the active one carries a short bar under its
|
|
970
|
+
// label in the primary ink. State speaks through TYPE (active
|
|
971
|
+
// ink vs muted) plus the bar, never through a fill.
|
|
972
|
+
.underline => {
|
|
973
|
+
if (widget.style.background orelse visual.background) |background| {
|
|
974
|
+
try builder.fillRoundedRect(.{
|
|
975
|
+
.id = widgetPartId(widget.id, 1),
|
|
976
|
+
.rect = widget.frame,
|
|
977
|
+
.radius = radius,
|
|
978
|
+
.fill = colorFill(widgetBackgroundColor(widget, buttonStateBackground(visual, false, washHovered(widget), background))),
|
|
979
|
+
});
|
|
980
|
+
}
|
|
981
|
+
if (selected) {
|
|
982
|
+
if (segmentedControlUnderlineRect(widget, tokens)) |bar| {
|
|
983
|
+
try builder.fillRect(.{
|
|
984
|
+
.id = widgetPartId(widget.id, 2),
|
|
985
|
+
.rect = bar,
|
|
986
|
+
.fill = colorFill(widgetAccentColor(widget, visual.active_background orelse tokens.colors.text)),
|
|
987
|
+
});
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
},
|
|
991
|
+
}
|
|
992
|
+
if (widget.state.focused) try emitWidgetFocusRingForRect(builder, widget, tokens, 4, widget.frame, radius);
|
|
993
|
+
// Inactive labels sit in the muted ink; in the underline register a
|
|
994
|
+
// hovered (enabled) trigger previews the active ink — the register
|
|
995
|
+
// has no hover WASH, so the type itself is the hover feedback.
|
|
996
|
+
const active_ink = widgetForegroundColor(widget, tokens, visual.foreground orelse tokens.colors.text);
|
|
997
|
+
const hover_preview = tokens.controls.tabs_indicator == .underline and widget.state.hovered and !widget.state.disabled;
|
|
998
|
+
try builder.drawText(.{
|
|
999
|
+
.id = widgetPartId(widget.id, 3),
|
|
1000
|
+
.font_id = tokens.typography.font_id,
|
|
1001
|
+
.size = text_size,
|
|
1002
|
+
.origin = pixelSnapTextPoint(tokens, boundedTextOrigin(widget.frame, text_size, text_inset)),
|
|
1003
|
+
.color = if (selected or hover_preview) active_ink else widgetForegroundColor(widget, tokens, visual.foreground orelse tokens.colors.text_muted),
|
|
1004
|
+
.text = widget.text,
|
|
1005
|
+
.text_layout = boundedTextLayout(widget.frame, text_size, text_inset, .center, .none, widget.text_overflow, tokens),
|
|
1006
|
+
});
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
pub fn emitCheckboxWidget(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!void {
|
|
1010
|
+
const visual = selectionControlVisualTokens(widget, tokens);
|
|
1011
|
+
const box = checkboxWidgetBoxRect(widget, tokens);
|
|
1012
|
+
const selected = booleanControlSelected(widget);
|
|
1013
|
+
// A literal 4px default, not the sm radius token: on a 16px box the
|
|
1014
|
+
// 6px token reads nearly round; 4px keeps the square-with-softened-
|
|
1015
|
+
// corners shape the checkbox is known by.
|
|
1016
|
+
const radius = controlRadius(widget, visual, 4);
|
|
1017
|
+
try builder.fillRoundedRect(.{
|
|
1018
|
+
.id = widgetPartId(widget.id, 1),
|
|
1019
|
+
.rect = box,
|
|
1020
|
+
.radius = radius,
|
|
1021
|
+
.fill = if (selected)
|
|
1022
|
+
colorFill(disabledWash(widgetAccentColor(widget, visual.active_background orelse tokens.colors.accent), widget.state.disabled, tokens.states.disabled_alpha))
|
|
1023
|
+
else
|
|
1024
|
+
colorFill(widgetBackgroundColor(widget, buttonStateBackground(visual, false, washHovered(widget), tokens.colors.surface))),
|
|
1025
|
+
});
|
|
1026
|
+
try builder.strokeRect(.{
|
|
1027
|
+
.id = widgetPartId(widget.id, 2),
|
|
1028
|
+
.rect = box,
|
|
1029
|
+
.radius = radius,
|
|
1030
|
+
.stroke = .{
|
|
1031
|
+
.fill = colorFill(disabledWash(if (selected) widgetAccentColor(widget, visual.border orelse visual.active_background orelse tokens.colors.accent) else widgetBorderColor(widget, visual.border orelse tokens.colors.border), widget.state.disabled, tokens.states.disabled_alpha)),
|
|
1032
|
+
.width = controlStrokeWidth(widget, visual, tokens.stroke.regular),
|
|
1033
|
+
},
|
|
1034
|
+
});
|
|
1035
|
+
if (widget.state.focused) try emitWidgetFocusRingForRect(builder, widget, tokens, 3, box, radius);
|
|
1036
|
+
if (selected) {
|
|
1037
|
+
// The check keeps the accent-foreground tint even when disabled
|
|
1038
|
+
// (washed to half strength with the box) — swapping it to the
|
|
1039
|
+
// muted text gray would read muddy on the washed accent fill.
|
|
1040
|
+
const check_color = disabledWash(widget.style.accent_foreground orelse visual.foreground orelse tokens.colors.accent_text, widget.state.disabled, tokens.states.disabled_alpha);
|
|
1041
|
+
const left = pixelSnapGeometryPoint(tokens, geometry.PointF.init(box.x + box.width * 0.26, box.y + box.height * 0.54));
|
|
1042
|
+
const mid = pixelSnapGeometryPoint(tokens, geometry.PointF.init(box.x + box.width * 0.43, box.y + box.height * 0.70));
|
|
1043
|
+
const right = pixelSnapGeometryPoint(tokens, geometry.PointF.init(box.x + box.width * 0.76, box.y + box.height * 0.32));
|
|
1044
|
+
try builder.drawLine(.{
|
|
1045
|
+
.id = widgetPartId(widget.id, 4),
|
|
1046
|
+
.from = left,
|
|
1047
|
+
.to = mid,
|
|
1048
|
+
.stroke = .{ .fill = colorFill(check_color), .width = 2 },
|
|
1049
|
+
});
|
|
1050
|
+
try builder.drawLine(.{
|
|
1051
|
+
.id = widgetPartId(widget.id, 5),
|
|
1052
|
+
.from = mid,
|
|
1053
|
+
.to = right,
|
|
1054
|
+
.stroke = .{ .fill = colorFill(check_color), .width = 2 },
|
|
1055
|
+
});
|
|
1056
|
+
}
|
|
1057
|
+
try emitControlLabelWithColor(builder, widget, tokens, box.x + box.width + widgetControlInset(widget, tokens, tokens.spacing.sm), 6, visual.foreground orelse tokens.colors.text);
|
|
1058
|
+
}
|
|
1059
|
+
|
|
1060
|
+
pub fn emitRadioWidget(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!void {
|
|
1061
|
+
const visual = selectionControlVisualTokens(widget, tokens);
|
|
1062
|
+
const circle = radioWidgetCircleRect(widget, tokens);
|
|
1063
|
+
const selected = booleanControlSelected(widget);
|
|
1064
|
+
const radius = controlRadius(widget, visual, circle.height * 0.5);
|
|
1065
|
+
try builder.fillRoundedRect(.{
|
|
1066
|
+
.id = widgetPartId(widget.id, 1),
|
|
1067
|
+
.rect = circle,
|
|
1068
|
+
.radius = radius,
|
|
1069
|
+
.fill = colorFill(widgetBackgroundColor(widget, buttonStateBackground(visual, false, washHovered(widget), tokens.colors.surface))),
|
|
1070
|
+
});
|
|
1071
|
+
try builder.strokeRect(.{
|
|
1072
|
+
.id = widgetPartId(widget.id, 2),
|
|
1073
|
+
.rect = circle,
|
|
1074
|
+
.radius = radius,
|
|
1075
|
+
// The border stays on the input hairline even when selected —
|
|
1076
|
+
// the primary-colored dot alone carries the checked state.
|
|
1077
|
+
.stroke = .{
|
|
1078
|
+
.fill = colorFill(disabledWash(widgetBorderColor(widget, visual.border orelse tokens.colors.border), widget.state.disabled, tokens.states.disabled_alpha)),
|
|
1079
|
+
.width = controlStrokeWidth(widget, visual, tokens.stroke.regular),
|
|
1080
|
+
},
|
|
1081
|
+
});
|
|
1082
|
+
if (widget.state.focused) try emitWidgetFocusRingForRect(builder, widget, tokens, 3, circle, radius);
|
|
1083
|
+
if (selected) {
|
|
1084
|
+
const dot_size = @max(0, circle.height * 0.5);
|
|
1085
|
+
const dot = pixelSnapGeometryRect(tokens, geometry.RectF.init(
|
|
1086
|
+
circle.x + (circle.width - dot_size) * 0.5,
|
|
1087
|
+
circle.y + (circle.height - dot_size) * 0.5,
|
|
1088
|
+
dot_size,
|
|
1089
|
+
dot_size,
|
|
1090
|
+
));
|
|
1091
|
+
try builder.fillRoundedRect(.{
|
|
1092
|
+
.id = widgetPartId(widget.id, 4),
|
|
1093
|
+
.rect = dot,
|
|
1094
|
+
.radius = Radius.all(dot.height * 0.5),
|
|
1095
|
+
.fill = colorFill(disabledWash(widgetAccentColor(widget, visual.active_background orelse tokens.colors.accent), widget.state.disabled, tokens.states.disabled_alpha)),
|
|
1096
|
+
});
|
|
1097
|
+
}
|
|
1098
|
+
try emitControlLabelWithColor(builder, widget, tokens, circle.x + circle.width + widgetControlInset(widget, tokens, tokens.spacing.sm), 5, visual.foreground orelse tokens.colors.text);
|
|
1099
|
+
}
|
|
1100
|
+
|
|
1101
|
+
pub fn emitToggleWidget(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!void {
|
|
1102
|
+
const selected = booleanControlSelected(widget);
|
|
1103
|
+
const visual = selectionControlVisualTokens(widget, tokens);
|
|
1104
|
+
const knob_inset = widgetSizedDensityValue(widget, tokens, 2);
|
|
1105
|
+
const track = toggleWidgetTrackRect(widget, tokens);
|
|
1106
|
+
const track_radius = controlRadius(widget, visual, track.height * 0.5);
|
|
1107
|
+
const knob_size = @max(0, track.height - knob_inset * 2);
|
|
1108
|
+
const knob_x = if (selected)
|
|
1109
|
+
track.x + track.width - knob_size - knob_inset
|
|
1110
|
+
else
|
|
1111
|
+
track.x + knob_inset;
|
|
1112
|
+
const knob = pixelSnapGeometryRect(tokens, geometry.RectF.init(knob_x, track.y + knob_inset, knob_size, knob_size));
|
|
1113
|
+
|
|
1114
|
+
try builder.fillRoundedRect(.{
|
|
1115
|
+
.id = widgetPartId(widget.id, 1),
|
|
1116
|
+
.rect = track,
|
|
1117
|
+
.radius = track_radius,
|
|
1118
|
+
.fill = if (selected)
|
|
1119
|
+
colorFill(disabledWash(widgetAccentColor(widget, visual.active_background orelse tokens.colors.accent), widget.state.disabled, tokens.states.disabled_alpha))
|
|
1120
|
+
else
|
|
1121
|
+
colorFill(disabledWash(widgetBackgroundColor(widget, buttonStateBackground(visual, false, washHovered(widget), tokens.colors.surface_pressed)), widget.state.disabled, tokens.states.disabled_alpha)),
|
|
1122
|
+
});
|
|
1123
|
+
// Borderless by default: the switch is a filled pill (primary when
|
|
1124
|
+
// on, the input wash when off) whose near-white thumb provides the
|
|
1125
|
+
// edge — a track hairline reads as chrome the control doesn't have.
|
|
1126
|
+
// Themes that opt into a border (a color or an explicit width on
|
|
1127
|
+
// the toggle control tokens) still get the stroked track.
|
|
1128
|
+
const wants_track_stroke = widget.style.border != null or visual.border != null;
|
|
1129
|
+
const track_stroke_width = controlStrokeWidth(widget, visual, if (wants_track_stroke) tokens.stroke.regular else 0);
|
|
1130
|
+
if (track_stroke_width > 0) {
|
|
1131
|
+
try builder.strokeRect(.{
|
|
1132
|
+
.id = widgetPartId(widget.id, 2),
|
|
1133
|
+
.rect = track,
|
|
1134
|
+
.radius = track_radius,
|
|
1135
|
+
.stroke = .{
|
|
1136
|
+
.fill = widgetBorderFill(widget, visual.border orelse tokens.colors.border),
|
|
1137
|
+
.width = track_stroke_width,
|
|
1138
|
+
},
|
|
1139
|
+
});
|
|
1140
|
+
}
|
|
1141
|
+
try builder.fillRoundedRect(.{
|
|
1142
|
+
.id = widgetPartId(widget.id, 3),
|
|
1143
|
+
.rect = knob,
|
|
1144
|
+
.radius = controlRadius(widget, visual, knob.height * 0.5),
|
|
1145
|
+
// The thumb is near-white in both states and schemes (the
|
|
1146
|
+
// primary-foreground tint), so it stays legible on the primary
|
|
1147
|
+
// track and on the dark input wash alike. Disabled washes it to
|
|
1148
|
+
// half strength with the track instead of swapping to gray.
|
|
1149
|
+
.fill = colorFill(disabledWash(
|
|
1150
|
+
if (selected) widget.style.accent_foreground orelse visual.foreground orelse tokens.colors.accent_text else widget.style.background orelse visual.foreground orelse tokens.colors.accent_text,
|
|
1151
|
+
widget.state.disabled,
|
|
1152
|
+
tokens.states.disabled_alpha,
|
|
1153
|
+
)),
|
|
1154
|
+
});
|
|
1155
|
+
if (widget.state.focused) try emitWidgetFocusRingForRect(builder, widget, tokens, 4, track, track_radius);
|
|
1156
|
+
try emitControlLabelWithColor(builder, widget, tokens, track.x + track.width + widgetControlInset(widget, tokens, tokens.spacing.sm), 5, visual.foreground orelse tokens.colors.text);
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1159
|
+
pub fn emitSliderWidget(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!void {
|
|
1160
|
+
const value = std.math.clamp(widget.value, 0, 1);
|
|
1161
|
+
const visual = selectionControlVisualTokens(widget, tokens);
|
|
1162
|
+
const track = sliderWidgetTrackRect(widget, tokens);
|
|
1163
|
+
const active = pixelSnapGeometryRect(tokens, geometry.RectF.init(track.x, track.y, track.width * value, track.height));
|
|
1164
|
+
const knob = sliderWidgetKnobRect(widget, tokens);
|
|
1165
|
+
// The rail is a pill in every register; the RADIUS channel (widget
|
|
1166
|
+
// style or the themed slider table) shapes only the thumb, because
|
|
1167
|
+
// thumb shape is where slider registers actually differ — a round
|
|
1168
|
+
// dot versus a barely-rounded grab handle — while a squared-off rail
|
|
1169
|
+
// is no register at all.
|
|
1170
|
+
const track_radius = Radius.all(track.height * 0.5);
|
|
1171
|
+
const knob_radius = controlRadius(widget, visual, @min(knob.width, knob.height) * 0.5);
|
|
1172
|
+
|
|
1173
|
+
// Disabled register: with no themed statement the whole slider mutes
|
|
1174
|
+
// to the half-strength wash as one piece — rail, range, and thumb
|
|
1175
|
+
// together. A themed table that states a disabled color is the SWAP
|
|
1176
|
+
// register: the stated color replaces the range fill and everything
|
|
1177
|
+
// it does not restate keeps full strength (the swap is the pack's
|
|
1178
|
+
// entire disabled statement).
|
|
1179
|
+
const swap_disabled = visual.disabled_background != null or visual.disabled_foreground != null;
|
|
1180
|
+
const washed = widget.state.disabled and !swap_disabled;
|
|
1181
|
+
|
|
1182
|
+
// Track on the muted wash, filled range on the primary, and a
|
|
1183
|
+
// paper-white thumb under a neutral hairline — the range carries the
|
|
1184
|
+
// color; the thumb reads as a quiet handle on top of it.
|
|
1185
|
+
try builder.fillRoundedRect(.{
|
|
1186
|
+
.id = widgetPartId(widget.id, 1),
|
|
1187
|
+
.rect = track,
|
|
1188
|
+
.radius = track_radius,
|
|
1189
|
+
.fill = colorFill(disabledWash(widgetBackgroundColor(widget, visual.background orelse tokens.colors.surface_subtle), washed, tokens.states.disabled_alpha)),
|
|
1190
|
+
});
|
|
1191
|
+
const active_rest = widgetAccentColor(widget, visual.active_background orelse tokens.colors.accent);
|
|
1192
|
+
try builder.fillRoundedRect(.{
|
|
1193
|
+
.id = widgetPartId(widget.id, 2),
|
|
1194
|
+
.rect = active,
|
|
1195
|
+
.radius = track_radius,
|
|
1196
|
+
.fill = colorFill(if (widget.state.disabled)
|
|
1197
|
+
visual.disabled_background orelse disabledWash(active_rest, true, tokens.states.disabled_alpha)
|
|
1198
|
+
else
|
|
1199
|
+
active_rest),
|
|
1200
|
+
});
|
|
1201
|
+
// Paper-white in BOTH schemes: the thumb must read against the
|
|
1202
|
+
// filled range and the muted rail alike, and the palette carries no
|
|
1203
|
+
// scheme-invariant white token — so the emitter states it, and a
|
|
1204
|
+
// theme restates it through the slider table's foreground channel.
|
|
1205
|
+
const knob_rest = widgetBackgroundColor(widget, visual.foreground orelse Color.rgb8(255, 255, 255));
|
|
1206
|
+
try builder.fillRoundedRect(.{
|
|
1207
|
+
.id = widgetPartId(widget.id, 3),
|
|
1208
|
+
.rect = knob,
|
|
1209
|
+
.radius = knob_radius,
|
|
1210
|
+
.fill = colorFill(if (widget.state.disabled)
|
|
1211
|
+
visual.disabled_foreground orelse disabledWash(knob_rest, washed, tokens.states.disabled_alpha)
|
|
1212
|
+
else
|
|
1213
|
+
knob_rest),
|
|
1214
|
+
});
|
|
1215
|
+
// The thumb's resting hairline wears the focus-ring neutral (a mid
|
|
1216
|
+
// gray in both schemes), so the ring on focus reads as a brighter
|
|
1217
|
+
// echo of an edge the control already owns — not a recolor.
|
|
1218
|
+
try builder.strokeRect(.{
|
|
1219
|
+
.id = widgetPartId(widget.id, 4),
|
|
1220
|
+
.rect = knob,
|
|
1221
|
+
.radius = knob_radius,
|
|
1222
|
+
.stroke = .{
|
|
1223
|
+
.fill = widgetBorderFill(widget, disabledWash(visual.border orelse tokens.colors.focus_ring, washed, tokens.states.disabled_alpha)),
|
|
1224
|
+
.width = controlStrokeWidth(widget, visual, tokens.stroke.regular),
|
|
1225
|
+
},
|
|
1226
|
+
});
|
|
1227
|
+
if (widget.state.focused) try emitWidgetFocusRingForRect(builder, widget, tokens, 5, knob, knob_radius);
|
|
1228
|
+
}
|
|
1229
|
+
|
|
1230
|
+
pub fn checkboxWidgetBoxRect(widget: Widget, tokens: DesignTokens) geometry.RectF {
|
|
1231
|
+
// 16px box at default size/density — the size-4 checkbox metric.
|
|
1232
|
+
const box_size = @min(@max(widgetSizedDensityValue(widget, tokens, 16), widget.frame.height * 0.55), widgetSizedDensityValue(widget, tokens, 20));
|
|
1233
|
+
return pixelSnapGeometryRect(tokens, geometry.RectF.init(
|
|
1234
|
+
widget.frame.x,
|
|
1235
|
+
widget.frame.y + (widget.frame.height - box_size) * 0.5,
|
|
1236
|
+
box_size,
|
|
1237
|
+
box_size,
|
|
1238
|
+
));
|
|
1239
|
+
}
|
|
1240
|
+
|
|
1241
|
+
pub fn radioWidgetCircleRect(widget: Widget, tokens: DesignTokens) geometry.RectF {
|
|
1242
|
+
// 16px circle at default size/density — the size-4 radio metric.
|
|
1243
|
+
const circle_size = @min(@max(widgetSizedDensityValue(widget, tokens, 16), widget.frame.height * 0.55), widgetSizedDensityValue(widget, tokens, 20));
|
|
1244
|
+
return pixelSnapGeometryRect(tokens, geometry.RectF.init(
|
|
1245
|
+
widget.frame.x,
|
|
1246
|
+
widget.frame.y + (widget.frame.height - circle_size) * 0.5,
|
|
1247
|
+
circle_size,
|
|
1248
|
+
circle_size,
|
|
1249
|
+
));
|
|
1250
|
+
}
|
|
1251
|
+
|
|
1252
|
+
pub fn toggleWidgetTrackRect(widget: Widget, tokens: DesignTokens) geometry.RectF {
|
|
1253
|
+
// 44x24 track at default size/density, giving the 20px thumb (track
|
|
1254
|
+
// height minus the 2px inset per side) 20px of travel — the classic
|
|
1255
|
+
// switch proportion, and wide enough that on/off read at a glance.
|
|
1256
|
+
const track_width = @min(widget.frame.width, @max(widgetSizedDensityValue(widget, tokens, 44), widget.frame.height * 1.75));
|
|
1257
|
+
const track_height = @min(widget.frame.height, widgetSizedDensityValue(widget, tokens, 24));
|
|
1258
|
+
return pixelSnapGeometryRect(tokens, geometry.RectF.init(
|
|
1259
|
+
widget.frame.x,
|
|
1260
|
+
widget.frame.y + (widget.frame.height - track_height) * 0.5,
|
|
1261
|
+
track_width,
|
|
1262
|
+
track_height,
|
|
1263
|
+
));
|
|
1264
|
+
}
|
|
1265
|
+
|
|
1266
|
+
fn sliderWidgetTrackRect(widget: Widget, tokens: DesignTokens) geometry.RectF {
|
|
1267
|
+
// The rail thickness comes off the metric ladder (house register:
|
|
1268
|
+
// a quiet 4px line — the thumb, not the rail, gives the control its
|
|
1269
|
+
// weight); packs with a heavier rail restate the token.
|
|
1270
|
+
const track_height: f32 = @min(widget.frame.height, widgetSizedDensityValue(widget, tokens, tokens.metrics.slider_track_height));
|
|
1271
|
+
return pixelSnapGeometryRect(tokens, geometry.RectF.init(
|
|
1272
|
+
widget.frame.x,
|
|
1273
|
+
widget.frame.y + (widget.frame.height - track_height) * 0.5,
|
|
1274
|
+
widget.frame.width,
|
|
1275
|
+
track_height,
|
|
1276
|
+
));
|
|
1277
|
+
}
|
|
1278
|
+
|
|
1279
|
+
pub fn sliderWidgetKnobRect(widget: Widget, tokens: DesignTokens) geometry.RectF {
|
|
1280
|
+
const value = std.math.clamp(widget.value, 0, 1);
|
|
1281
|
+
// Thumb geometry off the metric ladder (house register: a 12px dot;
|
|
1282
|
+
// width and height are separate tokens because some registers use a
|
|
1283
|
+
// narrow rectangular handle). Fixed-size on purpose — the thumb is
|
|
1284
|
+
// a grab target, so it must not swell with the row it sits in —
|
|
1285
|
+
// clamped only so a shallow row never overflows.
|
|
1286
|
+
const knob_width = @min(widget.frame.width, widgetSizedDensityValue(widget, tokens, tokens.metrics.slider_thumb_width));
|
|
1287
|
+
const knob_height = @min(widget.frame.height, widgetSizedDensityValue(widget, tokens, tokens.metrics.slider_thumb_height));
|
|
1288
|
+
const knob_x = std.math.clamp(
|
|
1289
|
+
widget.frame.x + widget.frame.width * value - knob_width * 0.5,
|
|
1290
|
+
widget.frame.x,
|
|
1291
|
+
widget.frame.x + @max(0, widget.frame.width - knob_width),
|
|
1292
|
+
);
|
|
1293
|
+
return pixelSnapGeometryRect(tokens, geometry.RectF.init(
|
|
1294
|
+
knob_x,
|
|
1295
|
+
widget.frame.y + (widget.frame.height - knob_height) * 0.5,
|
|
1296
|
+
knob_width,
|
|
1297
|
+
knob_height,
|
|
1298
|
+
));
|
|
1299
|
+
}
|
|
1300
|
+
|
|
1301
|
+
pub fn emitProgressWidget(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!void {
|
|
1302
|
+
const progress = std.math.clamp(widget.value, 0, 1);
|
|
1303
|
+
const visual = selectionControlVisualTokens(widget, tokens);
|
|
1304
|
+
const radius = controlRadius(widget, visual, @min(tokens.radius.md, widget.frame.height * 0.5));
|
|
1305
|
+
if (progress < 1) {
|
|
1306
|
+
// The unfilled track sits on the muted wash (the same rail the
|
|
1307
|
+
// slider uses), so the primary indicator reads against a quiet
|
|
1308
|
+
// gray rather than against a tint of itself.
|
|
1309
|
+
try builder.fillRoundedRect(.{
|
|
1310
|
+
.id = widgetPartId(widget.id, 1),
|
|
1311
|
+
.rect = widget.frame,
|
|
1312
|
+
.radius = radius,
|
|
1313
|
+
.fill = colorFill(widgetBackgroundColor(widget, visual.background orelse tokens.colors.surface_subtle)),
|
|
1314
|
+
});
|
|
1315
|
+
}
|
|
1316
|
+
if (progress > 0) {
|
|
1317
|
+
try builder.fillRoundedRect(.{
|
|
1318
|
+
.id = widgetPartId(widget.id, 2),
|
|
1319
|
+
.rect = pixelSnapGeometryRect(tokens, geometry.RectF.init(widget.frame.x, widget.frame.y, widget.frame.width * progress, widget.frame.height)),
|
|
1320
|
+
.radius = radius,
|
|
1321
|
+
.fill = colorFill(widgetAccentColor(widget, visual.active_background orelse tokens.colors.accent)),
|
|
1322
|
+
});
|
|
1323
|
+
}
|
|
1324
|
+
}
|
|
1325
|
+
|
|
1326
|
+
fn emitWidgetFocusRing(builder: *Builder, widget: Widget, tokens: DesignTokens, slot: ObjectId) Error!void {
|
|
1327
|
+
return emitWidgetFocusRingForRect(builder, widget, tokens, slot, widget.frame, widgetRadius(widget, tokens.radius.md));
|
|
1328
|
+
}
|
|
1329
|
+
|
|
1330
|
+
/// The ring-offset focus treatment: the control keeps its own border
|
|
1331
|
+
/// and the ring strokes a concentric rounded rect the token-stated gap
|
|
1332
|
+
/// (`stroke.focus_offset`) outside it, so focus adds an outline instead
|
|
1333
|
+
/// of recoloring the control's edge.
|
|
1334
|
+
fn emitWidgetFocusRingForRect(builder: *Builder, widget: Widget, tokens: DesignTokens, slot: ObjectId, rect: geometry.RectF, radius: Radius) Error!void {
|
|
1335
|
+
try builder.strokeRect(.{
|
|
1336
|
+
.id = widgetPartId(widget.id, slot),
|
|
1337
|
+
.rect = widget_render_style.focusRingRect(rect, tokens),
|
|
1338
|
+
.radius = widget_render_style.focusRingRadius(radius, tokens),
|
|
1339
|
+
.stroke = .{
|
|
1340
|
+
.fill = widgetFocusRingFill(widget, tokens),
|
|
1341
|
+
.width = tokens.stroke.focus,
|
|
1342
|
+
},
|
|
1343
|
+
});
|
|
1344
|
+
}
|
|
1345
|
+
|
|
1346
|
+
fn emitControlLabelWithColor(builder: *Builder, widget: Widget, tokens: DesignTokens, x: f32, slot: ObjectId, color: Color) Error!void {
|
|
1347
|
+
if (widget.text.len == 0) return;
|
|
1348
|
+
const text_size = widgetLabelTextSize(widget, tokens);
|
|
1349
|
+
try builder.drawText(.{
|
|
1350
|
+
.id = widgetPartId(widget.id, slot),
|
|
1351
|
+
.font_id = tokens.typography.font_id,
|
|
1352
|
+
.size = text_size,
|
|
1353
|
+
.origin = pixelSnapTextPoint(tokens, boundedTextOrigin(labelFrameForControl(widget.frame, x), text_size, 0)),
|
|
1354
|
+
.color = widgetForegroundColor(widget, tokens, color),
|
|
1355
|
+
.text = widget.text,
|
|
1356
|
+
.text_layout = boundedTextLayout(labelFrameForControl(widget.frame, x), text_size, 0, .start, .none, widget.text_overflow, tokens),
|
|
1357
|
+
});
|
|
1358
|
+
}
|
|
1359
|
+
|
|
1360
|
+
fn widgetPartId(id: ObjectId, slot: ObjectId) ObjectId {
|
|
1361
|
+
if (id == 0) return 0;
|
|
1362
|
+
const base = id *% 16;
|
|
1363
|
+
const part = base +% slot;
|
|
1364
|
+
return if (part == 0) id else part;
|
|
1365
|
+
}
|
|
1366
|
+
|
|
1367
|
+
fn textOrigin(frame: geometry.RectF, size: f32, inset: f32) geometry.PointF {
|
|
1368
|
+
const line_height = size * 1.25;
|
|
1369
|
+
return geometry.PointF.init(
|
|
1370
|
+
frame.x + inset,
|
|
1371
|
+
frame.y + @max(size, (frame.height - line_height) * 0.5 + size),
|
|
1372
|
+
);
|
|
1373
|
+
}
|
|
1374
|
+
|
|
1375
|
+
fn boundedTextOrigin(frame: geometry.RectF, size: f32, inset: f32) geometry.PointF {
|
|
1376
|
+
return geometry.PointF.init(frame.x + inset, textOrigin(frame, size, 0).y);
|
|
1377
|
+
}
|
|
1378
|
+
|
|
1379
|
+
fn boundedTextLayout(frame: geometry.RectF, size: f32, inset: f32, alignment: TextAlign, wrap: TextWrap, overflow: TextOverflow, tokens: DesignTokens) TextLayoutOptions {
|
|
1380
|
+
return .{
|
|
1381
|
+
.max_width = @max(1, frame.width - inset * 2),
|
|
1382
|
+
.line_height = size * 1.25,
|
|
1383
|
+
.wrap = wrap,
|
|
1384
|
+
.alignment = alignment,
|
|
1385
|
+
// Single-line labels follow the widget's overflow policy:
|
|
1386
|
+
// trailing ellipsis by default, so a control narrower than its
|
|
1387
|
+
// label elides instead of bleeding into its neighbors.
|
|
1388
|
+
.overflow = overflow,
|
|
1389
|
+
.measure = tokens.text_measure,
|
|
1390
|
+
};
|
|
1391
|
+
}
|
|
1392
|
+
|
|
1393
|
+
fn labelFrameForControl(frame: geometry.RectF, x: f32) geometry.RectF {
|
|
1394
|
+
return geometry.RectF.init(x, frame.y, @max(1, frame.x + frame.width - x), frame.height);
|
|
1395
|
+
}
|
|
1396
|
+
|
|
1397
|
+
fn centeredTextOrigin(frame: geometry.RectF, text: []const u8, size: f32, tokens: DesignTokens) geometry.PointF {
|
|
1398
|
+
return alignedTextOrigin(frame, text, size, 0, .center, tokens);
|
|
1399
|
+
}
|
|
1400
|
+
|
|
1401
|
+
fn alignedTextOrigin(frame: geometry.RectF, text: []const u8, size: f32, inset: f32, alignment: TextAlign, tokens: DesignTokens) geometry.PointF {
|
|
1402
|
+
const width = if (tokens.text_measure) |measure|
|
|
1403
|
+
measure.measureWidth(tokens.typography.font_id, size, text)
|
|
1404
|
+
else
|
|
1405
|
+
estimateTextWidth(text, size);
|
|
1406
|
+
const available_width = @max(0, frame.width - inset * 2);
|
|
1407
|
+
const offset = switch (alignment) {
|
|
1408
|
+
.start => 0,
|
|
1409
|
+
.center => @max(0, (available_width - width) * 0.5),
|
|
1410
|
+
.end => @max(0, available_width - width),
|
|
1411
|
+
};
|
|
1412
|
+
const line_height = size * 1.25;
|
|
1413
|
+
return geometry.PointF.init(
|
|
1414
|
+
frame.x + inset + offset,
|
|
1415
|
+
frame.y + @max(size, (frame.height - line_height) * 0.5 + size),
|
|
1416
|
+
);
|
|
1417
|
+
}
|
|
1418
|
+
|
|
1419
|
+
fn iconGlyphSize(widget: Widget, tokens: DesignTokens) f32 {
|
|
1420
|
+
const min_size = widgetSizedDensityValue(widget, tokens, 12);
|
|
1421
|
+
if (widget.frame.height > 0) return @min(@max(min_size, widget.frame.height * widgetIconGlyphScale(widget)), @max(min_size, widgetTypographySize(widget, tokens.typography.title_size)));
|
|
1422
|
+
return widgetButtonTextSize(widget, tokens);
|
|
1423
|
+
}
|
|
1424
|
+
|
|
1425
|
+
fn widgetIconGlyphScale(widget: Widget) f32 {
|
|
1426
|
+
return switch (widget.size) {
|
|
1427
|
+
.sm => 0.44,
|
|
1428
|
+
// heading/display are text-leaf typography rungs; icon glyphs
|
|
1429
|
+
// keep the default control proportion.
|
|
1430
|
+
.default, .icon, .heading, .display => 0.48,
|
|
1431
|
+
.lg => 0.52,
|
|
1432
|
+
};
|
|
1433
|
+
}
|
|
1434
|
+
|
|
1435
|
+
fn emitWidgetTextSelectionRects(
|
|
1436
|
+
builder: *Builder,
|
|
1437
|
+
widget: Widget,
|
|
1438
|
+
text: DrawText,
|
|
1439
|
+
options: TextLayoutOptions,
|
|
1440
|
+
range: TextRange,
|
|
1441
|
+
first_part: ObjectId,
|
|
1442
|
+
overflow_first_part: ObjectId,
|
|
1443
|
+
max_parts: usize,
|
|
1444
|
+
tokens: DesignTokens,
|
|
1445
|
+
) Error!void {
|
|
1446
|
+
var rect_buffer: [max_widget_text_range_rects]TextSelectionRect = undefined;
|
|
1447
|
+
const rects = layoutTextSelectionRects(text, options, range, rect_buffer[0..@min(max_parts, rect_buffer.len)]);
|
|
1448
|
+
for (rects, 0..) |selection, index| {
|
|
1449
|
+
// Square corners: the highlight is a solid accent block that the
|
|
1450
|
+
// selected-glyph repaint is clipped to, so fill and clip must
|
|
1451
|
+
// share one edge — and abutting per-line rects of a multi-line
|
|
1452
|
+
// selection meet without corner notches.
|
|
1453
|
+
try builder.fillRect(.{
|
|
1454
|
+
.id = widgetPartId(widget.id, widgetTextRangePart(first_part, overflow_first_part, index)),
|
|
1455
|
+
.rect = pixelSnapGeometryRect(tokens, selection.rect),
|
|
1456
|
+
.fill = .{ .color = textSelectionFillColor(widget, tokens) },
|
|
1457
|
+
});
|
|
1458
|
+
}
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1461
|
+
/// The inverted-selection glyph pass: the SAME text command the base
|
|
1462
|
+
/// pass drew, re-emitted once per highlight rect under that rect's clip
|
|
1463
|
+
/// with the selection foreground. Re-emitting the identical command is
|
|
1464
|
+
/// what makes the recolor drift-free — every glyph lands exactly where
|
|
1465
|
+
/// the base pass put it and only swaps ink where the highlight covers it
|
|
1466
|
+
/// (re-shaping the selected substring instead would re-kern at the
|
|
1467
|
+
/// segment boundary and shift the halves apart). Runs after the base
|
|
1468
|
+
/// text so the recolored glyphs paint over their normal-ink twins.
|
|
1469
|
+
fn emitWidgetTextSelectedGlyphs(
|
|
1470
|
+
builder: *Builder,
|
|
1471
|
+
widget: Widget,
|
|
1472
|
+
text: DrawText,
|
|
1473
|
+
options: TextLayoutOptions,
|
|
1474
|
+
range: TextRange,
|
|
1475
|
+
max_parts: usize,
|
|
1476
|
+
tokens: DesignTokens,
|
|
1477
|
+
) Error!void {
|
|
1478
|
+
var rect_buffer: [max_widget_text_range_rects]TextSelectionRect = undefined;
|
|
1479
|
+
const rects = layoutTextSelectionRects(text, options, range, rect_buffer[0..@min(max_parts, rect_buffer.len)]);
|
|
1480
|
+
for (rects, 0..) |selection, ordinal| {
|
|
1481
|
+
try builder.pushClip(.{
|
|
1482
|
+
.id = textSelectionOverlayCommandId(0x5eed_59a2_0000_0005, widget.id, ordinal),
|
|
1483
|
+
.rect = pixelSnapGeometryRect(tokens, selection.rect),
|
|
1484
|
+
});
|
|
1485
|
+
var command = text;
|
|
1486
|
+
command.id = textSelectionOverlayCommandId(0x5eed_59a2_0000_0006, widget.id, ordinal);
|
|
1487
|
+
command.color = textSelectionTextColor(widget, tokens);
|
|
1488
|
+
try builder.drawText(command);
|
|
1489
|
+
try builder.popClip();
|
|
1490
|
+
}
|
|
1491
|
+
}
|
|
1492
|
+
|
|
1493
|
+
/// Stable command ids for the selected-glyph repaint (one clip + one
|
|
1494
|
+
/// text per highlight rect). Hashed from the widget id and rect ordinal
|
|
1495
|
+
/// — the same scheme static-text selection rects use — because the
|
|
1496
|
+
/// arithmetic part-id space (16 slots per widget id) has no room left
|
|
1497
|
+
/// on text fields for four more rect-indexed parts.
|
|
1498
|
+
fn textSelectionOverlayCommandId(seed: u64, widget_id: ObjectId, ordinal: usize) ObjectId {
|
|
1499
|
+
var hasher = std.hash.Wyhash.init(seed);
|
|
1500
|
+
hasher.update(std.mem.asBytes(&widget_id));
|
|
1501
|
+
hasher.update(std.mem.asBytes(&@as(u64, ordinal)));
|
|
1502
|
+
const value = hasher.final();
|
|
1503
|
+
return if (value == 0) 1 else value;
|
|
1504
|
+
}
|
|
1505
|
+
|
|
1506
|
+
fn emitWidgetTextCompositionLines(
|
|
1507
|
+
builder: *Builder,
|
|
1508
|
+
widget: Widget,
|
|
1509
|
+
text: DrawText,
|
|
1510
|
+
options: TextLayoutOptions,
|
|
1511
|
+
range: TextRange,
|
|
1512
|
+
first_part: ObjectId,
|
|
1513
|
+
overflow_first_part: ObjectId,
|
|
1514
|
+
max_parts: usize,
|
|
1515
|
+
tokens: DesignTokens,
|
|
1516
|
+
) Error!void {
|
|
1517
|
+
var rect_buffer: [max_widget_text_range_rects]TextSelectionRect = undefined;
|
|
1518
|
+
const rects = layoutTextSelectionRects(text, options, range, rect_buffer[0..@min(max_parts, rect_buffer.len)]);
|
|
1519
|
+
for (rects, 0..) |selection, index| {
|
|
1520
|
+
// A filled bar, not a stroked line: a centered 1pt stroke on a
|
|
1521
|
+
// snapped coordinate covers half of each neighboring pixel row
|
|
1522
|
+
// at 1x and antialiases to a 50% ghost, while a snapped rect
|
|
1523
|
+
// covers whole device pixels and stays crisp at every scale.
|
|
1524
|
+
const snapped = pixelSnapGeometryRect(tokens, selection.rect);
|
|
1525
|
+
try builder.fillRect(.{
|
|
1526
|
+
.id = widgetPartId(widget.id, widgetTextRangePart(first_part, overflow_first_part, index)),
|
|
1527
|
+
.rect = pixelSnapGeometryRect(tokens, geometry.RectF.init(
|
|
1528
|
+
snapped.x,
|
|
1529
|
+
snapped.maxY() - tokens.stroke.regular,
|
|
1530
|
+
snapped.width,
|
|
1531
|
+
tokens.stroke.regular,
|
|
1532
|
+
)),
|
|
1533
|
+
.fill = .{ .color = textEditingInkColor(widget, tokens) },
|
|
1534
|
+
});
|
|
1535
|
+
}
|
|
1536
|
+
}
|
|
1537
|
+
|
|
1538
|
+
fn widgetTextRangePart(first_part: ObjectId, overflow_first_part: ObjectId, index: usize) ObjectId {
|
|
1539
|
+
if (index == 0 or overflow_first_part == 0) return first_part + @as(ObjectId, @intCast(index));
|
|
1540
|
+
return overflow_first_part + @as(ObjectId, @intCast(index - 1));
|
|
1541
|
+
}
|
|
1542
|
+
|
|
1543
|
+
fn emitWidgetTextCaret(
|
|
1544
|
+
builder: *Builder,
|
|
1545
|
+
widget: Widget,
|
|
1546
|
+
text: DrawText,
|
|
1547
|
+
options: TextLayoutOptions,
|
|
1548
|
+
offset: usize,
|
|
1549
|
+
part: ObjectId,
|
|
1550
|
+
tokens: DesignTokens,
|
|
1551
|
+
) Error!void {
|
|
1552
|
+
const rect = layoutTextCaretRect(text, options, offset) orelse return;
|
|
1553
|
+
// A filled one-point bar in the field's text ink. A fill, not a
|
|
1554
|
+
// stroked line: a centered 1pt stroke on a snapped x covers half of
|
|
1555
|
+
// each neighboring pixel column at 1x and antialiases to a 50%
|
|
1556
|
+
// ghost, while the snapped rect covers whole device pixels — the
|
|
1557
|
+
// caret stays crisp and full-contrast at every scale.
|
|
1558
|
+
try builder.fillRect(.{
|
|
1559
|
+
.id = widgetPartId(widget.id, part),
|
|
1560
|
+
.rect = pixelSnapGeometryRect(tokens, rect),
|
|
1561
|
+
.fill = .{ .color = textEditingInkColor(widget, tokens) },
|
|
1562
|
+
});
|
|
1563
|
+
}
|