Viewer trackpad gestures: two-finger scroll pans, pinch zooms

The Composition and Layer viewers took every scroll as a zoom, so a trackpad
could not pan. A trackpad's two-finger scroll now pans; a pinch,
Ctrl/Cmd+scroll, a mouse wheel and Alt + a trackpad scroll zoom around the
pointer.

Where the platform names the device (egui's MouseWheelSource, macOS), that
decides. Elsewhere browsers and some high-resolution wheels report a mouse
wheel in points, as a trackpad does, so the unit alone doesn't decide. A
scroll in points pans only once it has shown it is a trackpad: a touch phase,
movement on both axes at once, or a pinch. That holds until a wheel scrolls
in lines. Until then the vertical part zooms and the horizontal part pans.

ui.scroll gains unit (point|line), source (wheel|trackpad) and pinch so
agents can drive both gestures.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
pravdomil
2026-10-29 20:21:10 +01:00
co-authored by Claude Opus 5.5
parent 5ed248bece
commit caedb0727a
10 changed files with 280 additions and 26 deletions
+1 -1
View File
@@ -103,7 +103,7 @@ Points are logical window coordinates. A target is `{id}` (the element's centre;
| `ui.click` | `{id \| x,y, button?: left\|right\|middle, count?, modifiers?}` |
| `ui.move` | `{id \| x,y}` |
| `ui.drag` | `{from: target, to: target, steps? (12), modifiers?}`: press, move, release |
| `ui.scroll` | `{id \| x,y, dx, dy}` |
| `ui.scroll` | `{id \| x,y, dx?, dy?, unit?: point\|line, source?: wheel\|trackpad, pinch?, modifiers?}`: `line` is a mouse wheel (zooms the viewers); `point` (default) is a pixel-precise scroll; `source: trackpad` pans the viewers (as on macOS); with no `source` the viewers take a scroll in points as a wheel until one moves on both axes (a trackpad: from then on it pans); `pinch` is a trackpad pinch's zoom factor |
| `ui.key` | `{key}`, for example `Space`, `F9`, `Cmd+Z`, `Cmd+Shift+Z`, `PageDown`, `Escape` |
| `ui.type` | `{text}`: text input into the focused field |