native icon indicating copy to clipboard operation
native copied to clipboard

scroll: add horizontal axis and orthogonal nested routing

Open sreyassabbani opened this issue 4 months ago • 1 comments

scroll: add horizontal axis and orthogonal nested routing

Problem

Canvas scroll views currently support only vertical scrolling. The platform input contract already carries both delta_x and delta_y in types.zig, but the canvas event path in canvas_widget_events.zig forwards only the vertical component. The AppKit scroll handler is likewise implemented around a vertical offset in appkit_host.m.

As a result, a native trackpad gesture cannot navigate a horizontal timeline, calendar, or carousel. This becomes especially noticeable when a horizontally scrollable region contains a vertically scrollable child: the vertical child can scroll, but horizontal momentum over that child has no horizontal ancestor to reach.

Minimal reproduction

  1. Create a scroll view whose content is wider than its viewport and configure it for horizontal scrolling.
  2. Place a vertically scrollable region inside the horizontal region.
  3. Hover the nested vertical region and perform a horizontal two-finger trackpad gesture.
  4. Observe that the horizontal region does not move because the canvas event path discards delta_x.
  5. Perform a vertical gesture and observe that the inner vertical region scrolls normally.

Expected behavior

  • A horizontal gesture scrolls the deepest eligible horizontal region.
  • A vertical gesture scrolls the deepest eligible vertical region.
  • For an orthogonally nested pair, each gesture reaches the region matching its axis.
  • Once a gesture chooses an axis, momentum remains locked to that axis so minor diagonal noise does not switch targets mid-gesture.
  • When a same-axis inner region reaches its extent, the existing saturation handoff behavior continues to pass remaining movement to an eligible ancestor.

Proposed scope

Add a single-axis scroll contract:

  • Introduce WidgetScrollAxis { vertical, horizontal }.
  • Expose the axis through Native markup, for example axis="horizontal", and through Zig as ElementOptions.scroll_axis.
  • Retain the existing scalar scroll offset and interpret it along the selected axis.
  • Make scroll layout, content extents, semantics, keyboard behavior, scrollbar placement, and native driver updates axis-aware. The current layout path calculates vertical scroll geometry in widget_layout.zig, while the driver derives a vertical extent in canvas_widget_scroll_drivers.zig; both would select their active dimension from the new axis.
  • Route each gesture to the deepest scroll region whose configured axis matches the gesture's locked dominant axis.
  • Choose that axis from the first meaningful input sample and retain it through the gesture's momentum phase.
  • Preserve the existing same-axis nested boundary handoff covered by the vertical nested-scroll tests in canvas_widget_scroll_tests.zig.

This keeps the change narrow: one scrollable axis per region, one scalar offset, and one axis-aware routing rule. Supporting simultaneous two-dimensional scrolling is not required.

Non-goals

The following application-level features should remain separate from this change:

  • synchronized scroll groups
  • content recycling or reach-boundary callbacks
  • scrollbar visibility controls
  • nested template iteration

Existing issues and pull requests

No existing issue or pull request found against upstream main at eefa369 covers general horizontal canvas scrolling or orthogonal nested routing. PR #90 and PR #83 concern text-field scrolling and do not appear to be the right threads to join.

sreyassabbani avatar Jul 17 '26 00:07 sreyassabbani

I traced this against current main before starting an implementation. The vertical assumptions still exist at three distinct seams:

  • the engine wheel path receives both deltas but applies only delta.dy
  • GpuSurfaceScrollDriver / its event expose only offset_y
  • AppKit locks a phased gesture to the deepest hit driver before considering the gesture's dominant axis

The last point makes orthogonal nesting more than a layout change. AppKit has phase / momentumPhase internally, but the shared GpuSurfaceInputEvent.scroll contract has no wheel phase. Could maintainers confirm these scope choices before I open a broad cross-layer PR?

  1. Should the shared scroll input gain an explicit begin/change/end phase so the engine can preserve one dominant-axis choice through momentum, or should phase locking remain a native-driver responsibility with per-sample dominant-axis routing on hosts without phased wheel input?
  2. For the pre-1.0 native driver contract, is an axis plus a neutral scalar offset / event offset preferred, or should the existing offset_y names remain for compatibility and be interpreted by axis?
  3. Should horizontal virtualized lists be rejected/out of scope initially, keeping virtualization vertical-only while ordinary scroll views become axis-aware?

A reviewable tracer slice could cover the enum/default-vertical API, markup parsing, non-virtual layout/extents, engine routing, and null-platform tests first; then add the AppKit native-driver ABI/gesture behavior once the phase contract is agreed. If you prefer one atomic PR because the macOS driver owns scrolling for eligible regions, I can keep the same non-goals but implement the full vertical-preserving path together.

narmi924 avatar Jul 19 '26 11:07 narmi924