@native-sdk/cli 0.10.1 → 0.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -6
- package/bin/native.js +2 -1
- package/build/app.zig +393 -97
- package/build/corewire.zig +53 -0
- package/build/test_shards.zig +49 -0
- package/build/ts_run.mjs +3 -3
- package/build.zig +2030 -83
- package/native-sdk.d.ts +5 -1
- package/package.json +20 -14
- package/packages/core/compile-surface/core.ts +164 -72
- package/packages/core/package-lock.json +75 -357
- package/packages/core/package.json +25 -4
- package/packages/core/scripts/compiler_command.mjs +17 -12
- package/packages/core/scripts/compiler_typecheck.mjs +1 -0
- package/packages/core/scripts/gen_declarations.mjs +3 -2
- package/packages/core/scripts/gen_service_surface.mjs +22 -10
- package/packages/core/scripts/install_scriptc.mjs +182 -0
- package/packages/core/scripts/invoke_scriptc.mjs +18 -0
- package/packages/core/scripts/merge_static_archives.mjs +6 -1
- package/packages/core/scripts/npm_static_spike.mjs +2 -2
- package/packages/core/scripts/run_external_core_compiler.mjs +22 -10
- package/packages/core/scripts/run_external_service_compiler.mjs +15 -15
- package/packages/core/scripts/run_library_compiler.mjs +51 -0
- package/packages/core/scripts/run_native_tests.mjs +22 -0
- package/packages/core/scripts/scriptc-toolchain.json +101 -0
- package/packages/core/scripts/scriptc_toolchain.mjs +121 -0
- package/packages/core/scripts/stage_external_core.mjs +68 -1
- package/packages/core/scripts/surface_manifest_diff.mjs +19 -12
- package/packages/core/sdk/bytes.d.ts +2 -0
- package/packages/core/sdk/bytes.ts +86 -0
- package/packages/core/sdk/core.d.ts +332 -5
- package/packages/core/sdk/core.ts +371 -85
- package/packages/core/sdk/events.d.ts +252 -0
- package/packages/core/sdk/events.ts +240 -2
- package/packages/core/sdk/internal/image_identity.d.ts +7 -0
- package/packages/core/sdk/internal/image_identity.ts +71 -0
- package/packages/core/sdk/internal/markdown_policy.d.ts +5 -0
- package/packages/core/sdk/internal/markdown_policy.ts +878 -0
- package/packages/core/sdk/text.d.ts +27 -0
- package/packages/core/sdk/text.ts +206 -15
- package/packages/core/sdk/theme.d.ts +251 -0
- package/packages/core/sdk/theme.ts +267 -0
- package/packages/core/src/authorization.ts +137 -0
- package/packages/core/src/automation_commands.ts +201 -0
- package/packages/core/src/automation_interactions.ts +92 -0
- package/packages/core/src/bridge_descriptors.ts +104 -0
- package/packages/core/src/builtin_coordination.ts +172 -0
- package/packages/core/src/canvas_frame_coordination.ts +81 -0
- package/packages/core/src/canvas_presentation_lifecycle.ts +84 -0
- package/packages/core/src/canvas_scene_observation.ts +145 -0
- package/packages/core/src/chart_content.ts +161 -0
- package/packages/core/src/chart_plans.ts +432 -0
- package/packages/core/src/checker.ts +186 -19
- package/packages/core/src/cli.ts +2 -11
- package/packages/core/src/code_content.ts +580 -0
- package/packages/core/src/command_coordination.ts +140 -0
- package/packages/core/src/component_composition.ts +94 -0
- package/packages/core/src/component_construction.ts +149 -0
- package/packages/core/src/context_menus.ts +76 -0
- package/packages/core/src/contract.ts +25 -7
- package/packages/core/src/control_appearance.ts +232 -0
- package/packages/core/src/control_commands.ts +115 -0
- package/packages/core/src/control_content.ts +105 -0
- package/packages/core/src/control_geometry.ts +107 -0
- package/packages/core/src/control_payloads.ts +119 -0
- package/packages/core/src/control_primitives.ts +134 -0
- package/packages/core/src/devhost.ts +82 -7
- package/packages/core/src/devhost_journal.mjs +30 -7
- package/packages/core/src/diagnostics.ts +7 -0
- package/packages/core/src/effect_plans.ts +71 -0
- package/packages/core/src/extent_program.ts +53 -0
- package/packages/core/src/flow_measurement.ts +121 -0
- package/packages/core/src/font_registry.ts +37 -0
- package/packages/core/src/frontend.ts +12 -10
- package/packages/core/src/glyph_atlas.ts +86 -0
- package/packages/core/src/gpu_packet_preparation.ts +130 -0
- package/packages/core/src/gpu_planning.ts +123 -0
- package/packages/core/src/gpu_presentation.ts +55 -0
- package/packages/core/src/host_flow.ts +89 -0
- package/packages/core/src/host_input_regions.ts +165 -0
- package/packages/core/src/image_registry.ts +66 -0
- package/packages/core/src/indicator_plans.ts +132 -0
- package/packages/core/src/infer.ts +150 -8
- package/packages/core/src/input_composition.ts +116 -0
- package/packages/core/src/intrinsic_measure.ts +100 -0
- package/packages/core/src/layout_coordination.ts +207 -0
- package/packages/core/src/leaf_plans.ts +134 -0
- package/packages/core/src/markup_canonical.ts +140 -0
- package/packages/core/src/markup_construction.ts +189 -0
- package/packages/core/src/markup_development.ts +160 -0
- package/packages/core/src/markup_display.ts +43 -0
- package/packages/core/src/markup_document.ts +226 -0
- package/packages/core/src/markup_elements.ts +225 -0
- package/packages/core/src/markup_expressions.ts +79 -0
- package/packages/core/src/markup_imports.ts +146 -0
- package/packages/core/src/markup_parser.ts +228 -0
- package/packages/core/src/markup_runtime.ts +93 -0
- package/packages/core/src/markup_scalars.ts +143 -0
- package/packages/core/src/markup_shapes.ts +243 -0
- package/packages/core/src/markup_specialized.ts +242 -0
- package/packages/core/src/markup_text.ts +86 -0
- package/packages/core/src/markup_values.ts +336 -0
- package/packages/core/src/measurement_coordination.ts +185 -0
- package/packages/core/src/modules.ts +1 -1
- package/packages/core/src/motion_sampling.ts +100 -0
- package/packages/core/src/paragraph_layout.ts +192 -0
- package/packages/core/src/portable_sources.json +98 -0
- package/packages/core/src/portable_sources.ts +17 -0
- package/packages/core/src/registered_font.ts +92 -0
- package/packages/core/src/render_animation_lifecycle.ts +128 -0
- package/packages/core/src/render_coordination.ts +170 -0
- package/packages/core/src/render_resources.ts +234 -0
- package/packages/core/src/runtime_policy.ts +3954 -0
- package/packages/core/src/scalar_text.ts +82 -0
- package/packages/core/src/scroll_mutation.ts +86 -0
- package/packages/core/src/scroll_tree.ts +86 -0
- package/packages/core/src/service_contract.ts +55 -3
- package/packages/core/src/session_codecs.ts +309 -0
- package/packages/core/src/shell_admission.ts +126 -0
- package/packages/core/src/shell_coordination.ts +93 -0
- package/packages/core/src/sqlite_cli.ts +14 -46
- package/packages/core/src/sqlite_codegen.ts +84 -0
- package/packages/core/src/staged_rebuild.ts +60 -0
- package/packages/core/src/status_validation.ts +232 -0
- package/packages/core/src/stream_policy.ts +63 -0
- package/packages/core/src/surface_recipes.ts +136 -0
- package/packages/core/src/system_admission.ts +60 -0
- package/packages/core/src/terminal_paint.ts +436 -0
- package/packages/core/src/text_document_width.ts +81 -0
- package/packages/core/src/text_measurement_cache.ts +69 -0
- package/packages/core/src/text_query_layout.ts +179 -0
- package/packages/core/src/text_run_layout.ts +410 -0
- package/packages/core/src/text_span_queries.ts +355 -0
- package/packages/core/src/typed_ast.ts +18 -1
- package/packages/core/src/types.ts +7 -5
- package/packages/core/src/vector_effects.ts +98 -0
- package/packages/core/src/vector_raster.ts +243 -0
- package/packages/core/src/view_bridge.ts +161 -0
- package/packages/core/src/view_check.ts +145 -0
- package/packages/core/src/view_components.ts +2415 -0
- package/packages/core/src/view_coordination.ts +198 -0
- package/packages/core/src/view_evaluator.ts +823 -0
- package/packages/core/src/view_frontend.ts +1102 -0
- package/packages/core/src/view_program.ts +221 -0
- package/packages/core/src/view_reload.ts +166 -0
- package/packages/core/src/view_reload_watch.ts +98 -0
- package/packages/core/src/view_sources.ts +34 -0
- package/packages/core/src/virtual_windows.ts +88 -0
- package/packages/core/src/web_panes.ts +67 -0
- package/packages/core/src/widget_audits.ts +202 -0
- package/packages/core/src/widget_changes.ts +258 -0
- package/packages/core/src/widget_continuity.ts +37 -0
- package/packages/core/src/widget_metrics.ts +139 -0
- package/packages/core/src/widget_motion.ts +171 -0
- package/packages/core/src/widget_paint.ts +272 -0
- package/packages/core/src/widget_paint_walk.ts +203 -0
- package/packages/core/src/widget_presentation.ts +141 -0
- package/packages/core/src/widget_reconcile.ts +63 -0
- package/packages/core/src/widget_retention.ts +62 -0
- package/packages/core/src/widget_routing.ts +262 -0
- package/packages/core/src/window_lifecycle.ts +92 -0
- package/packages/core/testing/index.ts +430 -0
- package/schemas/app.schema.json +13 -0
- package/skill-data/core/SKILL.md +2 -2
- package/skill-data/native-ui/SKILL.md +77 -18
- package/skill-data/ts-core/SKILL.md +117 -11
- package/skill-data/ts-services/SKILL.md +1 -1
- package/skill-data/ts-services/references/service-surface.md +288 -144
- package/src/app_runner/root.zig +39 -12
- package/src/app_runner/ts_compiled_view.zig +1702 -0
- package/src/app_runner/ts_core_main.zig +185 -14
- package/src/app_runner/ts_core_mobile.zig +25 -13
- package/src/automation/server.zig +57 -6
- package/src/automation/snapshot.zig +9 -637
- package/src/automation/snapshot_reference.zig +656 -0
- package/src/automation/snapshot_serialization.zig +566 -0
- package/src/embed/host.zig +2 -0
- package/src/embed/tests.zig +2 -0
- package/src/embed/ui_host.zig +2 -0
- package/src/platform/keyboard_input.zig +32 -0
- package/src/platform/linux/gtk_host.c +36 -24
- package/src/platform/linux/gtk_pixels.h +118 -0
- package/src/platform/linux/gtk_pixels_test.c +241 -0
- package/src/platform/linux/root.zig +4 -0
- package/src/platform/macos/appkit_host.h +7 -2
- package/src/platform/macos/appkit_host.m +219 -39
- package/src/platform/macos/cef_host.mm +15 -1
- package/src/platform/macos/global_shortcuts.zig +138 -0
- package/src/platform/macos/key_codes.zig +102 -0
- package/src/platform/macos/keyboard_input.zig +81 -0
- package/src/platform/macos/pointer_motion_test.m +96 -0
- package/src/platform/macos/root.zig +25 -3
- package/src/platform/macos/scroll_driver_test.m +105 -0
- package/src/platform/macos/spectrum_bins.h +34 -0
- package/src/platform/macos/spectrum_bins_test.c +56 -0
- package/src/platform/macos/text_keyboard_test.m +80 -0
- package/src/platform/macos/webview_inspection_test.m +106 -0
- package/src/platform/macos/widget_focus_test.m +66 -0
- package/src/platform/null_platform.zig +130 -2
- package/src/platform/null_platform_tests.zig +13 -0
- package/src/platform/root.zig +15 -0
- package/src/platform/types.zig +115 -0
- package/src/platform/windows/global_shortcuts.zig +157 -0
- package/src/platform/windows/key_codes.zig +63 -0
- package/src/platform/windows/keyboard_input.zig +136 -0
- package/src/platform/windows/root.zig +17 -0
- package/src/platform/windows/webview2_host.cpp +7 -2
- package/src/primitives/app_manifest/comptime_scene.zig +1 -1
- package/src/primitives/app_manifest/root.zig +2 -0
- package/src/primitives/app_manifest/tests.zig +4 -1
- package/src/primitives/app_manifest/validation.zig +2 -0
- package/src/primitives/canvas/a11y_audit.zig +3 -1
- package/src/primitives/canvas/canvas_frame_coordination_policy.zig +134 -0
- package/src/primitives/canvas/chart_content_policy.zig +75 -0
- package/src/primitives/canvas/chart_plan_policy.zig +196 -0
- package/src/primitives/canvas/code_content_policy.zig +162 -0
- package/src/primitives/canvas/commands.zig +29 -1
- package/src/primitives/canvas/component_composition.zig +125 -0
- package/src/primitives/canvas/component_composition_policy.zig +44 -0
- package/src/primitives/canvas/component_construction_policy.zig +187 -0
- package/src/primitives/canvas/container_layout_policy.zig +87 -0
- package/src/primitives/canvas/control_appearance_policy.zig +142 -0
- package/src/primitives/canvas/control_command_policy.zig +75 -0
- package/src/primitives/canvas/control_content_policy.zig +90 -0
- package/src/primitives/canvas/control_geometry_policy.zig +165 -0
- package/src/primitives/canvas/control_payload_policy.zig +48 -0
- package/src/primitives/canvas/control_primitive_policy.zig +129 -0
- package/src/primitives/canvas/decision_reuse.zig +133 -0
- package/src/primitives/canvas/effect_plan_policy.zig +96 -0
- package/src/primitives/canvas/events.zig +1027 -1
- package/src/primitives/canvas/flow_measurement_policy.zig +237 -0
- package/src/primitives/canvas/font_ttf.zig +27 -3
- package/src/primitives/canvas/fonts/Geist-Bold.ttf +0 -0
- package/src/primitives/canvas/fonts/Geist-Medium.ttf +0 -0
- package/src/primitives/canvas/fonts/OFL.txt +93 -0
- package/src/primitives/canvas/fonts/README.md +15 -0
- package/src/primitives/canvas/frame.zig +92 -23
- package/src/primitives/canvas/glyph_atlas_policy.zig +40 -0
- package/src/primitives/canvas/gpu.zig +10 -0
- package/src/primitives/canvas/gpu_packet_preparation_policy.zig +325 -0
- package/src/primitives/canvas/gpu_planning_policy.zig +364 -0
- package/src/primitives/canvas/gpu_presentation_policy.zig +74 -0
- package/src/primitives/canvas/grid_layout_policy.zig +51 -0
- package/src/primitives/canvas/indicator_plan_policy.zig +128 -0
- package/src/primitives/canvas/intrinsic_layout_policy.zig +87 -0
- package/src/primitives/canvas/intrinsic_measure_policy.zig +131 -0
- package/src/primitives/canvas/layout_audit.zig +5 -2
- package/src/primitives/canvas/layout_coordination_policy.zig +262 -0
- package/src/primitives/canvas/leaf_plan_policy.zig +117 -0
- package/src/primitives/canvas/markdown.zig +13 -3
- package/src/primitives/canvas/markdown_content_policy.zig +227 -0
- package/src/primitives/canvas/markdown_image_binding.zig +81 -0
- package/src/primitives/canvas/markdown_tests.zig +3 -3
- package/src/primitives/canvas/measurement_coordination_policy.zig +288 -0
- package/src/primitives/canvas/numeric_capabilities.zig +14 -0
- package/src/primitives/canvas/reference.zig +15 -11
- package/src/primitives/canvas/reference_tests.zig +58 -0
- package/src/primitives/canvas/registered_font_policy.zig +152 -0
- package/src/primitives/canvas/render.zig +48 -0
- package/src/primitives/canvas/render_cache_policy.zig +184 -0
- package/src/primitives/canvas/render_coordination_policy.zig +163 -0
- package/src/primitives/canvas/render_damage_policy.zig +160 -0
- package/src/primitives/canvas/render_effects.zig +14 -0
- package/src/primitives/canvas/render_generic_resources.zig +14 -0
- package/src/primitives/canvas/render_images.zig +14 -0
- package/src/primitives/canvas/render_layers.zig +14 -0
- package/src/primitives/canvas/render_override_policy.zig +119 -0
- package/src/primitives/canvas/render_paths.zig +14 -0
- package/src/primitives/canvas/render_plan_policy.zig +199 -0
- package/src/primitives/canvas/render_resource_policy.zig +476 -0
- package/src/primitives/canvas/root.zig +107 -4
- package/src/primitives/canvas/semantic_tree_policy.zig +158 -0
- package/src/primitives/canvas/serialization.zig +8 -1
- package/src/primitives/canvas/surface_layout_policy.zig +36 -0
- package/src/primitives/canvas/surface_recipe_policy.zig +231 -0
- package/src/primitives/canvas/terminal_grid.zig +10 -696
- package/src/primitives/canvas/terminal_grid_reference.zig +709 -0
- package/src/primitives/canvas/terminal_paint_policy.zig +191 -0
- package/src/primitives/canvas/text.zig +1 -0
- package/src/primitives/canvas/text_atlas.zig +113 -0
- package/src/primitives/canvas/text_cache_policy.zig +94 -0
- package/src/primitives/canvas/text_document_policy.zig +120 -0
- package/src/primitives/canvas/text_layout.zig +51 -2
- package/src/primitives/canvas/text_layout_cache.zig +29 -0
- package/src/primitives/canvas/text_layout_hash.zig +1 -0
- package/src/primitives/canvas/text_layout_types.zig +3 -0
- package/src/primitives/canvas/text_measure_cache.zig +46 -0
- package/src/primitives/canvas/text_measurement_policy.zig +124 -0
- package/src/primitives/canvas/text_metrics.zig +53 -37
- package/src/primitives/canvas/text_metrics_tests.zig +52 -7
- package/src/primitives/canvas/text_query_policy.zig +295 -0
- package/src/primitives/canvas/text_run_policy.zig +252 -0
- package/src/primitives/canvas/text_scalar_policy.zig +234 -0
- package/src/primitives/canvas/text_span_query_policy.zig +232 -0
- package/src/primitives/canvas/text_spans.zig +280 -8
- package/src/primitives/canvas/text_tests.zig +10 -0
- package/src/primitives/canvas/tokens.zig +47 -0
- package/src/primitives/canvas/ui.zig +251 -83
- package/src/primitives/canvas/ui_markup.zig +207 -46
- package/src/primitives/canvas/ui_markup_canonical.zig +237 -0
- package/src/primitives/canvas/ui_markup_compiled.zig +1724 -80
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +225 -0
- package/src/primitives/canvas/ui_markup_compiled_values.zig +76 -0
- package/src/primitives/canvas/ui_markup_construction.zig +146 -0
- package/src/primitives/canvas/ui_markup_contract.zig +146 -14
- package/src/primitives/canvas/ui_markup_contract_tests.zig +77 -0
- package/src/primitives/canvas/ui_markup_display.zig +82 -0
- package/src/primitives/canvas/ui_markup_document.zig +196 -0
- package/src/primitives/canvas/ui_markup_elements.zig +163 -0
- package/src/primitives/canvas/ui_markup_expr.zig +192 -2
- package/src/primitives/canvas/ui_markup_imports.zig +262 -0
- package/src/primitives/canvas/ui_markup_parser.zig +117 -0
- package/src/primitives/canvas/ui_markup_reflect.zig +56 -0
- package/src/primitives/canvas/ui_markup_runtime.zig +76 -0
- package/src/primitives/canvas/ui_markup_scalars.zig +115 -0
- package/src/primitives/canvas/ui_markup_shapes.zig +224 -0
- package/src/primitives/canvas/ui_markup_specialized.zig +106 -0
- package/src/primitives/canvas/ui_markup_tests.zig +116 -0
- package/src/primitives/canvas/ui_markup_text.zig +128 -0
- package/src/primitives/canvas/ui_markup_values.zig +368 -0
- package/src/primitives/canvas/ui_markup_view.zig +3026 -57
- package/src/primitives/canvas/ui_markup_view_tests.zig +142 -10
- package/src/primitives/canvas/ui_schema.zig +13 -1
- package/src/primitives/canvas/ui_schema_tests.zig +11 -7
- package/src/primitives/canvas/ui_tests.zig +1 -0
- package/src/primitives/canvas/vector.zig +36 -2
- package/src/primitives/canvas/vector_effect_policy.zig +236 -0
- package/src/primitives/canvas/vector_raster_policy.zig +190 -0
- package/src/primitives/canvas/virtual_extent_policy.zig +350 -0
- package/src/primitives/canvas/virtual_extents.zig +113 -3
- package/src/primitives/canvas/virtual_flow_policy.zig +108 -0
- package/src/primitives/canvas/widget_audit_policy.zig +293 -0
- package/src/primitives/canvas/widget_change_policy.zig +298 -0
- package/src/primitives/canvas/widget_invalidation.zig +113 -2
- package/src/primitives/canvas/widget_layout.zig +673 -128
- package/src/primitives/canvas/widget_layout_tests.zig +4 -0
- package/src/primitives/canvas/widget_metric_policy.zig +129 -0
- package/src/primitives/canvas/widget_metrics.zig +45 -6
- package/src/primitives/canvas/widget_paint_policy.zig +166 -0
- package/src/primitives/canvas/widget_paint_walk_policy.zig +252 -0
- package/src/primitives/canvas/widget_presentation_policy.zig +168 -0
- package/src/primitives/canvas/widget_render.zig +744 -74
- package/src/primitives/canvas/widget_render_controls.zig +1217 -133
- package/src/primitives/canvas/widget_render_scroll.zig +11 -3
- package/src/primitives/canvas/widget_render_style.zig +94 -0
- package/src/primitives/canvas/widget_render_surfaces.zig +61 -50
- package/src/primitives/canvas/widget_routing.zig +75 -0
- package/src/primitives/canvas/widget_routing_policy.zig +135 -0
- package/src/primitives/canvas/widget_runtime.zig +21 -1
- package/src/primitives/canvas/widget_semantics.zig +25 -0
- package/src/primitives/canvas/widget_text_input.zig +86 -23
- package/src/primitives/canvas/widget_text_select.zig +1 -0
- package/src/primitives/canvas/widget_tree.zig +8 -1
- package/src/primitives/canvas/widgets.zig +42 -12
- package/src/primitives/canvas/wrapped_layout_policy.zig +104 -0
- package/src/root.zig +26 -0
- package/src/runtime/accessibility_policy.zig +122 -0
- package/src/runtime/api.zig +29 -0
- package/src/runtime/app_dispatch_policy.zig +68 -0
- package/src/runtime/authorization_policy.zig +150 -0
- package/src/runtime/automation_command_policy.zig +241 -0
- package/src/runtime/automation_interaction_policy.zig +107 -0
- package/src/runtime/automation_snapshot.zig +52 -22
- package/src/runtime/automation_snapshot_reference.zig +290 -0
- package/src/runtime/automation_widget_dispatch.zig +267 -355
- package/src/runtime/automation_widget_dispatch_reference.zig +900 -0
- package/src/runtime/blob_policy.zig +58 -0
- package/src/runtime/blob_reference.zig +64 -0
- package/src/runtime/bridge_descriptor_policy.zig +206 -0
- package/src/runtime/bridge_payload.zig +2 -0
- package/src/runtime/builtin_bridge.zig +180 -44
- package/src/runtime/builtin_coordination_policy.zig +121 -0
- package/src/runtime/callback_policy_test_reference.zig +97 -0
- package/src/runtime/canvas_drag_policy.zig +94 -0
- package/src/runtime/canvas_fonts.zig +38 -10
- package/src/runtime/canvas_frame.zig +590 -134
- package/src/runtime/canvas_frame_helpers.zig +1 -0
- package/src/runtime/canvas_hover_policy.zig +131 -0
- package/src/runtime/canvas_images.zig +59 -30
- package/src/runtime/canvas_keyboard_focus_policy.zig +154 -0
- package/src/runtime/canvas_limits.zig +1 -1
- package/src/runtime/canvas_presentation_lifecycle_policy.zig +86 -0
- package/src/runtime/canvas_scene_observation_policy.zig +181 -0
- package/src/runtime/canvas_widget_context_menu.zig +183 -4
- package/src/runtime/canvas_widget_context_menu_test_cases.zig +1147 -0
- package/src/runtime/canvas_widget_context_menu_tests.zig +23 -1098
- package/src/runtime/canvas_widget_display.zig +110 -9
- package/src/runtime/canvas_widget_events.zig +718 -328
- package/src/runtime/canvas_widget_runtime.zig +720 -150
- package/src/runtime/canvas_widget_scroll_drivers.zig +39 -1
- package/src/runtime/canvas_widget_scroll_tests.zig +31 -0
- package/src/runtime/canvas_widget_state.zig +93 -56
- package/src/runtime/channel_sources.zig +80 -0
- package/src/runtime/command_policy.zig +161 -0
- package/src/runtime/component_policy.zig +83 -0
- package/src/runtime/context_menu_policy.zig +112 -0
- package/src/runtime/core.zig +170 -6
- package/src/runtime/desktop_files.zig +189 -0
- package/src/runtime/effects.zig +638 -33
- package/src/runtime/effects_host_tests.zig +25 -0
- package/src/runtime/effects_tests.zig +28 -0
- package/src/runtime/file_policy_test_reference.zig +113 -0
- package/src/runtime/flow.zig +419 -341
- package/src/runtime/flow_reference.zig +1427 -0
- package/src/runtime/font_registry_policy.zig +72 -0
- package/src/runtime/frame_profile.zig +24 -33
- package/src/runtime/global_shortcuts.zig +75 -0
- package/src/runtime/gpu_surface_events.zig +97 -35
- package/src/runtime/host_event_pump.zig +303 -0
- package/src/runtime/host_event_pump_reference.zig +268 -0
- package/src/runtime/host_flow_policy.zig +155 -0
- package/src/runtime/host_input_regions_policy.zig +156 -0
- package/src/runtime/image_registry_policy.zig +94 -0
- package/src/runtime/input_composition_policy.zig +138 -0
- package/src/runtime/journal_policy.zig +66 -0
- package/src/runtime/journal_reference.zig +53 -0
- package/src/runtime/keyboard_input.zig +86 -0
- package/src/runtime/lifecycle_policy_test_reference.zig +97 -0
- package/src/runtime/markup_development_policy.zig +91 -0
- package/src/runtime/media_surface.zig +40 -1
- package/src/runtime/motion_sampling_policy.zig +159 -0
- package/src/runtime/recording_policy.zig +42 -0
- package/src/runtime/render_animation_policy.zig +206 -0
- package/src/runtime/replay_policy.zig +66 -0
- package/src/runtime/replay_policy_reference.zig +326 -0
- package/src/runtime/replay_progress_policy.zig +64 -0
- package/src/runtime/replay_progress_reference.zig +34 -0
- package/src/runtime/request_policy_test_reference.zig +188 -0
- package/src/runtime/root.zig +16 -0
- package/src/runtime/scroll_mutation_policy.zig +130 -0
- package/src/runtime/scroll_mutation_runtime.zig +158 -0
- package/src/runtime/scroll_tree_policy.zig +99 -0
- package/src/runtime/session_blobs.zig +157 -58
- package/src/runtime/session_blobs_reference.zig +692 -0
- package/src/runtime/session_codec.zig +361 -0
- package/src/runtime/session_codec_reference.zig +1027 -0
- package/src/runtime/session_journal.zig +246 -983
- package/src/runtime/session_record.zig +231 -45
- package/src/runtime/session_replay.zig +157 -415
- package/src/runtime/session_tests.zig +552 -0
- package/src/runtime/shell_admission_policy.zig +225 -0
- package/src/runtime/shell_coordination_policy.zig +138 -0
- package/src/runtime/shell_layout.zig +126 -1
- package/src/runtime/snapshot_policy.zig +60 -0
- package/src/runtime/snapshot_reference.zig +64 -0
- package/src/runtime/staged_rebuild_policy.zig +83 -0
- package/src/runtime/state.zig +16 -0
- package/src/runtime/status_validation.zig +190 -0
- package/src/runtime/system_admission_policy.zig +140 -0
- package/src/runtime/system_services.zig +65 -36
- package/src/runtime/tests.zig +2 -0
- package/src/runtime/ts_canvas_hooks.zig +261 -0
- package/src/runtime/ts_canvas_hooks_tests.zig +279 -0
- package/src/runtime/ts_canvas_icons.zig +234 -0
- package/src/runtime/ts_core_host.zig +2451 -411
- package/src/runtime/ts_core_host_tests.zig +1982 -0
- package/src/runtime/ts_test_host.zig +699 -0
- package/src/runtime/ts_ui_app.zig +1111 -45
- package/src/runtime/ui_app.zig +1381 -650
- package/src/runtime/ui_app_provenance.zig +147 -5
- package/src/runtime/ui_app_provenance_reference.zig +370 -0
- package/src/runtime/ui_app_tests.zig +667 -188
- package/src/runtime/ui_app_window_tests.zig +222 -0
- package/src/runtime/view.zig +25 -0
- package/src/runtime/view_canvas.zig +30 -6
- package/src/runtime/view_coordination_policy.zig +147 -0
- package/src/runtime/view_reload.zig +226 -0
- package/src/runtime/view_widget_control.zig +51 -14
- package/src/runtime/view_widget_scroll.zig +46 -26
- package/src/runtime/view_widget_text.zig +153 -68
- package/src/runtime/view_widget_tree.zig +503 -69
- package/src/runtime/virtual_window_policy.zig +128 -0
- package/src/runtime/web_pane_policy.zig +111 -0
- package/src/runtime/web_pane_test_cases.zig +204 -0
- package/src/runtime/webview_view_bridge_tests.zig +2 -0
- package/src/runtime/widget_continuity_policy.zig +73 -0
- package/src/runtime/widget_motion_policy.zig +238 -0
- package/src/runtime/widget_reconcile_policy.zig +81 -0
- package/src/runtime/widget_retention_policy.zig +75 -0
- package/src/runtime/window_command_bridge_tests.zig +63 -0
- package/src/runtime/window_lifecycle_policy.zig +127 -0
- package/src/runtime/window_storage.zig +74 -8
- package/src/runtime/window_view_runtime.zig +148 -33
- package/src/runtime/window_views.zig +179 -11
- package/src/security/root.zig +1 -0
- package/src/tooling/components/identity_tests.zig +62 -36
- package/src/tooling/components/stepper.native +24 -0
- package/src/tooling/components/stepper.zig +0 -19
- package/src/tooling/components/timeline-item.native +22 -0
- package/src/tooling/components/timeline.native +5 -3
- package/src/tooling/components/timeline_item.zig +0 -32
- package/src/tooling/eject_components.zig +76 -8
- package/src/tooling/ios.zig +66 -12
- package/src/tooling/manifest.zig +35 -0
- package/src/tooling/raw_manifest.zig +6 -0
- package/src/tooling/templates.zig +23 -3
- package/src/tooling/ts_core.zig +97 -4
- package/src/tooling/verbs.zig +87 -1
- package/tools/corewire/build_profile.mjs +54 -0
- package/tools/corewire/contract_intake.ts +303 -0
- package/tools/corewire/contract_intake.zig +82 -0
- package/tools/corewire/core.test.ts +188 -0
- package/tools/corewire/core_abi.zig +55 -0
- package/tools/corewire/core_cases.ts +233 -0
- package/tools/corewire/core_contract.ts +407 -0
- package/tools/corewire/core_emission.ts +136 -0
- package/tools/corewire/core_emission.zig +69 -0
- package/tools/corewire/core_goldens.json +3110 -0
- package/tools/corewire/core_policy.ts +14 -0
- package/tools/corewire/core_policy.zig +48 -0
- package/tools/corewire/core_projection.ts +361 -0
- package/tools/corewire/core_vocabulary.ts +6 -0
- package/tools/corewire/emit.zig +19 -1590
- package/tools/corewire/emit_facade.ts +714 -0
- package/tools/corewire/emit_facade.zig +10 -3752
- package/tools/corewire/emit_mirror.ts +300 -0
- package/tools/corewire/emit_profile.ts +50 -0
- package/tools/corewire/emit_service.ts +331 -0
- package/tools/corewire/emit_service.zig +23 -842
- package/tools/corewire/entry.test.ts +95 -0
- package/tools/corewire/entry_coordination.ts +127 -0
- package/tools/corewire/entry_coordination.zig +190 -0
- package/tools/corewire/facade_templates.ts +85 -0
- package/tools/corewire/filesystem.test.ts +166 -0
- package/tools/corewire/filesystem_coordination.ts +213 -0
- package/tools/corewire/filesystem_coordination.zig +245 -0
- package/tools/corewire/intake.test.ts +39 -0
- package/tools/corewire/intake_cases.ts +55 -0
- package/tools/corewire/intake_goldens.json +12237 -0
- package/tools/corewire/invocation.test.ts +28 -0
- package/tools/corewire/invocation.ts +175 -0
- package/tools/corewire/invocation.zig +136 -0
- package/tools/corewire/invocation_cases.ts +60 -0
- package/tools/corewire/invocation_fixture.ts +33 -0
- package/tools/corewire/invocation_goldens.json +1143 -0
- package/tools/corewire/invocation_tests.zig +111 -0
- package/tools/corewire/invocation_usage.ts +2 -0
- package/tools/corewire/lossless_projection.ts +96 -0
- package/tools/corewire/main.zig +7 -680
- package/tools/corewire/main_reference.zig +415 -0
- package/tools/corewire/mirror_templates.ts +59 -0
- package/tools/corewire/profile.test.ts +248 -0
- package/tools/corewire/profile.zig +56 -0
- package/tools/corewire/profile_emission.ts +204 -0
- package/tools/corewire/profile_library.json +29 -0
- package/tools/corewire/profile_tests.zig +136 -0
- package/tools/corewire/service.test.ts +75 -0
- package/tools/corewire/service_cases.ts +61 -0
- package/tools/corewire/service_contract.zig +40 -146
- package/tools/corewire/service_goldens.json +650 -0
- package/tools/corewire/service_projection.zig +52 -0
- package/tools/corewire/service_templates.ts +14 -0
- package/tools/corewire/shim_rt.zig +9 -0
- package/tools/corewire/sidecar.zig +269 -1438
- package/tools/corewire/emit_profile.zig +0 -521
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
pub const staged_rebuild_policy = @import("staged_rebuild_policy.zig");
|
|
2
|
+
pub const continuity_policy = @import("widget_continuity_policy.zig");
|
|
3
|
+
pub const scroll_tree_policy = @import("scroll_tree_policy.zig");
|
|
4
|
+
const retention = @import("widget_retention_policy.zig");
|
|
5
|
+
const keyboard_focus = @import("canvas_keyboard_focus_policy.zig");
|
|
1
6
|
const std = @import("std");
|
|
2
7
|
const geometry = @import("geometry");
|
|
3
8
|
const canvas = @import("canvas");
|
|
@@ -224,7 +229,7 @@ pub fn restoreCanvasWidgetLayoutScrollOffsets(
|
|
|
224
229
|
previous_runtime_offsets: []const CanvasWidgetSourceScrollEntry,
|
|
225
230
|
previous_source_offsets: []const CanvasWidgetSourceScrollEntry,
|
|
226
231
|
) void {
|
|
227
|
-
restoreCanvasWidgetLayoutScrollOffsetsAtAnchoredDepth(nodes, previous_runtime_offsets, previous_source_offsets, null);
|
|
232
|
+
restoreCanvasWidgetLayoutScrollOffsetsAtAnchoredDepth(nodes, previous_runtime_offsets, previous_source_offsets, null, null, null);
|
|
228
233
|
}
|
|
229
234
|
|
|
230
235
|
fn restoreCanvasWidgetLayoutScrollOffsetsAtAnchoredDepth(
|
|
@@ -232,14 +237,16 @@ fn restoreCanvasWidgetLayoutScrollOffsetsAtAnchoredDepth(
|
|
|
232
237
|
previous_runtime_offsets: []const CanvasWidgetSourceScrollEntry,
|
|
233
238
|
previous_source_offsets: []const CanvasWidgetSourceScrollEntry,
|
|
234
239
|
anchored_depth: ?usize,
|
|
240
|
+
strata: ?canvas.layout_coordination_policy.RetainedPlan,
|
|
241
|
+
policy: scroll_tree_policy.Policy,
|
|
235
242
|
) void {
|
|
236
243
|
for (nodes, 0..) |node, index| {
|
|
237
244
|
if (node.widget.kind != .scroll_view or node.widget.id == 0) continue;
|
|
238
245
|
if (anchored_depth) |depth| {
|
|
239
|
-
if (canvas.anchoredNestingDepth(nodes, index) != depth) continue;
|
|
246
|
+
if ((if (strata) |plan| plan.nesting(index) else canvas.anchoredNestingDepth(nodes, index)) != depth) continue;
|
|
240
247
|
}
|
|
241
248
|
const previous_runtime = canvasWidgetSourceScrollEntryById(previous_runtime_offsets, node.widget.id) orelse continue;
|
|
242
|
-
const previous_source = canvasWidgetSourceScrollEntryById(previous_source_offsets, node.widget.id)
|
|
249
|
+
const previous_source = canvasWidgetSourceScrollEntryById(previous_source_offsets, node.widget.id);
|
|
243
250
|
// Each axis reconciles on its own: a programmatic vertical
|
|
244
251
|
// scroll (source-side `value` change) must not snap a
|
|
245
252
|
// user-scrolled horizontal offset back, and vice versa. Only
|
|
@@ -248,20 +255,18 @@ fn restoreCanvasWidgetLayoutScrollOffsetsAtAnchoredDepth(
|
|
|
248
255
|
// would translate content that never moved (the clamp pass
|
|
249
256
|
// pins the stale value home instead).
|
|
250
257
|
var restore = geometry.OffsetF{};
|
|
251
|
-
if (canvas.widgetScrollsAxis(node.widget, .vertical) and
|
|
252
|
-
|
|
253
|
-
{
|
|
254
|
-
restore.dy =
|
|
255
|
-
nodes[index].widget.value =
|
|
258
|
+
const next_y = if (canvas.widgetCompiledScrollResult(node.widget, .{ .operation = 2, .current = node.widget.value, .previous_source = if (previous_source) |entry| entry.value else null, .retained = previous_runtime.value, .granted = canvas.widgetScrollsAxis(node.widget, .vertical) })) |result| result.dx else if (previous_source != null and canvas.widgetScrollsAxis(node.widget, .vertical) and node.widget.value == previous_source.?.value) previous_runtime.value else node.widget.value;
|
|
259
|
+
const next_x = if (canvas.widgetCompiledScrollResult(node.widget, .{ .operation = 2, .current = node.widget.value_x, .previous_source = if (previous_source) |entry| entry.value_x else null, .retained = previous_runtime.value_x, .granted = canvas.widgetScrollsAxis(node.widget, .horizontal) })) |result| result.dx else if (previous_source != null and canvas.widgetScrollsAxis(node.widget, .horizontal) and node.widget.value_x == previous_source.?.value_x) previous_runtime.value_x else node.widget.value_x;
|
|
260
|
+
if (next_y != node.widget.value) {
|
|
261
|
+
restore.dy = next_y - node.widget.value;
|
|
262
|
+
nodes[index].widget.value = next_y;
|
|
256
263
|
}
|
|
257
|
-
if (
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
restore.dx = previous_runtime.value_x - node.widget.value_x;
|
|
261
|
-
nodes[index].widget.value_x = previous_runtime.value_x;
|
|
264
|
+
if (next_x != node.widget.value_x) {
|
|
265
|
+
restore.dx = next_x - node.widget.value_x;
|
|
266
|
+
nodes[index].widget.value_x = next_x;
|
|
262
267
|
}
|
|
263
268
|
if (restore.dx == 0 and restore.dy == 0) continue;
|
|
264
|
-
|
|
269
|
+
translateCanvasWidgetLayoutScrollDescendantsWithPolicy(policy, nodes, index, .{ .dx = -restore.dx, .dy = -restore.dy });
|
|
265
270
|
}
|
|
266
271
|
}
|
|
267
272
|
|
|
@@ -281,12 +286,14 @@ fn clampCanvasWidgetLayoutProgrammaticScrollOffsets(
|
|
|
281
286
|
previous_runtime_offsets: []const CanvasWidgetSourceScrollEntry,
|
|
282
287
|
previous_source_offsets: []const CanvasWidgetSourceScrollEntry,
|
|
283
288
|
anchored_depth: ?usize,
|
|
289
|
+
strata: ?canvas.layout_coordination_policy.RetainedPlan,
|
|
290
|
+
policy: scroll_tree_policy.Policy,
|
|
284
291
|
) void {
|
|
285
292
|
for (nodes, 0..) |node, index| {
|
|
286
293
|
if (node.widget.kind != .scroll_view or node.widget.id == 0) continue;
|
|
287
294
|
if (node.widget.layout.virtualized and !canvas.widgetVirtualRuntimeScrolled(node.widget)) continue;
|
|
288
295
|
if (anchored_depth) |depth| {
|
|
289
|
-
if (canvas.anchoredNestingDepth(nodes, index) != depth) continue;
|
|
296
|
+
if ((if (strata) |plan| plan.nesting(index) else canvas.anchoredNestingDepth(nodes, index)) != depth) continue;
|
|
290
297
|
}
|
|
291
298
|
|
|
292
299
|
const source_node = source.findById(node.widget.id) orelse continue;
|
|
@@ -299,23 +306,24 @@ fn clampCanvasWidgetLayoutProgrammaticScrollOffsets(
|
|
|
299
306
|
const runtime_echo_x = previous_runtime != null and source_node.widget.value_x == previous_runtime.?.value_x;
|
|
300
307
|
const clamp_y = source_moved_y and !runtime_echo_y;
|
|
301
308
|
const clamp_x = source_moved_x and !runtime_echo_x;
|
|
302
|
-
if (!clamp_y and !clamp_x) continue;
|
|
309
|
+
if (!node.widget.runtime_flags.compiled_scroll_policy and !clamp_y and !clamp_x) continue;
|
|
303
310
|
|
|
304
311
|
const viewport = node.frame.inset(node.widget.layout.padding).normalized();
|
|
305
312
|
if (viewport.isEmpty()) continue;
|
|
306
313
|
|
|
314
|
+
const extents = canvasWidgetLayoutScrollExtentsWithPolicy(policy, nodes, index, viewport);
|
|
307
315
|
const current_y = node.widget.value;
|
|
308
316
|
const current_x = node.widget.value_x;
|
|
309
|
-
const next_y = if (clamp_y)
|
|
317
|
+
const next_y = if (canvas.widgetCompiledScrollResult(node.widget, .{ .operation = 3, .current = current_y, .viewport = viewport.height, .content = extents.dy, .delta = source_node.widget.value, .previous_source = if (previous_source) |entry| entry.value else null, .retained = if (previous_runtime) |entry| entry.value else null, .granted = canvas.widgetScrollsAxis(node.widget, .vertical) })) |result| result.dx else if (clamp_y)
|
|
310
318
|
if (canvas.widgetScrollsAxis(node.widget, .vertical))
|
|
311
|
-
std.math.clamp(@max(0, current_y), 0, @max(0,
|
|
319
|
+
std.math.clamp(@max(0, current_y), 0, @max(0, extents.dy - viewport.height))
|
|
312
320
|
else
|
|
313
321
|
0
|
|
314
322
|
else
|
|
315
323
|
current_y;
|
|
316
|
-
const next_x = if (clamp_x)
|
|
324
|
+
const next_x = if (canvas.widgetCompiledScrollResult(node.widget, .{ .operation = 3, .current = current_x, .viewport = viewport.width, .content = extents.dx, .delta = source_node.widget.value_x, .previous_source = if (previous_source) |entry| entry.value_x else null, .retained = if (previous_runtime) |entry| entry.value_x else null, .granted = canvas.widgetScrollsAxis(node.widget, .horizontal) })) |result| result.dx else if (clamp_x)
|
|
317
325
|
if (canvas.widgetScrollsAxis(node.widget, .horizontal))
|
|
318
|
-
std.math.clamp(@max(0, current_x), 0, @max(0,
|
|
326
|
+
std.math.clamp(@max(0, current_x), 0, @max(0, extents.dx - viewport.width))
|
|
319
327
|
else
|
|
320
328
|
0
|
|
321
329
|
else
|
|
@@ -324,7 +332,7 @@ fn clampCanvasWidgetLayoutProgrammaticScrollOffsets(
|
|
|
324
332
|
|
|
325
333
|
nodes[index].widget.value = next_y;
|
|
326
334
|
nodes[index].widget.value_x = next_x;
|
|
327
|
-
|
|
335
|
+
translateCanvasWidgetLayoutScrollDescendantsWithPolicy(policy, nodes, index, .{
|
|
328
336
|
.dx = if (canvas.widgetScrollsAxis(node.widget, .horizontal)) -(next_x - current_x) else 0,
|
|
329
337
|
.dy = if (canvas.widgetScrollsAxis(node.widget, .vertical)) -(next_y - current_y) else 0,
|
|
330
338
|
});
|
|
@@ -342,13 +350,13 @@ fn previousLayoutHasSelectedTab(previous: canvas.WidgetLayoutTree, id: canvas.Ob
|
|
|
342
350
|
/// viewport. This runs after retained scroll restoration, against final layout
|
|
343
351
|
/// frames, so an already-visible tab preserves the exact offset and a newly
|
|
344
352
|
/// mounted native scroll driver never paints a speculative leading-edge jump.
|
|
345
|
-
fn revealNewlySelectedTabs(previous: canvas.WidgetLayoutTree, nodes: []canvas.WidgetLayoutNode, anchored_depth: ?usize) void {
|
|
353
|
+
pub fn revealNewlySelectedTabs(previous: canvas.WidgetLayoutTree, nodes: []canvas.WidgetLayoutNode, anchored_depth: ?usize, strata: ?canvas.layout_coordination_policy.RetainedPlan) void {
|
|
346
354
|
for (nodes, 0..) |tab_node, tab_index| {
|
|
347
355
|
const tab = tab_node.widget;
|
|
348
356
|
if (tab.semantics.role != .tab or !tab.state.selected) continue;
|
|
349
357
|
if (tab.id != 0 and previousLayoutHasSelectedTab(previous, tab.id)) continue;
|
|
350
358
|
if (anchored_depth) |depth| {
|
|
351
|
-
if (canvas.anchoredNestingDepth(nodes, tab_index) != depth) continue;
|
|
359
|
+
if ((if (strata) |plan| plan.nesting(tab_index) else canvas.anchoredNestingDepth(nodes, tab_index)) != depth) continue;
|
|
352
360
|
}
|
|
353
361
|
|
|
354
362
|
var ancestor = tab_node.parent_index;
|
|
@@ -597,6 +605,17 @@ pub const CanvasWidgetPasteClamp = struct {
|
|
|
597
605
|
};
|
|
598
606
|
|
|
599
607
|
pub fn clampCanvasWidgetPasteText(widget: canvas.Widget, view_text_len: usize, text: []const u8) CanvasWidgetPasteClamp {
|
|
608
|
+
const capacity = @import("canvas_limits.zig").max_canvas_widget_text_bytes_per_view;
|
|
609
|
+
const replaced_len = blk: {
|
|
610
|
+
if (widget.text_composition) |composition| break :blk composition.byteLen(widget.text.len);
|
|
611
|
+
if (canvas.widgetTextSelectionRange(widget)) |range| break :blk range.byteLen(widget.text.len);
|
|
612
|
+
break :blk 0;
|
|
613
|
+
};
|
|
614
|
+
const available = capacity -| (view_text_len -| replaced_len);
|
|
615
|
+
if (widget.interaction_policy != null and (widget.kind == .textarea or canvas.widgetKindSingleLineTextEntry(widget.kind)) and text.len <= capacity) {
|
|
616
|
+
const prepared = canvas.widgetCompiledTextInput(widget, text, 2, null, available) orelse return .{};
|
|
617
|
+
return .{ .text = prepared.text, .truncated = prepared.truncated };
|
|
618
|
+
}
|
|
600
619
|
// Sanitize BEFORE clamping — the shared step for BOTH paste entry
|
|
601
620
|
// points (the cmd+V shortcut and the context-menu Paste). A
|
|
602
621
|
// single-line target strips \r/\n at the edit-derivation seam
|
|
@@ -613,14 +632,6 @@ pub fn clampCanvasWidgetPasteText(widget: canvas.Widget, view_text_len: usize, t
|
|
|
613
632
|
event.insert_text
|
|
614
633
|
else
|
|
615
634
|
return .{};
|
|
616
|
-
const capacity = @import("canvas_limits.zig").max_canvas_widget_text_bytes_per_view;
|
|
617
|
-
const replaced_len = blk: {
|
|
618
|
-
if (widget.text_composition) |composition| break :blk composition.byteLen(widget.text.len);
|
|
619
|
-
if (canvas.widgetTextSelectionRange(widget)) |range| break :blk range.byteLen(widget.text.len);
|
|
620
|
-
break :blk 0;
|
|
621
|
-
};
|
|
622
|
-
const used = view_text_len -| replaced_len;
|
|
623
|
-
const available = capacity -| used;
|
|
624
635
|
if (sanitized.len <= available) return .{ .text = sanitized };
|
|
625
636
|
const clamped = canvas.snapTextOffset(sanitized, available);
|
|
626
637
|
return .{ .text = sanitized[0..clamped], .truncated = true };
|
|
@@ -805,6 +816,45 @@ fn canvasWidgetSourceTextEntryByIdKind(
|
|
|
805
816
|
return null;
|
|
806
817
|
}
|
|
807
818
|
|
|
819
|
+
pub const reconcile_policy = @import("widget_reconcile_policy.zig");
|
|
820
|
+
pub fn canvasWidgetReconcilePlan(policy: reconcile_policy.Policy, layout: canvas.WidgetLayoutTree, controls: *const CanvasWidgetControlEntryIndex, sources: *const CanvasWidgetSourceControlEntryIndex, texts: *const CanvasWidgetTextEntryIndex) ?reconcile_policy.Plan {
|
|
821
|
+
return reconcile_policy.build(policy, layout, controls, sources, texts, canvasWidgetLayoutNodeHidden, canvasWidgetSourceTextFingerprint, canvasWidgetResizableMinWidth);
|
|
822
|
+
}
|
|
823
|
+
pub fn canvasWidgetLayoutNodeWithPlannedText(node: canvas.WidgetLayoutNode, action: reconcile_policy.Action, previous: *const CanvasWidgetTextEntryIndex) canvas.WidgetLayoutNode {
|
|
824
|
+
var copy = node;
|
|
825
|
+
if (action.flags & (16 | 32 | 64 | 128 | 256 | 512) != 0) {
|
|
826
|
+
const entry = previous.firstWithKind(node.widget.id, node.widget.kind) orelse @panic("missing planned text record");
|
|
827
|
+
if (action.flags & 16 != 0) copy.widget.text = entry.text;
|
|
828
|
+
if (action.flags & 32 != 0) copy.widget.value = entry.value;
|
|
829
|
+
if (action.flags & 64 != 0) {
|
|
830
|
+
copy.widget.text_selection = entry.text_selection;
|
|
831
|
+
// Static text restores only selection, never composition.
|
|
832
|
+
if (copy.widget.kind != .text) copy.widget.text_composition = entry.text_composition;
|
|
833
|
+
} else if (action.flags & 128 != 0) copy.widget.text_selection.?.affinity = entry.text_selection.?.affinity;
|
|
834
|
+
if (action.flags & 256 != 0) copy.widget.value_x = entry.value_x;
|
|
835
|
+
if (action.flags & 512 != 0) {
|
|
836
|
+
copy.widget.code_content_width = entry.code_content_width;
|
|
837
|
+
copy.widget.code_content_width_generation = entry.code_content_width_generation;
|
|
838
|
+
copy.widget.code_content_width_font_id = entry.code_content_width_font_id;
|
|
839
|
+
copy.widget.code_content_width_size_bits = entry.code_content_width_size_bits;
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
return if (action.flags & 1024 != 0) canvasWidgetLayoutNodeWithCaretSafeSelection(copy) else copy;
|
|
843
|
+
}
|
|
844
|
+
pub fn canvasWidgetLayoutNodeWithPlannedControl(node: canvas.WidgetLayoutNode, action: reconcile_policy.Action) canvas.WidgetLayoutNode {
|
|
845
|
+
var copy = node;
|
|
846
|
+
if (action.flags & 1 != 0) {
|
|
847
|
+
copy.widget.state.selected = action.flags & 2 != 0;
|
|
848
|
+
copy.widget.value = if (copy.widget.state.selected) 1 else 0;
|
|
849
|
+
}
|
|
850
|
+
if (action.flags & 4 != 0) copy.widget.value = action.value;
|
|
851
|
+
if (action.flags & 8 != 0) {
|
|
852
|
+
copy.frame.width = action.value;
|
|
853
|
+
copy.widget.frame.width = action.value;
|
|
854
|
+
}
|
|
855
|
+
return copy;
|
|
856
|
+
}
|
|
857
|
+
|
|
808
858
|
pub fn canvasWidgetLayoutNodeWithControlReconcileState(
|
|
809
859
|
node: canvas.WidgetLayoutNode,
|
|
810
860
|
layout: canvas.WidgetLayoutTree,
|
|
@@ -832,15 +882,14 @@ pub fn canvasWidgetLayoutNodeWithControlReconcileState(
|
|
|
832
882
|
source_entry.selected
|
|
833
883
|
else
|
|
834
884
|
false;
|
|
835
|
-
const selected =
|
|
836
|
-
source_selected
|
|
837
|
-
else
|
|
838
|
-
entry.state.selected or entry.value >= 0.5;
|
|
885
|
+
const selected = canvasWidgetCompiledToggleSelected(copy.widget, 9, previously_selected, entry.state.selected or entry.value >= 0.5) orelse
|
|
886
|
+
if (source_selected or previously_selected) source_selected else entry.state.selected or entry.value >= 0.5;
|
|
839
887
|
copy.widget.state.selected = selected;
|
|
840
888
|
copy.widget.value = if (selected) 1 else 0;
|
|
841
889
|
},
|
|
842
890
|
.checkbox, .switch_control, .toggle => {
|
|
843
|
-
const selected = entry.state.selected or entry.value >= 0.5
|
|
891
|
+
const selected = canvasWidgetCompiledToggleSelected(copy.widget, 10, false, entry.state.selected or entry.value >= 0.5) orelse
|
|
892
|
+
entry.state.selected or entry.value >= 0.5;
|
|
844
893
|
copy.widget.state.selected = selected;
|
|
845
894
|
copy.widget.value = if (selected) 1 else 0;
|
|
846
895
|
},
|
|
@@ -857,10 +906,8 @@ pub fn canvasWidgetLayoutNodeWithControlReconcileState(
|
|
|
857
906
|
const source_selected = canvasWidgetBooleanSelected(copy.widget);
|
|
858
907
|
const previous_source = previous_source_controls.firstWithKind(copy.widget.id, copy.widget.kind);
|
|
859
908
|
const source_moved = if (previous_source) |source_entry| source_selected != source_entry.selected else false;
|
|
860
|
-
const selected = if (
|
|
861
|
-
source_selected
|
|
862
|
-
else
|
|
863
|
-
entry.state.selected or entry.value >= 0.5;
|
|
909
|
+
const selected = canvasWidgetCompiledAccordionSelected(copy.widget, 9, if (previous_source) |source_entry| source_entry.selected else null, entry.state.selected or entry.value >= 0.5) orelse
|
|
910
|
+
if (source_moved) source_selected else entry.state.selected or entry.value >= 0.5;
|
|
864
911
|
copy.widget.state.selected = selected;
|
|
865
912
|
copy.widget.value = if (selected) 1 else 0;
|
|
866
913
|
},
|
|
@@ -878,11 +925,12 @@ pub fn canvasWidgetLayoutNodeWithControlReconcileState(
|
|
|
878
925
|
copy.widget.value != source_entry.value
|
|
879
926
|
else
|
|
880
927
|
false;
|
|
881
|
-
|
|
882
|
-
|
|
928
|
+
copy.widget.value = canvas.widgetCompiledSliderValue(copy.widget, 1, if (previous_source) |source_entry| source_entry.value else null, entry.value, entry.state.pressed) orelse
|
|
929
|
+
std.math.clamp(if (!source_moved or entry.state.pressed) entry.value else copy.widget.value, 0, 1);
|
|
883
930
|
},
|
|
884
931
|
.resizable => {
|
|
885
|
-
const width =
|
|
932
|
+
const width = canvas.widgetCompiledResizableWidth(copy.widget, 1, entry.value, 0) orelse
|
|
933
|
+
@max(canvasWidgetResizableMinWidth(copy.widget), entry.value);
|
|
886
934
|
copy.frame.width = width;
|
|
887
935
|
copy.widget.frame.width = width;
|
|
888
936
|
},
|
|
@@ -948,10 +996,16 @@ pub fn canvasWidgetLayoutNodeWithTextReconcileState(
|
|
|
948
996
|
const next_source_text = canvasWidgetSourceTextFingerprint(copy.widget.text);
|
|
949
997
|
const source_unchanged = entry.source_text_len == next_source_text.len and entry.source_text_hash == next_source_text.hash;
|
|
950
998
|
const source_matches_runtime_text = std.mem.eql(u8, entry.text, copy.widget.text);
|
|
951
|
-
|
|
999
|
+
const reconcile = canvas.widgetCompiledTextReconcile(copy.widget, .{
|
|
1000
|
+
.source_unchanged = source_unchanged,
|
|
1001
|
+
.source_matches_runtime = source_matches_runtime_text,
|
|
1002
|
+
.previous_source_selection = entry.source_text_selection,
|
|
1003
|
+
.retained_selection = entry.text_selection,
|
|
1004
|
+
}) orelse referenceTextReconcilePolicy(copy.widget, entry, source_unchanged, source_matches_runtime_text);
|
|
1005
|
+
if (!reconcile.retain_state) {
|
|
952
1006
|
return canvasWidgetLayoutNodeWithCaretSafeSelection(copy);
|
|
953
1007
|
}
|
|
954
|
-
if (
|
|
1008
|
+
if (reconcile.retain_text) copy.widget.text = entry.text;
|
|
955
1009
|
// The retained scroll offset rides `value` for every editable
|
|
956
1010
|
// text kind: the textarea's vertical offset and the single-line
|
|
957
1011
|
// field's horizontal one both survive rebuilds through this
|
|
@@ -968,37 +1022,34 @@ pub fn canvasWidgetLayoutNodeWithTextReconcileState(
|
|
|
968
1022
|
copy.widget.code_content_width_size_bits = entry.code_content_width_size_bits;
|
|
969
1023
|
}
|
|
970
1024
|
}
|
|
971
|
-
if (
|
|
1025
|
+
if (reconcile.retain_selection_composition) {
|
|
972
1026
|
copy.widget.text_selection = entry.text_selection;
|
|
973
1027
|
copy.widget.text_composition = entry.text_composition;
|
|
974
|
-
} else if (
|
|
975
|
-
|
|
976
|
-
// and C-ABI controlled models historically echo only
|
|
977
|
-
// anchor/focus, so the bridge materializes `.upstream` on
|
|
978
|
-
// every rebuild. When those offsets faithfully echo the
|
|
979
|
-
// retained selection, keep the retained visual-line owner;
|
|
980
|
-
// changing either offset remains the source-authoritative
|
|
981
|
-
// way to move the selection.
|
|
982
|
-
if (entry.text_selection) |retained_selection| {
|
|
983
|
-
if (source_selection.anchor == retained_selection.anchor and
|
|
984
|
-
source_selection.focus == retained_selection.focus)
|
|
985
|
-
{
|
|
986
|
-
const source_affinity_changed = if (entry.source_text_selection) |previous_source_selection|
|
|
987
|
-
source_selection.affinity != previous_source_selection.affinity
|
|
988
|
-
else
|
|
989
|
-
// The legacy shape can only materialize upstream;
|
|
990
|
-
// a first downstream value is therefore explicit.
|
|
991
|
-
source_selection.affinity != .upstream;
|
|
992
|
-
if (!source_affinity_changed) {
|
|
993
|
-
source_selection.affinity = retained_selection.affinity;
|
|
994
|
-
}
|
|
995
|
-
}
|
|
996
|
-
}
|
|
1028
|
+
} else if (reconcile.retain_affinity) {
|
|
1029
|
+
copy.widget.text_selection.?.affinity = entry.text_selection.?.affinity;
|
|
997
1030
|
}
|
|
998
1031
|
}
|
|
999
1032
|
return canvasWidgetLayoutNodeWithCaretSafeSelection(copy);
|
|
1000
1033
|
}
|
|
1001
1034
|
|
|
1035
|
+
fn referenceTextReconcilePolicy(widget: canvas.Widget, entry: *const CanvasWidgetTextReconcileEntry, source_unchanged: bool, source_matches_runtime: bool) canvas.TextReconcilePolicyResult {
|
|
1036
|
+
var retain_affinity = false;
|
|
1037
|
+
if (widget.text_selection) |source| {
|
|
1038
|
+
if (entry.text_selection) |retained| {
|
|
1039
|
+
// Byte-identical legacy source echoes carry upstream affinity;
|
|
1040
|
+
// preserve the runtime's painted stop unless the source changed it.
|
|
1041
|
+
const affinity_changed = if (entry.source_text_selection) |previous| source.affinity != previous.affinity else source.affinity != .upstream;
|
|
1042
|
+
retain_affinity = source.anchor == retained.anchor and source.focus == retained.focus and !affinity_changed;
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
return .{
|
|
1046
|
+
.retain_text = source_unchanged,
|
|
1047
|
+
.retain_state = source_unchanged or source_matches_runtime,
|
|
1048
|
+
.retain_selection_composition = widget.text_selection == null and widget.text_composition == null,
|
|
1049
|
+
.retain_affinity = retain_affinity,
|
|
1050
|
+
};
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1002
1053
|
fn canvasWidgetLayoutNodeWithCaretSafeSelection(node: canvas.WidgetLayoutNode) canvas.WidgetLayoutNode {
|
|
1003
1054
|
var copy = node;
|
|
1004
1055
|
if (!canvasWidgetEditableTextKind(copy.widget.kind)) return copy;
|
|
@@ -1033,16 +1084,19 @@ pub fn canvasWidgetLayoutTreeWithRuntimeReconcileState(
|
|
|
1033
1084
|
) anyerror!canvas.WidgetLayoutTree {
|
|
1034
1085
|
if (next.nodes.len > node_buffer.len) return error.WidgetNodeLimitReached;
|
|
1035
1086
|
|
|
1036
|
-
const previous_control_states =
|
|
1087
|
+
const previous_control_states = collectCanvasWidgetControlReconcileEntriesWithPolicy(
|
|
1088
|
+
tokens.widget_retention_policy,
|
|
1037
1089
|
previous.nodes,
|
|
1038
1090
|
control_entries,
|
|
1039
1091
|
);
|
|
1040
|
-
const previous_runtime_offsets =
|
|
1092
|
+
const previous_runtime_offsets = collectCanvasWidgetScrollOffsetEntriesWithPolicy(
|
|
1093
|
+
tokens.widget_retention_policy,
|
|
1041
1094
|
previous.nodes,
|
|
1042
1095
|
scroll_offset_entries,
|
|
1043
1096
|
);
|
|
1044
1097
|
var text_len: usize = 0;
|
|
1045
|
-
const previous_text_states = try
|
|
1098
|
+
const previous_text_states = try collectCanvasWidgetTextReconcileEntriesWithPolicy(
|
|
1099
|
+
tokens.widget_retention_policy,
|
|
1046
1100
|
previous.nodes,
|
|
1047
1101
|
previous_source_text_entries,
|
|
1048
1102
|
text_entries,
|
|
@@ -1076,75 +1130,132 @@ pub fn canvasWidgetLayoutTreeWithRuntimeReconcileState(
|
|
|
1076
1130
|
const staged_nodes = node_buffer[0..next.nodes.len];
|
|
1077
1131
|
@memcpy(staged_nodes, next.nodes);
|
|
1078
1132
|
const staged_root_bounds = next.root_bounds orelse if (staged_nodes.len > 0) staged_nodes[0].frame else geometry.RectF.init(0, 0, 0, 0);
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
canvas.slideSplitChildren(node.frame, previous_runtime, index, staged_nodes);
|
|
1122
|
-
} else {
|
|
1123
|
-
try canvas.relayoutSplitChildren(staged_nodes[index].widget, node.frame, index, node.depth, node_buffer, staged_root_bounds, tokens);
|
|
1133
|
+
var strata_scratch = std.heap.stackFallback(2048, std.heap.page_allocator);
|
|
1134
|
+
const strata = if (tokens.layout_coordination_policy) |policy|
|
|
1135
|
+
canvas.layout_coordination_policy.RetainedPlan.init(strata_scratch.get(), policy, staged_nodes) catch @panic("reconcile strata allocation failed")
|
|
1136
|
+
else
|
|
1137
|
+
null;
|
|
1138
|
+
defer if (strata) |plan| plan.deinit();
|
|
1139
|
+
const max_anchored_depth = if (strata) |plan| plan.maximum() else canvas.maxAnchoredNestingDepth(staged_nodes);
|
|
1140
|
+
if (tokens.staged_rebuild_policy) |policy| {
|
|
1141
|
+
var program = staged_rebuild_policy.Program.init(policy, staged_nodes.len, max_anchored_depth);
|
|
1142
|
+
for (staged_nodes, 0..) |node, i| program.setNode(i, node, if (strata) |plan| plan.nesting(i) else canvas.anchoredNestingDepth(staged_nodes, i));
|
|
1143
|
+
while (true) {
|
|
1144
|
+
const step = program.next();
|
|
1145
|
+
switch (step.kind) {
|
|
1146
|
+
.done => break,
|
|
1147
|
+
.split => {
|
|
1148
|
+
// Read the node AFTER prior mutations: an outer split
|
|
1149
|
+
// or anchored replay may have rebuilt this source value.
|
|
1150
|
+
const node = staged_nodes[step.index];
|
|
1151
|
+
const result = staged_rebuild_policy.split(policy, node, canvasWidgetSourceScrollById(previous_runtime_offsets, node.widget.id), canvasWidgetSourceScrollById(previous_source_scroll_entries, node.widget.id), objectIdInList(armed_split_tween_ids, node.widget.id), pressed_split_id != 0 and node.widget.id == pressed_split_id);
|
|
1152
|
+
switch (result.kind) {
|
|
1153
|
+
.keep => {},
|
|
1154
|
+
.enter_slide => canvas.slideSplitChildrenWithTokens(node.frame, result.value, step.index, staged_nodes, tokens),
|
|
1155
|
+
.value_only => staged_nodes[step.index].widget.value = result.value,
|
|
1156
|
+
.slide => {
|
|
1157
|
+
staged_nodes[step.index].widget.value = result.value;
|
|
1158
|
+
canvas.slideSplitChildrenWithTokens(node.frame, result.value, step.index, staged_nodes, tokens);
|
|
1159
|
+
},
|
|
1160
|
+
.relayout => {
|
|
1161
|
+
staged_nodes[step.index].widget.value = result.value;
|
|
1162
|
+
try canvas.relayoutSplitChildren(staged_nodes[step.index].widget, node.frame, step.index, node.depth, node_buffer, staged_root_bounds, tokens);
|
|
1163
|
+
},
|
|
1164
|
+
}
|
|
1165
|
+
program.refreshAdmission(staged_nodes);
|
|
1166
|
+
},
|
|
1167
|
+
.restore_scroll => restoreCanvasWidgetLayoutScrollOffsetsAtAnchoredDepth(staged_nodes, previous_runtime_offsets, previous_source_scroll_entries, step.depth, strata, tokens.scroll_tree_policy),
|
|
1168
|
+
.clamp_scroll => clampCanvasWidgetLayoutProgrammaticScrollOffsets(staged_nodes, next, previous_runtime_offsets, previous_source_scroll_entries, step.depth, strata, tokens.scroll_tree_policy),
|
|
1169
|
+
.reveal_tabs => revealNewlySelectedTabsWithPolicy(tokens.scroll_tree_policy, previous, staged_nodes, step.depth, strata),
|
|
1170
|
+
.anchors => {
|
|
1171
|
+
try canvas.relayoutAnchoredChildrenAtDepth(staged_nodes, staged_root_bounds, tokens, step.depth);
|
|
1172
|
+
if (strata) |plan| for (staged_nodes, 0..) |node, i| plan.setNode(i, node);
|
|
1173
|
+
for (staged_nodes, 0..) |node, i| program.setNode(i, node, if (strata) |plan| plan.nesting(i) else canvas.anchoredNestingDepth(staged_nodes, i));
|
|
1174
|
+
},
|
|
1124
1175
|
}
|
|
1125
1176
|
}
|
|
1177
|
+
} else {
|
|
1178
|
+
var anchored_depth: usize = 0;
|
|
1179
|
+
while (anchored_depth <= max_anchored_depth) : (anchored_depth += 1) {
|
|
1180
|
+
for (staged_nodes, 0..) |node, index| {
|
|
1181
|
+
if (node.widget.kind != .split or node.widget.id == 0) continue;
|
|
1182
|
+
if ((if (strata) |plan| plan.nesting(index) else canvas.anchoredNestingDepth(staged_nodes, index)) != anchored_depth) continue;
|
|
1183
|
+
const tween_armed = objectIdInList(armed_split_tween_ids, node.widget.id);
|
|
1184
|
+
const previous_runtime = canvasWidgetSourceScrollById(previous_runtime_offsets, node.widget.id) orelse {
|
|
1185
|
+
// A FRESH split (no retained fraction): a declared enter
|
|
1186
|
+
// origin slides the first layout's boundary to the origin
|
|
1187
|
+
// pose — children keep the declared value's (target) wrap —
|
|
1188
|
+
// so the tween armed right after this reconcile eases it in
|
|
1189
|
+
// instead of the mount popping to its value.
|
|
1190
|
+
if (node.widget.resize_duration_ms != 0 and node.widget.resize_origin >= 0 and node.widget.children.len != 0) {
|
|
1191
|
+
canvas.slideSplitChildrenWithTokens(node.frame, node.widget.resize_origin, index, staged_nodes, tokens);
|
|
1192
|
+
}
|
|
1193
|
+
continue;
|
|
1194
|
+
};
|
|
1195
|
+
const previous_source = canvasWidgetSourceScrollById(previous_source_scroll_entries, node.widget.id);
|
|
1196
|
+
// Source-wins: the runtime-owned fraction survives rebuilds only
|
|
1197
|
+
// while the SOURCE fraction is unchanged; a source-side change
|
|
1198
|
+
// (the model echoing or driving the fraction) wins — UNLESS the
|
|
1199
|
+
// split declares a layout tween (`resize_duration_ms` nonzero)
|
|
1200
|
+
// or one is already in flight: then the moved source value is a
|
|
1201
|
+
// TARGET, the rendered fraction stays where it is, and the
|
|
1202
|
+
// runtime's tween lowering (armed right after this reconcile
|
|
1203
|
+
// lands, in setCanvasWidgetLayout) eases it there one presented
|
|
1204
|
+
// frame at a time. Reduced motion still snaps: the tween
|
|
1205
|
+
// lowering's snap path applies the target through this same
|
|
1206
|
+
// mutation family in the same rebuild.
|
|
1207
|
+
const source_moved = if (previous_source) |source| node.widget.value != source else false;
|
|
1208
|
+
const retained_fraction = canvas.widgetCompiledSplitValue(node.widget, .{
|
|
1209
|
+
.operation = 2,
|
|
1210
|
+
.value = node.widget.value,
|
|
1211
|
+
.previous_source = previous_source,
|
|
1212
|
+
.retained = previous_runtime,
|
|
1213
|
+
.declared_tween = node.widget.resize_duration_ms != 0,
|
|
1214
|
+
.armed_tween = tween_armed,
|
|
1215
|
+
}) orelse if (previous_source == null or (source_moved and node.widget.resize_duration_ms == 0 and !tween_armed)) node.widget.value else previous_runtime;
|
|
1216
|
+
if (node.widget.value == retained_fraction) continue;
|
|
1217
|
+
staged_nodes[index].widget.value = retained_fraction;
|
|
1218
|
+
// Retained trees clear children; a split without them keeps the
|
|
1219
|
+
// value restore only (frames follow on the next full layout).
|
|
1220
|
+
if (node.widget.children.len == 0) continue;
|
|
1221
|
+
// A pressed divider is a live drag: its echo rebuilds must keep
|
|
1222
|
+
// re-wrapping at the dragged width (the pinned drag behavior),
|
|
1223
|
+
// so the slide shape only applies to tween-owned motion.
|
|
1224
|
+
const dragging = pressed_split_id != 0 and node.widget.id == pressed_split_id;
|
|
1225
|
+
if (!dragging and (tween_armed or (source_moved and node.widget.resize_duration_ms != 0))) {
|
|
1226
|
+
canvas.slideSplitChildrenWithTokens(node.frame, retained_fraction, index, staged_nodes, tokens);
|
|
1227
|
+
} else {
|
|
1228
|
+
try canvas.relayoutSplitChildren(staged_nodes[index].widget, node.frame, index, node.depth, node_buffer, staged_root_bounds, tokens);
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1126
1231
|
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1232
|
+
// Scroll restore is staged too (after splits, so translated frames
|
|
1233
|
+
// are final geometry): the retained offset comes back WITH its
|
|
1234
|
+
// descendants translated to match. Engine-side clamping happens at
|
|
1235
|
+
// the caller AFTER native scroll drivers are stamped — a rebuild
|
|
1236
|
+
// mid-rubber-band must not clamp an offset the OS scroller owns.
|
|
1237
|
+
restoreCanvasWidgetLayoutScrollOffsetsAtAnchoredDepth(
|
|
1238
|
+
staged_nodes,
|
|
1239
|
+
previous_runtime_offsets,
|
|
1240
|
+
previous_source_scroll_entries,
|
|
1241
|
+
anchored_depth,
|
|
1242
|
+
strata,
|
|
1243
|
+
tokens.scroll_tree_policy,
|
|
1244
|
+
);
|
|
1245
|
+
clampCanvasWidgetLayoutProgrammaticScrollOffsets(
|
|
1246
|
+
staged_nodes,
|
|
1247
|
+
next,
|
|
1248
|
+
previous_runtime_offsets,
|
|
1249
|
+
previous_source_scroll_entries,
|
|
1250
|
+
anchored_depth,
|
|
1251
|
+
strata,
|
|
1252
|
+
tokens.scroll_tree_policy,
|
|
1253
|
+
);
|
|
1254
|
+
revealNewlySelectedTabsWithPolicy(tokens.scroll_tree_policy, previous, staged_nodes, anchored_depth, strata);
|
|
1255
|
+
if (anchored_depth < max_anchored_depth) {
|
|
1256
|
+
try canvas.relayoutAnchoredChildrenAtDepth(staged_nodes, staged_root_bounds, tokens, anchored_depth);
|
|
1257
|
+
if (strata) |plan| for (staged_nodes, 0..) |node, i| plan.setNode(i, node);
|
|
1258
|
+
}
|
|
1148
1259
|
}
|
|
1149
1260
|
}
|
|
1150
1261
|
|
|
@@ -1155,14 +1266,50 @@ pub fn canvasWidgetLayoutTreeWithRuntimeReconcileState(
|
|
|
1155
1266
|
index_scratch.semantics.build(source_semantics);
|
|
1156
1267
|
|
|
1157
1268
|
const staged = canvas.WidgetLayoutTree{ .nodes = staged_nodes, .root_bounds = next.root_bounds };
|
|
1269
|
+
const reconcile_plan = canvasWidgetReconcilePlan(tokens.widget_reconcile_policy, staged, &index_scratch.controls, &index_scratch.source_controls, &index_scratch.texts);
|
|
1270
|
+
const continuity_plan = continuity_policy.layout(tokens.widget_continuity_policy, staged_nodes, @as([]const CanvasWidgetScrollReconcileEntry, &.{}), &index_scratch.semantics);
|
|
1158
1271
|
for (staged_nodes, 0..) |node, index| {
|
|
1159
|
-
const text_copy = canvasWidgetLayoutNodeWithTextReconcileState(node, staged, index, &index_scratch.texts);
|
|
1160
|
-
const control_copy = canvasWidgetLayoutNodeWithControlReconcileState(text_copy, staged, index, &index_scratch.controls, &index_scratch.source_controls);
|
|
1161
|
-
node_buffer[index] =
|
|
1272
|
+
const text_copy = if (reconcile_plan) |*plan| canvasWidgetLayoutNodeWithPlannedText(node, plan.entries[index], &index_scratch.texts) else canvasWidgetLayoutNodeWithTextReconcileState(node, staged, index, &index_scratch.texts);
|
|
1273
|
+
const control_copy = if (reconcile_plan) |*plan| canvasWidgetLayoutNodeWithPlannedControl(text_copy, plan.entries[index]) else canvasWidgetLayoutNodeWithControlReconcileState(text_copy, staged, index, &index_scratch.controls, &index_scratch.source_controls);
|
|
1274
|
+
node_buffer[index] = canvasWidgetLayoutNodeWithPlannedSourceSemantics(control_copy, &index_scratch.semantics, if (continuity_plan) |plan| plan.actions[index] else null);
|
|
1162
1275
|
}
|
|
1163
1276
|
const reconciled = node_buffer[0..next.nodes.len];
|
|
1164
1277
|
clampCanvasWidgetLayoutTextOffsets(reconciled, tokens);
|
|
1165
|
-
return .{ .nodes = reconciled, .root_bounds = next.root_bounds };
|
|
1278
|
+
return .{ .nodes = reconciled, .root_bounds = next.root_bounds, .change_policy = next.change_policy, .text_run_policy = next.text_run_policy };
|
|
1279
|
+
}
|
|
1280
|
+
|
|
1281
|
+
/// Apply only the compiled selection; complete records and physics remain in
|
|
1282
|
+
/// native-owned storage. Null plans preserve the independent native reference.
|
|
1283
|
+
pub fn canvasWidgetLayoutNodeWithPlannedSourceSemantics(node: canvas.WidgetLayoutNode, sources: *const CanvasWidgetSemanticsIndex, action: ?u8) canvas.WidgetLayoutNode {
|
|
1284
|
+
const flags = action orelse return canvasWidgetLayoutNodeWithSourceSemantics(node, sources);
|
|
1285
|
+
var copy = node;
|
|
1286
|
+
if (flags & 1 != 0) {
|
|
1287
|
+
const source = sources.first(node.widget.id) orelse @panic("missing planned source semantics");
|
|
1288
|
+
copy.widget.semantics.list_item_index = source.list.item_index;
|
|
1289
|
+
copy.widget.semantics.list_item_count = source.list.item_count;
|
|
1290
|
+
}
|
|
1291
|
+
return copy;
|
|
1292
|
+
}
|
|
1293
|
+
pub fn canvasWidgetScrollStateWithPlan(node: canvas.WidgetLayoutNode, previous: []const CanvasWidgetScrollReconcileEntry, action: ?u8) canvas.ScrollState {
|
|
1294
|
+
const flags = action orelse return canvasWidgetScrollStateForLayoutNode(node, previous);
|
|
1295
|
+
var state = canvas.ScrollState{ .offset_y = node.widget.value, .offset_x = node.widget.value_x };
|
|
1296
|
+
if (flags & 12 != 0) for (previous) |entry| {
|
|
1297
|
+
if (entry.id != node.widget.id) continue;
|
|
1298
|
+
if (flags & 4 != 0) state.velocity_y = entry.state.velocity_y;
|
|
1299
|
+
if (flags & 8 != 0) state.velocity_x = entry.state.velocity_x;
|
|
1300
|
+
break;
|
|
1301
|
+
};
|
|
1302
|
+
return state;
|
|
1303
|
+
}
|
|
1304
|
+
pub fn applyCanvasWidgetSourceScrollSemanticsWithPolicy(policy: continuity_policy.Policy, nodes: []canvas.WidgetSemanticsNode, sources: *const CanvasWidgetSemanticsIndex) void {
|
|
1305
|
+
const plan = continuity_policy.semanticsPlan(policy, nodes, sources) orelse return applyCanvasWidgetSourceScrollSemantics(nodes, sources);
|
|
1306
|
+
for (nodes, 0..) |*node, i| if (plan.actions[i] & 2 != 0) {
|
|
1307
|
+
const source = sources.first(node.id) orelse @panic("missing planned scroll semantics");
|
|
1308
|
+
node.value = source.value;
|
|
1309
|
+
node.scroll = source.scroll;
|
|
1310
|
+
node.actions = source.actions;
|
|
1311
|
+
node.focusable = source.focusable;
|
|
1312
|
+
};
|
|
1166
1313
|
}
|
|
1167
1314
|
|
|
1168
1315
|
pub fn canvasWidgetLayoutNodeWithSourceSemantics(
|
|
@@ -1251,21 +1398,22 @@ fn clampCanvasWidgetLayoutScrollOffsetsImpl(
|
|
|
1251
1398
|
const viewport = node.frame.inset(node.widget.layout.padding).normalized();
|
|
1252
1399
|
if (viewport.isEmpty()) continue;
|
|
1253
1400
|
|
|
1254
|
-
const
|
|
1401
|
+
const extents = canvasWidgetLayoutScrollExtentsWithPolicy(tokens.scroll_tree_policy, nodes, index, viewport);
|
|
1402
|
+
const content_extent = extents.dy;
|
|
1255
1403
|
const max_offset = @max(0, content_extent - viewport.height);
|
|
1256
1404
|
const current_offset = node.widget.value;
|
|
1257
1405
|
// An offset on an axis the region does not grant pins home: a
|
|
1258
1406
|
// rebuild that flips the axis (or virtualizes the region) must
|
|
1259
1407
|
// not leave content displaced along the revoked axis.
|
|
1260
|
-
const next_offset = if (canvas.widgetScrollsAxis(node.widget, .vertical))
|
|
1408
|
+
const next_offset = if (canvas.widgetCompiledScrollResult(node.widget, .{ .operation = 0, .current = current_offset, .viewport = viewport.height, .content = content_extent, .granted = canvas.widgetScrollsAxis(node.widget, .vertical) })) |result| result.dx else if (canvas.widgetScrollsAxis(node.widget, .vertical))
|
|
1261
1409
|
std.math.clamp(@max(0, current_offset), 0, max_offset)
|
|
1262
1410
|
else
|
|
1263
1411
|
0;
|
|
1264
1412
|
|
|
1265
|
-
const content_extent_x =
|
|
1413
|
+
const content_extent_x = extents.dx;
|
|
1266
1414
|
const max_offset_x = @max(0, content_extent_x - viewport.width);
|
|
1267
1415
|
const current_offset_x = node.widget.value_x;
|
|
1268
|
-
const next_offset_x = if (canvas.widgetScrollsAxis(node.widget, .horizontal))
|
|
1416
|
+
const next_offset_x = if (canvas.widgetCompiledScrollResult(node.widget, .{ .operation = 0, .current = current_offset_x, .viewport = viewport.width, .content = content_extent_x, .granted = canvas.widgetScrollsAxis(node.widget, .horizontal) })) |result| result.dx else if (canvas.widgetScrollsAxis(node.widget, .horizontal))
|
|
1269
1417
|
std.math.clamp(@max(0, current_offset_x), 0, max_offset_x)
|
|
1270
1418
|
else
|
|
1271
1419
|
0;
|
|
@@ -1276,7 +1424,7 @@ fn clampCanvasWidgetLayoutScrollOffsetsImpl(
|
|
|
1276
1424
|
// Only granted axes translate: the layout pass never displaced
|
|
1277
1425
|
// children along an ungranted axis (`scrollLayoutOffset` gates
|
|
1278
1426
|
// it), so pinning that value home is bookkeeping, not motion.
|
|
1279
|
-
|
|
1427
|
+
translateCanvasWidgetLayoutScrollDescendantsWithPolicy(tokens.scroll_tree_policy, nodes, index, .{
|
|
1280
1428
|
.dx = if (canvas.widgetScrollsAxis(node.widget, .horizontal)) -(next_offset_x - current_offset_x) else 0,
|
|
1281
1429
|
.dy = if (canvas.widgetScrollsAxis(node.widget, .vertical)) -(next_offset - current_offset) else 0,
|
|
1282
1430
|
});
|
|
@@ -1324,6 +1472,34 @@ pub fn clampCanvasWidgetLayoutTextOffsets(nodes: []canvas.WidgetLayoutNode, toke
|
|
|
1324
1472
|
}
|
|
1325
1473
|
}
|
|
1326
1474
|
|
|
1475
|
+
/// A fresh copied plan observes every earlier split/scroll mutation. Never
|
|
1476
|
+
/// cache geometry plans across relayout or across two selected-tab reveals.
|
|
1477
|
+
pub fn canvasWidgetLayoutScrollExtentsWithPolicy(policy: scroll_tree_policy.Policy, nodes: []const canvas.WidgetLayoutNode, index: usize, viewport: geometry.RectF) geometry.OffsetF {
|
|
1478
|
+
if (index >= nodes.len) return .{};
|
|
1479
|
+
if (scroll_tree_policy.build(policy, nodes, .{ .operation = 0, .target = index, .viewport = viewport })) |plan| return .{ .dx = plan.x, .dy = plan.y };
|
|
1480
|
+
return .{ .dx = canvasWidgetLayoutScrollContentExtentX(nodes, index, viewport), .dy = canvasWidgetLayoutScrollContentExtent(nodes, index, viewport) };
|
|
1481
|
+
}
|
|
1482
|
+
|
|
1483
|
+
pub fn translateCanvasWidgetLayoutScrollDescendantsWithPolicy(policy: scroll_tree_policy.Policy, nodes: []canvas.WidgetLayoutNode, index: usize, offset: geometry.OffsetF) void {
|
|
1484
|
+
if (index >= nodes.len) return;
|
|
1485
|
+
if (scroll_tree_policy.build(policy, nodes, .{ .operation = 1, .target = index })) |plan| {
|
|
1486
|
+
plan.translate(nodes, offset);
|
|
1487
|
+
} else translateCanvasWidgetLayoutScrollDescendants(nodes, index, offset);
|
|
1488
|
+
}
|
|
1489
|
+
|
|
1490
|
+
pub fn revealNewlySelectedTabsWithPolicy(policy: scroll_tree_policy.Policy, previous: canvas.WidgetLayoutTree, nodes: []canvas.WidgetLayoutNode, anchored_depth: ?usize, strata: ?canvas.layout_coordination_policy.RetainedPlan) void {
|
|
1491
|
+
if (policy == null) return revealNewlySelectedTabs(previous, nodes, anchored_depth, strata);
|
|
1492
|
+
var cursor: usize = 0;
|
|
1493
|
+
while (cursor < nodes.len) {
|
|
1494
|
+
const plan = scroll_tree_policy.build(policy, nodes, .{ .operation = 2, .target = cursor, .previous = previous, .anchored_depth = anchored_depth, .strata = strata }).?;
|
|
1495
|
+
if (plan.target) |index| {
|
|
1496
|
+
nodes[index].widget.value_x = plan.y;
|
|
1497
|
+
plan.translate(nodes, .{ .dx = plan.x });
|
|
1498
|
+
}
|
|
1499
|
+
cursor = plan.cursor;
|
|
1500
|
+
}
|
|
1501
|
+
}
|
|
1502
|
+
|
|
1327
1503
|
pub fn canvasWidgetLayoutScrollContentExtent(nodes: []const canvas.WidgetLayoutNode, scroll_index: usize, viewport: geometry.RectF) f32 {
|
|
1328
1504
|
if (scroll_index >= nodes.len) return 0;
|
|
1329
1505
|
const scroll_node = nodes[scroll_index];
|
|
@@ -1555,6 +1731,15 @@ pub fn canvasWidgetSpatialFocusAllowed(layout: canvas.WidgetLayoutTree, focused:
|
|
|
1555
1731
|
};
|
|
1556
1732
|
}
|
|
1557
1733
|
|
|
1734
|
+
pub fn canvasWidgetSpatialFocusAllowedWithPolicy(layout: canvas.WidgetLayoutTree, focused: canvas.WidgetFocusTarget, target: canvas.WidgetFocusTarget, direction: canvas.WidgetFocusDirection, policy: keyboard_focus.Policy) bool {
|
|
1735
|
+
const focused_scope = canvasWidgetRadioGroupScopeIndex(layout, focused.index);
|
|
1736
|
+
const target_scope = canvasWidgetRadioGroupScopeIndex(layout, target.index);
|
|
1737
|
+
const facts: u16 = @as(u16, if (canvasWidgetFocusTargetsShareParent(layout, focused, target)) 1 else 0) |
|
|
1738
|
+
@as(u16, if (focused_scope != null) 2 else 0) | @as(u16, if (target_scope != null) 4 else 0) |
|
|
1739
|
+
@as(u16, if (focused_scope != null and focused_scope == target_scope) 8 else 0);
|
|
1740
|
+
return keyboard_focus.decide(policy, .{ .stage = .spatial, .a = keyboard_focus.directionCode(direction), .kind = focused.kind, .target = target.kind, .parent = canvasWidgetFocusParentKind(layout, focused), .facts = facts }) != 0;
|
|
1741
|
+
}
|
|
1742
|
+
|
|
1558
1743
|
pub fn canvasWidgetFocusTargetsShareParent(layout: canvas.WidgetLayoutTree, a: canvas.WidgetFocusTarget, b: canvas.WidgetFocusTarget) bool {
|
|
1559
1744
|
if (a.index >= layout.nodes.len or b.index >= layout.nodes.len) return false;
|
|
1560
1745
|
return layout.nodes[a.index].parent_index == layout.nodes[b.index].parent_index;
|
|
@@ -1597,12 +1782,30 @@ pub const CanvasWidgetGroupDirection = enum {
|
|
|
1597
1782
|
};
|
|
1598
1783
|
|
|
1599
1784
|
pub fn canvasWidgetGroupDirectionalFocusTarget(layout: canvas.WidgetLayoutTree, focused: canvas.WidgetFocusTarget, direction: canvas.WidgetFocusDirection) ?canvas.WidgetFocusTarget {
|
|
1785
|
+
return canvasWidgetGroupDirectionalFocusTargetWithPolicy(layout, focused, direction, null);
|
|
1786
|
+
}
|
|
1787
|
+
|
|
1788
|
+
pub fn canvasWidgetGroupDirectionalFocusTargetWithPolicy(layout: canvas.WidgetLayoutTree, focused: canvas.WidgetFocusTarget, direction: canvas.WidgetFocusDirection, policy: keyboard_focus.Policy) ?canvas.WidgetFocusTarget {
|
|
1600
1789
|
if (canvasWidgetRadioGroupDirectionalFocusTarget(layout, focused, direction)) |target| return target;
|
|
1601
1790
|
if (focused.index >= layout.nodes.len) return null;
|
|
1602
1791
|
const parent_index = layout.nodes[focused.index].parent_index orelse return null;
|
|
1603
1792
|
if (parent_index >= layout.nodes.len) return null;
|
|
1604
1793
|
const parent_kind = layout.nodes[parent_index].widget.kind;
|
|
1605
|
-
const
|
|
1794
|
+
const decision = keyboard_focus.decide(policy, .{ .stage = .group, .a = keyboard_focus.directionCode(direction), .kind = focused.kind, .parent = parent_kind });
|
|
1795
|
+
const group_direction: CanvasWidgetGroupDirection = switch (decision) {
|
|
1796
|
+
1 => .previous,
|
|
1797
|
+
2 => .next,
|
|
1798
|
+
else => return null,
|
|
1799
|
+
};
|
|
1800
|
+
if (parent_kind == .tabs and focused.kind == .segmented_control and layout.nodes[focused.index].widget.interaction_policy != null)
|
|
1801
|
+
return compiledTabsFocus(layout, focused.index, if (group_direction == .previous) 4 else 5);
|
|
1802
|
+
if (parent_kind == .list and focused.kind == .list_item and layout.nodes[focused.index].widget.interaction_policy != null)
|
|
1803
|
+
return compiledListFocus(layout, focused.index, if (group_direction == .previous) 4 else 5);
|
|
1804
|
+
if ((parent_kind == .menu_surface or parent_kind == .dropdown_menu) and focused.kind == .menu_item and layout.nodes[focused.index].widget.interaction_policy != null)
|
|
1805
|
+
return canvasWidgetCompiledMenuFocus(layout, focused.index, if (group_direction == .previous) 4 else 5);
|
|
1806
|
+
if (parent_kind == .toggle_group and focused.kind == .toggle_button and layout.nodes[focused.index].widget.interaction_policy != null)
|
|
1807
|
+
return canvasWidgetCompiledToggleFocus(layout, focused.index, if (group_direction == .previous) 4 else 5);
|
|
1808
|
+
if (policy != null) return canvasWidgetCompiledGroupFocus(layout, focused, if (group_direction == .previous) 0 else 1, policy.?) orelse focused;
|
|
1606
1809
|
return canvasWidgetAdjacentGroupFocusTarget(layout, parent_index, focused, group_direction) orelse focused;
|
|
1607
1810
|
}
|
|
1608
1811
|
|
|
@@ -1639,10 +1842,216 @@ pub fn canvasWidgetGroupDirectionForFocus(parent_kind: canvas.WidgetKind, child_
|
|
|
1639
1842
|
// logical targets intentionally omit only scroll clipping so keyboard
|
|
1640
1843
|
// focus can reveal an offscreen radio before committing to it.
|
|
1641
1844
|
|
|
1845
|
+
/// Retained geometry is native; selection scope and traversal are portable.
|
|
1846
|
+
/// Wire v1 uses preorder indices rather than ids (ids can exceed JS integers).
|
|
1847
|
+
pub fn canvasWidgetRadioPolicy(layout: canvas.WidgetLayoutTree, subject: usize, operation: u8, output: []u8) ?usize {
|
|
1848
|
+
if (subject >= layout.nodes.len) return null;
|
|
1849
|
+
const policy = layout.nodes[subject].widget.interaction_policy orelse return null;
|
|
1850
|
+
if (layout.nodes.len > canvas_limits.max_canvas_widget_nodes_per_view) @panic("radio policy tree exceeds native view budget");
|
|
1851
|
+
var request: [5 + canvas_limits.max_canvas_widget_nodes_per_view * 4]u8 = undefined;
|
|
1852
|
+
request[0] = operation;
|
|
1853
|
+
std.mem.writeInt(u16, request[1..3], @intCast(subject), .little);
|
|
1854
|
+
std.mem.writeInt(u16, request[3..5], @intCast(layout.nodes.len), .little);
|
|
1855
|
+
for (layout.nodes, 0..) |node, index| {
|
|
1856
|
+
const at = 5 + index * 4;
|
|
1857
|
+
std.mem.writeInt(u16, request[at..][0..2], if (node.parent_index) |parent| @intCast(parent) else 65535, .little);
|
|
1858
|
+
request[at + 2] = switch (node.widget.kind) {
|
|
1859
|
+
.radio => 1,
|
|
1860
|
+
.radio_group => 2,
|
|
1861
|
+
else => 0,
|
|
1862
|
+
};
|
|
1863
|
+
request[at + 3] = @as(u8, if (operation != 0 and operation != 8 and node.widget.kind == .radio and layout.logicalFocusTargetAtIndex(index) != null) 1 else 0) |
|
|
1864
|
+
@as(u8, if ((operation == 2 or operation == 3) and node.widget.kind == .radio and layout.focusTargetById(node.widget.id) != null) 2 else 0) |
|
|
1865
|
+
@as(u8, if (canvasWidgetSelectableSelected(node.widget)) 4 else 0);
|
|
1866
|
+
}
|
|
1867
|
+
return policy(request[0 .. 5 + layout.nodes.len * 4], output);
|
|
1868
|
+
}
|
|
1869
|
+
|
|
1870
|
+
pub fn canvasWidgetTabsPolicy(layout: canvas.WidgetLayoutTree, subject: usize, operation: u8, output: []u8) ?usize {
|
|
1871
|
+
if (subject >= layout.nodes.len) return null;
|
|
1872
|
+
const policy = layout.nodes[subject].widget.interaction_policy orelse return null;
|
|
1873
|
+
if (layout.nodes.len > canvas_limits.max_canvas_widget_nodes_per_view) @panic("tabs policy tree exceeds native view budget");
|
|
1874
|
+
var request: [5 + canvas_limits.max_canvas_widget_nodes_per_view * 4]u8 = undefined;
|
|
1875
|
+
request[0] = operation;
|
|
1876
|
+
std.mem.writeInt(u16, request[1..3], @intCast(subject), .little);
|
|
1877
|
+
std.mem.writeInt(u16, request[3..5], @intCast(layout.nodes.len), .little);
|
|
1878
|
+
for (layout.nodes, 0..) |node, index| {
|
|
1879
|
+
const at = 5 + index * 4;
|
|
1880
|
+
std.mem.writeInt(u16, request[at..][0..2], if (node.parent_index) |parent| @intCast(parent) else 65535, .little);
|
|
1881
|
+
request[at + 2] = switch (node.widget.kind) {
|
|
1882
|
+
.segmented_control => 1,
|
|
1883
|
+
.tabs => 2,
|
|
1884
|
+
else => 0,
|
|
1885
|
+
};
|
|
1886
|
+
request[at + 3] = @as(u8, if (operation != 0 and operation != 8 and node.widget.kind == .segmented_control and layout.focusTargetById(node.widget.id) != null) 2 else 0) |
|
|
1887
|
+
@as(u8, if (canvasWidgetSelectableSelected(node.widget)) 4 else 0);
|
|
1888
|
+
}
|
|
1889
|
+
return policy(request[0 .. 5 + layout.nodes.len * 4], output);
|
|
1890
|
+
}
|
|
1891
|
+
|
|
1892
|
+
fn compiledTabsFocus(layout: canvas.WidgetLayoutTree, subject: usize, operation: u8) ?canvas.WidgetFocusTarget {
|
|
1893
|
+
var output: [2]u8 = undefined;
|
|
1894
|
+
const len = canvasWidgetTabsPolicy(layout, subject, operation, &output) orelse return null;
|
|
1895
|
+
if (len != 2) @panic("invalid tabs policy target");
|
|
1896
|
+
const index = std.mem.readInt(u16, &output, .little);
|
|
1897
|
+
if (index == 65535) return null;
|
|
1898
|
+
if (index >= layout.nodes.len) @panic("tabs policy target outside tree");
|
|
1899
|
+
return layout.focusTargetById(layout.nodes[index].widget.id);
|
|
1900
|
+
}
|
|
1901
|
+
|
|
1902
|
+
/// Direct-sibling list policy receives both logical and visible eligibility:
|
|
1903
|
+
/// arrows admit scroll-clipped rows; Home/End preserves visible-only edges.
|
|
1904
|
+
pub fn canvasWidgetListPolicy(layout: canvas.WidgetLayoutTree, subject: usize, operation: u8, output: []u8) ?usize {
|
|
1905
|
+
if (subject >= layout.nodes.len) return null;
|
|
1906
|
+
const policy = layout.nodes[subject].widget.interaction_policy orelse return null;
|
|
1907
|
+
if (layout.nodes.len > canvas_limits.max_canvas_widget_nodes_per_view) @panic("list policy tree exceeds native view budget");
|
|
1908
|
+
var request: [5 + canvas_limits.max_canvas_widget_nodes_per_view * 4]u8 = undefined;
|
|
1909
|
+
request[0] = operation;
|
|
1910
|
+
std.mem.writeInt(u16, request[1..3], @intCast(subject), .little);
|
|
1911
|
+
std.mem.writeInt(u16, request[3..5], @intCast(layout.nodes.len), .little);
|
|
1912
|
+
for (layout.nodes, 0..) |node, index| {
|
|
1913
|
+
const at = 5 + index * 4;
|
|
1914
|
+
std.mem.writeInt(u16, request[at..][0..2], if (node.parent_index) |parent| @intCast(parent) else 65535, .little);
|
|
1915
|
+
request[at + 2] = switch (node.widget.kind) {
|
|
1916
|
+
.list_item => 1,
|
|
1917
|
+
.list => 2,
|
|
1918
|
+
else => 0,
|
|
1919
|
+
};
|
|
1920
|
+
request[at + 3] = @as(u8, if ((operation == 4 or operation == 5) and node.widget.kind == .list_item and layout.logicalFocusTargetAtIndex(index) != null) 1 else 0) |
|
|
1921
|
+
@as(u8, if ((operation == 6 or operation == 7) and node.widget.kind == .list_item and layout.focusTargetById(node.widget.id) != null) 2 else 0) |
|
|
1922
|
+
@as(u8, if (canvasWidgetSelectableSelected(node.widget)) 4 else 0);
|
|
1923
|
+
}
|
|
1924
|
+
return policy(request[0 .. 5 + layout.nodes.len * 4], output);
|
|
1925
|
+
}
|
|
1926
|
+
|
|
1927
|
+
fn compiledListFocus(layout: canvas.WidgetLayoutTree, subject: usize, operation: u8) ?canvas.WidgetFocusTarget {
|
|
1928
|
+
var output: [2]u8 = undefined;
|
|
1929
|
+
const len = canvasWidgetListPolicy(layout, subject, operation, &output) orelse return null;
|
|
1930
|
+
if (len != 2) @panic("invalid list policy target");
|
|
1931
|
+
const index = std.mem.readInt(u16, &output, .little);
|
|
1932
|
+
if (index == 65535) return null;
|
|
1933
|
+
if (index >= layout.nodes.len) @panic("list policy target outside tree");
|
|
1934
|
+
return if (operation == 4 or operation == 5) layout.logicalFocusTargetAtIndex(index) else layout.focusTargetById(layout.nodes[index].widget.id);
|
|
1935
|
+
}
|
|
1936
|
+
|
|
1937
|
+
/// Geometry and eligibility remain native. The compiled menu policy chooses
|
|
1938
|
+
/// entry, traversal and committed-choice selection from the retained tree.
|
|
1939
|
+
pub fn canvasWidgetMenuPolicy(layout: canvas.WidgetLayoutTree, subject: usize, operation: u8, output: []u8) ?usize {
|
|
1940
|
+
if (subject >= layout.nodes.len) return null;
|
|
1941
|
+
const policy = layout.nodes[subject].widget.interaction_policy orelse return null;
|
|
1942
|
+
if (layout.nodes.len > canvas_limits.max_canvas_widget_nodes_per_view) @panic("menu policy tree exceeds native view budget");
|
|
1943
|
+
var request: [5 + canvas_limits.max_canvas_widget_nodes_per_view * 4]u8 = undefined;
|
|
1944
|
+
request[0] = operation;
|
|
1945
|
+
std.mem.writeInt(u16, request[1..3], @intCast(subject), .little);
|
|
1946
|
+
std.mem.writeInt(u16, request[3..5], @intCast(layout.nodes.len), .little);
|
|
1947
|
+
for (layout.nodes, 0..) |node, index| {
|
|
1948
|
+
const at = 5 + index * 4;
|
|
1949
|
+
std.mem.writeInt(u16, request[at..][0..2], if (node.parent_index) |parent| @intCast(parent) else 65535, .little);
|
|
1950
|
+
const item = node.widget.kind == .menu_item or node.widget.kind == .list_item;
|
|
1951
|
+
request[at + 2] = switch (node.widget.kind) {
|
|
1952
|
+
.menu_item => 1,
|
|
1953
|
+
.menu_surface, .dropdown_menu => 2,
|
|
1954
|
+
.list_item => 3,
|
|
1955
|
+
else => 0,
|
|
1956
|
+
};
|
|
1957
|
+
request[at + 3] = @as(u8, if (operation != 8 and item and layout.focusTargetById(node.widget.id) != null) 2 else 0) |
|
|
1958
|
+
@as(u8, if (canvasWidgetSelectableSelected(node.widget)) 4 else 0) |
|
|
1959
|
+
@as(u8, if (node.widget.state.selected) 8 else 0);
|
|
1960
|
+
}
|
|
1961
|
+
return policy(request[0 .. 5 + layout.nodes.len * 4], output);
|
|
1962
|
+
}
|
|
1963
|
+
|
|
1964
|
+
/// Toggle transitions and source/retained reconciliation run without a tree
|
|
1965
|
+
/// scan. The native caller applies the returned selected state and value.
|
|
1966
|
+
pub fn canvasWidgetCompiledToggleSelected(widget: canvas.Widget, operation: u8, previously_selected: bool, retained_selected: bool) ?bool {
|
|
1967
|
+
if (widget.kind != .toggle_button and widget.kind != .checkbox and widget.kind != .switch_control and widget.kind != .toggle) return null;
|
|
1968
|
+
const policy = widget.interaction_policy orelse return null;
|
|
1969
|
+
const request = [_]u8{
|
|
1970
|
+
operation,
|
|
1971
|
+
@as(u8, if (canvasWidgetBooleanSelected(widget)) 1 else 0) |
|
|
1972
|
+
@as(u8, if (previously_selected) 2 else 0) |
|
|
1973
|
+
@as(u8, if (retained_selected) 4 else 0),
|
|
1974
|
+
};
|
|
1975
|
+
var output: [1]u8 = undefined;
|
|
1976
|
+
const len = policy(&request, &output);
|
|
1977
|
+
if (len != 1 or output[0] > 1) @panic("invalid toggle state policy result");
|
|
1978
|
+
return output[0] == 1;
|
|
1979
|
+
}
|
|
1980
|
+
|
|
1981
|
+
pub fn canvasWidgetCompiledAccordionSelected(widget: canvas.Widget, operation: u8, previous_source: ?bool, retained_selected: bool) ?bool {
|
|
1982
|
+
if (widget.kind != .accordion) return null;
|
|
1983
|
+
const policy = widget.interaction_policy orelse return null;
|
|
1984
|
+
const request = [_]u8{
|
|
1985
|
+
operation,
|
|
1986
|
+
@as(u8, if (canvasWidgetBooleanSelected(widget)) 1 else 0) |
|
|
1987
|
+
@as(u8, if (previous_source orelse false) 2 else 0) |
|
|
1988
|
+
@as(u8, if (retained_selected) 4 else 0) |
|
|
1989
|
+
@as(u8, if (previous_source != null) 8 else 0),
|
|
1990
|
+
};
|
|
1991
|
+
var output: [1]u8 = undefined;
|
|
1992
|
+
const len = policy(&request, &output);
|
|
1993
|
+
if (len != 1 or output[0] > 1) @panic("invalid accordion state policy result");
|
|
1994
|
+
return output[0] == 1;
|
|
1995
|
+
}
|
|
1996
|
+
|
|
1997
|
+
pub fn canvasWidgetCompiledToggleFocus(layout: canvas.WidgetLayoutTree, subject: usize, operation: u8) ?canvas.WidgetFocusTarget {
|
|
1998
|
+
if (subject >= layout.nodes.len) return null;
|
|
1999
|
+
const policy = layout.nodes[subject].widget.interaction_policy orelse return null;
|
|
2000
|
+
if (layout.nodes.len > canvas_limits.max_canvas_widget_nodes_per_view) @panic("toggle policy tree exceeds native view budget");
|
|
2001
|
+
var request: [5 + canvas_limits.max_canvas_widget_nodes_per_view * 4]u8 = undefined;
|
|
2002
|
+
request[0] = operation;
|
|
2003
|
+
std.mem.writeInt(u16, request[1..3], @intCast(subject), .little);
|
|
2004
|
+
std.mem.writeInt(u16, request[3..5], @intCast(layout.nodes.len), .little);
|
|
2005
|
+
for (layout.nodes, 0..) |node, index| {
|
|
2006
|
+
const at = 5 + index * 4;
|
|
2007
|
+
std.mem.writeInt(u16, request[at..][0..2], if (node.parent_index) |parent| @intCast(parent) else 65535, .little);
|
|
2008
|
+
request[at + 2] = switch (node.widget.kind) {
|
|
2009
|
+
.toggle_button => 1,
|
|
2010
|
+
.toggle_group => 2,
|
|
2011
|
+
.button_group => 3,
|
|
2012
|
+
else => 0,
|
|
2013
|
+
};
|
|
2014
|
+
request[at + 3] = if (node.widget.kind == .toggle_button and layout.focusTargetById(node.widget.id) != null) 2 else 0;
|
|
2015
|
+
}
|
|
2016
|
+
var output: [2]u8 = undefined;
|
|
2017
|
+
const len = policy(request[0 .. 5 + layout.nodes.len * 4], &output);
|
|
2018
|
+
if (len != 2) @panic("invalid toggle focus policy result");
|
|
2019
|
+
const index = std.mem.readInt(u16, &output, .little);
|
|
2020
|
+
if (index == 65535) return null;
|
|
2021
|
+
if (index >= layout.nodes.len) @panic("toggle policy target outside tree");
|
|
2022
|
+
return layout.focusTargetById(layout.nodes[index].widget.id);
|
|
2023
|
+
}
|
|
2024
|
+
|
|
2025
|
+
pub fn canvasWidgetCompiledMenuFocus(layout: canvas.WidgetLayoutTree, subject: usize, operation: u8) ?canvas.WidgetFocusTarget {
|
|
2026
|
+
var output: [2]u8 = undefined;
|
|
2027
|
+
const len = canvasWidgetMenuPolicy(layout, subject, operation, &output) orelse return null;
|
|
2028
|
+
if (len != 2) @panic("invalid menu policy target");
|
|
2029
|
+
const index = std.mem.readInt(u16, &output, .little);
|
|
2030
|
+
if (index == 65535) return null;
|
|
2031
|
+
if (index >= layout.nodes.len) @panic("menu policy target outside tree");
|
|
2032
|
+
return layout.focusTargetById(layout.nodes[index].widget.id);
|
|
2033
|
+
}
|
|
2034
|
+
|
|
2035
|
+
fn compiledRadioIndex(layout: canvas.WidgetLayoutTree, subject: usize, operation: u8) ?usize {
|
|
2036
|
+
var output: [2]u8 = undefined;
|
|
2037
|
+
const len = canvasWidgetRadioPolicy(layout, subject, operation, &output) orelse return null;
|
|
2038
|
+
if (len != 2) @panic("invalid radio policy target");
|
|
2039
|
+
const index = std.mem.readInt(u16, &output, .little);
|
|
2040
|
+
if (index == 65535) return null;
|
|
2041
|
+
if (index >= layout.nodes.len) @panic("radio policy target outside tree");
|
|
2042
|
+
return index;
|
|
2043
|
+
}
|
|
2044
|
+
|
|
2045
|
+
fn compiledRadioFocus(layout: canvas.WidgetLayoutTree, subject: usize, operation: u8) ?canvas.WidgetFocusTarget {
|
|
2046
|
+
const index = compiledRadioIndex(layout, subject, operation) orelse return null;
|
|
2047
|
+
return if (operation == 2 or operation == 3) layout.focusTargetById(layout.nodes[index].widget.id) else layout.logicalFocusTargetAtIndex(index);
|
|
2048
|
+
}
|
|
2049
|
+
|
|
1642
2050
|
/// Index of the nearest `.radio_group` ancestor, or null for a bare
|
|
1643
2051
|
/// radio (and for any other node outside a radio group).
|
|
1644
2052
|
pub fn canvasWidgetRadioGroupScopeIndex(layout: canvas.WidgetLayoutTree, node_index: usize) ?usize {
|
|
1645
2053
|
if (node_index >= layout.nodes.len) return null;
|
|
2054
|
+
if ((layout.nodes[node_index].widget.kind == .radio or layout.nodes[node_index].widget.kind == .radio_group) and layout.nodes[node_index].widget.interaction_policy != null) return compiledRadioIndex(layout, node_index, 0);
|
|
1646
2055
|
var current = layout.nodes[node_index].parent_index;
|
|
1647
2056
|
while (current) |index| {
|
|
1648
2057
|
if (index >= layout.nodes.len) return null;
|
|
@@ -1679,6 +2088,7 @@ fn canvasWidgetRadioGroupFocusTarget(
|
|
|
1679
2088
|
/// focusable radio. Selection may be represented by state or value.
|
|
1680
2089
|
pub fn canvasWidgetRovingTabEntryTarget(layout: canvas.WidgetLayoutTree, scope: CanvasWidgetRovingTabScope) ?canvas.WidgetFocusTarget {
|
|
1681
2090
|
if (scope.index >= layout.nodes.len or layout.nodes[scope.index].widget.kind != .radio_group) return null;
|
|
2091
|
+
if (layout.nodes[scope.index].widget.interaction_policy != null) return compiledRadioFocus(layout, scope.index, 1);
|
|
1682
2092
|
const scope_depth = layout.nodes[scope.index].depth;
|
|
1683
2093
|
var first: ?canvas.WidgetFocusTarget = null;
|
|
1684
2094
|
var index = scope.index + 1;
|
|
@@ -1697,6 +2107,7 @@ pub fn canvasWidgetRovingTabEntryTarget(layout: canvas.WidgetLayoutTree, scope:
|
|
|
1697
2107
|
/// composite's position around those intervening Tab stops.
|
|
1698
2108
|
pub fn canvasWidgetRovingTabStopTarget(layout: canvas.WidgetLayoutTree, scope: CanvasWidgetRovingTabScope) ?canvas.WidgetFocusTarget {
|
|
1699
2109
|
if (scope.index >= layout.nodes.len or layout.nodes[scope.index].widget.kind != .radio_group) return null;
|
|
2110
|
+
if (layout.nodes[scope.index].widget.interaction_policy != null) return compiledRadioFocus(layout, scope.index, 2);
|
|
1700
2111
|
const scope_depth = layout.nodes[scope.index].depth;
|
|
1701
2112
|
var index = scope.index + 1;
|
|
1702
2113
|
while (index < layout.nodes.len and layout.nodes[index].depth > scope_depth) : (index += 1) {
|
|
@@ -1715,6 +2126,7 @@ pub fn canvasWidgetRovingTabStopTarget(layout: canvas.WidgetLayoutTree, scope: C
|
|
|
1715
2126
|
/// an invisible focus id.
|
|
1716
2127
|
pub fn canvasWidgetRovingTabVisibleEntryTarget(layout: canvas.WidgetLayoutTree, scope: CanvasWidgetRovingTabScope) ?canvas.WidgetFocusTarget {
|
|
1717
2128
|
if (scope.index >= layout.nodes.len or layout.nodes[scope.index].widget.kind != .radio_group) return null;
|
|
2129
|
+
if (layout.nodes[scope.index].widget.interaction_policy != null) return compiledRadioFocus(layout, scope.index, 3);
|
|
1718
2130
|
const scope_depth = layout.nodes[scope.index].depth;
|
|
1719
2131
|
var first: ?canvas.WidgetFocusTarget = null;
|
|
1720
2132
|
var index = scope.index + 1;
|
|
@@ -1734,8 +2146,9 @@ pub fn canvasWidgetRadioGroupDirectionalFocusTarget(
|
|
|
1734
2146
|
direction: canvas.WidgetFocusDirection,
|
|
1735
2147
|
) ?canvas.WidgetFocusTarget {
|
|
1736
2148
|
if (focused.kind != .radio or focused.index >= layout.nodes.len) return null;
|
|
1737
|
-
const scope_index = canvasWidgetRadioGroupScopeIndex(layout, focused.index) orelse return null;
|
|
1738
2149
|
const group_direction = canvasWidgetAnyAxisGroupDirection(direction) orelse return null;
|
|
2150
|
+
if (layout.nodes[focused.index].widget.interaction_policy != null) return compiledRadioFocus(layout, focused.index, if (group_direction == .previous) 4 else 5);
|
|
2151
|
+
const scope_index = canvasWidgetRadioGroupScopeIndex(layout, focused.index) orelse return null;
|
|
1739
2152
|
return canvasWidgetRadioGroupAdjacentRadio(layout, scope_index, focused.index, group_direction) orelse focused;
|
|
1740
2153
|
}
|
|
1741
2154
|
|
|
@@ -1745,6 +2158,7 @@ pub fn canvasWidgetRadioGroupFocusEdgeTarget(
|
|
|
1745
2158
|
edge: CanvasWidgetGroupFocusEdge,
|
|
1746
2159
|
) ?canvas.WidgetFocusTarget {
|
|
1747
2160
|
if (focused.kind != .radio or focused.index >= layout.nodes.len) return null;
|
|
2161
|
+
if (layout.nodes[focused.index].widget.interaction_policy != null) return compiledRadioFocus(layout, focused.index, if (edge == .first) 6 else 7);
|
|
1748
2162
|
const scope_index = canvasWidgetRadioGroupScopeIndex(layout, focused.index) orelse return null;
|
|
1749
2163
|
if (scope_index >= layout.nodes.len) return null;
|
|
1750
2164
|
const scope_depth = layout.nodes[scope_index].depth;
|
|
@@ -1853,6 +2267,9 @@ pub fn canvasWidgetAdjacentGroupFocusTarget(
|
|
|
1853
2267
|
/// the node sits outside any tree.
|
|
1854
2268
|
pub fn canvasWidgetTreeScopeIndex(layout: canvas.WidgetLayoutTree, node_index: usize) ?usize {
|
|
1855
2269
|
if (node_index >= layout.nodes.len) return null;
|
|
2270
|
+
const widget = layout.nodes[node_index].widget;
|
|
2271
|
+
if ((widget.kind == .tree or widget.semantics.role == .tree or widget.semantics.role == .treeitem) and widget.interaction_policy != null)
|
|
2272
|
+
return compiledTreeIndex(layout, node_index, 0);
|
|
1856
2273
|
var current = layout.nodes[node_index].parent_index;
|
|
1857
2274
|
while (current) |index| {
|
|
1858
2275
|
if (index >= layout.nodes.len) return null;
|
|
@@ -1867,6 +2284,46 @@ pub fn canvasWidgetTreeScopeIndex(layout: canvas.WidgetLayoutTree, node_index: u
|
|
|
1867
2284
|
return null;
|
|
1868
2285
|
}
|
|
1869
2286
|
|
|
2287
|
+
/// Geometry stays native; the compiled policy receives retained topology,
|
|
2288
|
+
/// logical focus eligibility, selection, expansion, and flat row levels.
|
|
2289
|
+
pub fn canvasWidgetTreePolicy(layout: canvas.WidgetLayoutTree, subject: usize, operation: u8, output: []u8) ?usize {
|
|
2290
|
+
if (subject >= layout.nodes.len) return null;
|
|
2291
|
+
const widget = layout.nodes[subject].widget;
|
|
2292
|
+
if (widget.kind != .tree and widget.semantics.role != .tree and widget.semantics.role != .treeitem) return null;
|
|
2293
|
+
const policy = widget.interaction_policy orelse return null;
|
|
2294
|
+
if (layout.nodes.len > canvas_limits.max_canvas_widget_nodes_per_view) @panic("tree policy exceeds native view budget");
|
|
2295
|
+
var request: [5 + canvas_limits.max_canvas_widget_nodes_per_view * 6]u8 = undefined;
|
|
2296
|
+
request[0] = operation;
|
|
2297
|
+
std.mem.writeInt(u16, request[1..3], @intCast(subject), .little);
|
|
2298
|
+
std.mem.writeInt(u16, request[3..5], @intCast(layout.nodes.len), .little);
|
|
2299
|
+
for (layout.nodes, 0..) |node, index| {
|
|
2300
|
+
const at = 5 + index * 6;
|
|
2301
|
+
std.mem.writeInt(u16, request[at..][0..2], if (node.parent_index) |parent| @intCast(parent) else 65535, .little);
|
|
2302
|
+
request[at + 2] = @as(u8, if (node.widget.semantics.role == .treeitem) 1 else 0) |
|
|
2303
|
+
@as(u8, if (node.widget.kind == .tree or node.widget.semantics.role == .tree) 2 else 0);
|
|
2304
|
+
request[at + 3] = @as(u8, if (operation != 0 and operation != 8 and node.widget.semantics.role == .treeitem and layout.logicalFocusTargetAtIndex(index) != null) 1 else 0) |
|
|
2305
|
+
@as(u8, if (canvasWidgetSelectableSelected(node.widget)) 4 else 0) |
|
|
2306
|
+
@as(u8, if (node.widget.state.expanded orelse false) 8 else 0);
|
|
2307
|
+
std.mem.writeInt(u16, request[at + 4 ..][0..2], node.widget.tree_level, .little);
|
|
2308
|
+
}
|
|
2309
|
+
return policy(request[0 .. 5 + layout.nodes.len * 6], output);
|
|
2310
|
+
}
|
|
2311
|
+
|
|
2312
|
+
fn compiledTreeIndex(layout: canvas.WidgetLayoutTree, subject: usize, operation: u8) ?usize {
|
|
2313
|
+
var output: [2]u8 = undefined;
|
|
2314
|
+
const len = canvasWidgetTreePolicy(layout, subject, operation, &output) orelse return null;
|
|
2315
|
+
if (len != 2) @panic("invalid tree policy target");
|
|
2316
|
+
const index = std.mem.readInt(u16, &output, .little);
|
|
2317
|
+
if (index == 65535) return null;
|
|
2318
|
+
if (index >= layout.nodes.len) @panic("tree policy target outside tree");
|
|
2319
|
+
return index;
|
|
2320
|
+
}
|
|
2321
|
+
|
|
2322
|
+
fn compiledTreeFocus(layout: canvas.WidgetLayoutTree, subject: usize, operation: u8) ?canvas.WidgetFocusTarget {
|
|
2323
|
+
const index = compiledTreeIndex(layout, subject, operation) orelse return null;
|
|
2324
|
+
return layout.logicalFocusTargetAtIndex(index);
|
|
2325
|
+
}
|
|
2326
|
+
|
|
1870
2327
|
fn canvasWidgetTreeRowFocusTarget(layout: canvas.WidgetLayoutTree, node_index: usize) ?canvas.WidgetFocusTarget {
|
|
1871
2328
|
if (layout.nodes[node_index].widget.semantics.role != .treeitem) return null;
|
|
1872
2329
|
return canvasWidgetLogicalFocusTarget(layout, node_index);
|
|
@@ -1899,6 +2356,16 @@ pub fn canvasWidgetTreeDirectionalFocusTarget(
|
|
|
1899
2356
|
if (focused.index >= layout.nodes.len) return null;
|
|
1900
2357
|
if (layout.nodes[focused.index].widget.semantics.role != .treeitem) return null;
|
|
1901
2358
|
const tree_index = canvasWidgetTreeScopeIndex(layout, focused.index) orelse return null;
|
|
2359
|
+
if (layout.nodes[focused.index].widget.interaction_policy != null) {
|
|
2360
|
+
const operation: u8 = switch (direction) {
|
|
2361
|
+
.up => 4,
|
|
2362
|
+
.down => 5,
|
|
2363
|
+
.left => 9,
|
|
2364
|
+
.right => 10,
|
|
2365
|
+
.forward, .backward => return null,
|
|
2366
|
+
};
|
|
2367
|
+
return compiledTreeFocus(layout, focused.index, operation);
|
|
2368
|
+
}
|
|
1902
2369
|
return switch (direction) {
|
|
1903
2370
|
.up => canvasWidgetTreeAdjacentRow(layout, tree_index, focused.index, .previous) orelse focused,
|
|
1904
2371
|
.down => canvasWidgetTreeAdjacentRow(layout, tree_index, focused.index, .next) orelse focused,
|
|
@@ -1925,6 +2392,8 @@ pub fn canvasWidgetTreeFocusEdgeTarget(
|
|
|
1925
2392
|
if (focused.index >= layout.nodes.len) return null;
|
|
1926
2393
|
if (layout.nodes[focused.index].widget.semantics.role != .treeitem) return null;
|
|
1927
2394
|
const tree_index = canvasWidgetTreeScopeIndex(layout, focused.index) orelse return null;
|
|
2395
|
+
if (layout.nodes[focused.index].widget.interaction_policy != null)
|
|
2396
|
+
return compiledTreeFocus(layout, focused.index, if (edge == .first) 6 else 7);
|
|
1928
2397
|
switch (edge) {
|
|
1929
2398
|
.first => {
|
|
1930
2399
|
var index = tree_index + 1;
|
|
@@ -2015,10 +2484,23 @@ fn canvasWidgetTreeFirstChildRow(layout: canvas.WidgetLayoutTree, tree_index: us
|
|
|
2015
2484
|
}
|
|
2016
2485
|
|
|
2017
2486
|
pub fn canvasWidgetGroupFocusEdgeTarget(layout: canvas.WidgetLayoutTree, focused: canvas.WidgetFocusTarget, edge: CanvasWidgetGroupFocusEdge) ?canvas.WidgetFocusTarget {
|
|
2487
|
+
return canvasWidgetGroupFocusEdgeTargetWithPolicy(layout, focused, edge, null);
|
|
2488
|
+
}
|
|
2489
|
+
|
|
2490
|
+
pub fn canvasWidgetGroupFocusEdgeTargetWithPolicy(layout: canvas.WidgetLayoutTree, focused: canvas.WidgetFocusTarget, edge: CanvasWidgetGroupFocusEdge, policy: keyboard_focus.Policy) ?canvas.WidgetFocusTarget {
|
|
2018
2491
|
if (canvasWidgetRadioGroupFocusEdgeTarget(layout, focused, edge)) |target| return target;
|
|
2019
|
-
if (
|
|
2492
|
+
if (keyboard_focus.decide(policy, .{ .stage = .edge, .kind = focused.kind, .parent = canvasWidgetFocusParentKind(layout, focused) }) == 0) return null;
|
|
2020
2493
|
if (focused.index >= layout.nodes.len) return null;
|
|
2021
2494
|
const parent_index = layout.nodes[focused.index].parent_index;
|
|
2495
|
+
if (focused.kind == .segmented_control and layout.nodes[focused.index].widget.interaction_policy != null)
|
|
2496
|
+
return compiledTabsFocus(layout, focused.index, if (edge == .first) 6 else 7);
|
|
2497
|
+
if (focused.kind == .list_item and layout.nodes[focused.index].widget.interaction_policy != null)
|
|
2498
|
+
return compiledListFocus(layout, focused.index, if (edge == .first) 6 else 7);
|
|
2499
|
+
if (focused.kind == .menu_item and layout.nodes[focused.index].widget.interaction_policy != null)
|
|
2500
|
+
return canvasWidgetCompiledMenuFocus(layout, focused.index, if (edge == .first) 6 else 7);
|
|
2501
|
+
if (focused.kind == .toggle_button and layout.nodes[focused.index].widget.interaction_policy != null)
|
|
2502
|
+
return canvasWidgetCompiledToggleFocus(layout, focused.index, if (edge == .first) 6 else 7);
|
|
2503
|
+
if (policy != null) return canvasWidgetCompiledGroupFocus(layout, focused, if (edge == .first) 2 else 3, policy.?);
|
|
2022
2504
|
switch (edge) {
|
|
2023
2505
|
.first => {
|
|
2024
2506
|
for (layout.nodes) |node| {
|
|
@@ -2038,3 +2520,91 @@ pub fn canvasWidgetGroupFocusEdgeTarget(layout: canvas.WidgetLayoutTree, focused
|
|
|
2038
2520
|
}
|
|
2039
2521
|
return null;
|
|
2040
2522
|
}
|
|
2523
|
+
|
|
2524
|
+
/// Exact identities remain native. Only bounded indices and native focus
|
|
2525
|
+
/// capability outcomes cross the copied-byte group traversal boundary.
|
|
2526
|
+
fn canvasWidgetCompiledGroupFocus(layout: canvas.WidgetLayoutTree, focused: canvas.WidgetFocusTarget, operation: u8, policy: *const fn ([]const u8, []u8) usize) ?canvas.WidgetFocusTarget {
|
|
2527
|
+
if (focused.index >= layout.nodes.len) return null;
|
|
2528
|
+
if (layout.nodes.len > canvas_limits.max_canvas_widget_nodes_per_view) @panic("keyboard group exceeds native view budget");
|
|
2529
|
+
const parent = layout.nodes[focused.index].parent_index;
|
|
2530
|
+
const parent_kind = canvasWidgetFocusParentKind(layout, focused);
|
|
2531
|
+
var request: [9 + canvas_limits.max_canvas_widget_nodes_per_view * 4]u8 = undefined;
|
|
2532
|
+
request[0..5].* = .{ 34, 10, operation, @intCast(canvas.widgetKindCode(focused.kind)), if (parent_kind) |kind| @intCast(canvas.widgetKindCode(kind)) else 63 };
|
|
2533
|
+
std.mem.writeInt(u16, request[5..7], if (parent) |index| @intCast(index) else 65535, .little);
|
|
2534
|
+
std.mem.writeInt(u16, request[7..9], @intCast(layout.nodes.len), .little);
|
|
2535
|
+
for (layout.nodes, 0..) |node, index| {
|
|
2536
|
+
const record = request[9 + index * 4 ..][0..4];
|
|
2537
|
+
std.mem.writeInt(u16, record[0..2], if (node.parent_index) |parent_index| @intCast(parent_index) else 65535, .little);
|
|
2538
|
+
record[2] = @intCast(canvas.widgetKindCode(node.widget.kind));
|
|
2539
|
+
record[3] = @as(u8, if (layout.focusTargetById(node.widget.id) != null) 1 else 0) |
|
|
2540
|
+
@as(u8, if (node.widget.id == focused.id) 2 else 0) | @as(u8, if (canvasWidgetLogicalFocusTarget(layout, index) != null) 4 else 0);
|
|
2541
|
+
}
|
|
2542
|
+
var response: [2]u8 = undefined;
|
|
2543
|
+
if (policy(request[0 .. 9 + layout.nodes.len * 4], &response) != response.len) @panic("invalid compiled keyboard group result");
|
|
2544
|
+
const index = std.mem.readInt(u16, &response, .little);
|
|
2545
|
+
if (index == 65535) return null;
|
|
2546
|
+
if (index >= layout.nodes.len) @panic("compiled keyboard group index out of bounds");
|
|
2547
|
+
return if (operation < 2 and focused.kind == .list_item and parent_kind == .list)
|
|
2548
|
+
canvasWidgetLogicalFocusTarget(layout, index)
|
|
2549
|
+
else
|
|
2550
|
+
layout.focusTargetById(layout.nodes[index].widget.id);
|
|
2551
|
+
}
|
|
2552
|
+
|
|
2553
|
+
/// Compiled plans select complete native records, without lending their storage
|
|
2554
|
+
/// to the policy. Absent policies use the independent reference collectors.
|
|
2555
|
+
pub fn collectCanvasWidgetScrollOffsetEntriesWithPolicy(policy: retention.Policy, nodes: []const canvas.WidgetLayoutNode, output: []CanvasWidgetSourceScrollEntry) []const CanvasWidgetSourceScrollEntry {
|
|
2556
|
+
const plan = retention.collect(policy, .source_scroll, nodes, @as([]const CanvasWidgetSourceTextEntry, &.{}), output.len, 0) orelse return collectCanvasWidgetScrollOffsetEntries(nodes, output);
|
|
2557
|
+
for (plan.entries[0..plan.count], 0..) |entry, i| {
|
|
2558
|
+
const widget = nodes[entry.node].widget;
|
|
2559
|
+
output[i] = .{ .id = widget.id, .value = widget.value, .value_x = widget.value_x };
|
|
2560
|
+
}
|
|
2561
|
+
return output[0..plan.count];
|
|
2562
|
+
}
|
|
2563
|
+
pub fn collectCanvasWidgetSourceControlEntriesWithPolicy(policy: retention.Policy, nodes: []const canvas.WidgetLayoutNode, output: []CanvasWidgetSourceControlEntry) []const CanvasWidgetSourceControlEntry {
|
|
2564
|
+
const plan = retention.collect(policy, .source_control, nodes, @as([]const CanvasWidgetSourceTextEntry, &.{}), output.len, 0) orelse return collectCanvasWidgetSourceControlEntries(nodes, output);
|
|
2565
|
+
for (plan.entries[0..plan.count], 0..) |entry, i| {
|
|
2566
|
+
const widget = nodes[entry.node].widget;
|
|
2567
|
+
output[i] = .{ .id = widget.id, .kind = widget.kind, .selected = entry.selected, .value = widget.value };
|
|
2568
|
+
}
|
|
2569
|
+
return output[0..plan.count];
|
|
2570
|
+
}
|
|
2571
|
+
pub fn collectCanvasWidgetControlReconcileEntriesWithPolicy(policy: retention.Policy, nodes: []const canvas.WidgetLayoutNode, output: []CanvasWidgetControlReconcileEntry) []const CanvasWidgetControlReconcileEntry {
|
|
2572
|
+
const plan = retention.collect(policy, .control, nodes, @as([]const CanvasWidgetSourceTextEntry, &.{}), output.len, 0) orelse return collectCanvasWidgetControlReconcileEntries(nodes, output);
|
|
2573
|
+
for (plan.entries[0..plan.count], 0..) |entry, i| {
|
|
2574
|
+
const node = nodes[entry.node];
|
|
2575
|
+
output[i] = .{ .id = node.widget.id, .kind = node.widget.kind, .state = node.widget.state, .value = if (entry.resizable) node.frame.width else node.widget.value };
|
|
2576
|
+
}
|
|
2577
|
+
return output[0..plan.count];
|
|
2578
|
+
}
|
|
2579
|
+
pub fn collectCanvasWidgetScrollReconcileEntriesWithPolicy(policy: retention.Policy, nodes: []const canvas.WidgetLayoutNode, states: []const canvas.ScrollState, output: []CanvasWidgetScrollReconcileEntry) []const CanvasWidgetScrollReconcileEntry {
|
|
2580
|
+
const plan = retention.collect(policy, .scroll, nodes, @as([]const CanvasWidgetSourceTextEntry, &.{}), output.len, @min(nodes.len, states.len)) orelse return collectCanvasWidgetScrollReconcileEntries(nodes, states, output);
|
|
2581
|
+
for (plan.entries[0..plan.count], 0..) |entry, i| output[i] = .{ .id = nodes[entry.node].widget.id, .state = states[entry.node] };
|
|
2582
|
+
return output[0..plan.count];
|
|
2583
|
+
}
|
|
2584
|
+
pub fn collectCanvasWidgetTextReconcileEntriesWithPolicy(policy: retention.Policy, nodes: []const canvas.WidgetLayoutNode, source_entries: []const CanvasWidgetSourceTextEntry, output: []CanvasWidgetTextReconcileEntry, text_storage: []u8, text_len: *usize) anyerror![]const CanvasWidgetTextReconcileEntry {
|
|
2585
|
+
const plan = retention.collect(policy, .text, nodes, source_entries, output.len, 0) orelse return collectCanvasWidgetTextReconcileEntries(nodes, source_entries, output, text_storage, text_len);
|
|
2586
|
+
for (plan.entries[0..plan.count], 0..) |entry, i| {
|
|
2587
|
+
const widget = nodes[entry.node].widget;
|
|
2588
|
+
const text_range = try appendWidgetTextStorageRange(text_storage, text_len, widget.text);
|
|
2589
|
+
const source_entry: ?CanvasWidgetSourceTextEntry = if (entry.source) |index| source_entries[index] else null;
|
|
2590
|
+
const source_text = if (source_entry) |source| CanvasWidgetSourceTextFingerprint{ .len = source.text_len, .hash = source.text_hash } else canvasWidgetSourceTextFingerprint(widget.text);
|
|
2591
|
+
output[i] = .{
|
|
2592
|
+
.id = widget.id,
|
|
2593
|
+
.kind = widget.kind,
|
|
2594
|
+
.text = text_storage[text_range.start..text_range.end],
|
|
2595
|
+
.static_text_group_id = widget.static_text_group_id,
|
|
2596
|
+
.source_text_len = source_text.len,
|
|
2597
|
+
.source_text_hash = source_text.hash,
|
|
2598
|
+
.source_text_selection = if (source_entry) |source| source.text_selection else null,
|
|
2599
|
+
.text_selection = widget.text_selection,
|
|
2600
|
+
.text_composition = widget.text_composition,
|
|
2601
|
+
.value = widget.value,
|
|
2602
|
+
.value_x = widget.value_x,
|
|
2603
|
+
.code_content_width = if (!entry.code_diff) widget.code_content_width else 0,
|
|
2604
|
+
.code_content_width_generation = if (!entry.code_diff) widget.code_content_width_generation else 0,
|
|
2605
|
+
.code_content_width_font_id = if (!entry.code_diff) widget.code_content_width_font_id else 0,
|
|
2606
|
+
.code_content_width_size_bits = if (!entry.code_diff) widget.code_content_width_size_bits else 0,
|
|
2607
|
+
};
|
|
2608
|
+
}
|
|
2609
|
+
return output[0..plan.count];
|
|
2610
|
+
}
|