Pinch-to-font-size (continuous, content-point pinned) + IME-open scroll fix

Two feature bodies accumulated in the working tree:

1. Pinch to change the app font size, continuously (no snapping):
   - internal/ui/pinch_tracker.go: logic-free touch state machine.
     Two-mover formation (the resting palm can land first or last;
     movement is the only signal valid for both), pair = the mover
     pair whose distance changed most, baseline = press distance
     (formDist), lazy pending releases, survivor-scroll forwarding
     after a pair break. Robust to ~1 fps frames: a whole pinch can
     land in one drain (formDist/brokeFactor/lazy releases).
   - render.go: pinch probe (raw pointer events) + grab lifecycle so
     the pair is exclusive (scroll sees nothing of the pair) and the
     survivor's finger keeps working as a scroll after the pinch.
   - state.go/logic.go/session.go/frame.go: app-local float font
     scale, content-point pin (buffer byte + offset from baseline,
     not a layout point, so rewrap keeps the same character under
     the center), restore/font pins, session persistence.
   - pinch_test.go, pinch_font_test.go, tag_identity_test.go,
     real_draw_probe_test.go: unit + real-Renderer/real-Router tests.

2. Soft keyboard must not shift content:
   - Root cause: gioui.org/app calls Router.RevealFocus on any frame
     the viewport shrinks (IME open under adjustResize) and
     synthesizes a pointer.Scroll nudge aimed at the focused field's
     stale pre-resize bounds; gesture.Scroll consumed it -> a 32 dp
     content jump.
   - Fix: main.go flags the shrink frame; render.go drains that one
     synthetic scroll for the gesture's tag before Update (scroll-
     range clamping cannot work: the router UNIONs ranges across
     frames). Finger scroll (pointer.Drag) and the flinger are
     untouched. reveal_focus_drain_test.go reproduces RevealFocus at
     the router level and verifies the drain + zero delta.

Also: tools/touchinject (platform-signed emulator multi-touch
injection harness + e2e script, adb has no two-finger input),
docs (spec 2.2 + development_plan 18-20), .gitignore, gofmt.
This commit is contained in:
gmp
2026-08-23 09:00:51 -04:00
parent 0f1b6e6290
commit 180fa966c8
23 changed files with 3302 additions and 45 deletions
+20 -1
View File
@@ -157,9 +157,13 @@ func run(w *app.Window) error {
// applied to the main-owned find input (edge-triggered, see
// Frame.FindClearSeq).
var lastFindClearSeq int
// lastFrameW/H hold the previous FrameEvent's window size (px); 0 = no
// frame yet. Used to spot shrink frames (see ZeroWheelScroll below).
var lastFrameW, lastFrameH int
for {
switch e := w.Event().(type) {
e := w.Event()
switch e := e.(type) {
case app.DestroyEvent:
if prof != nil {
prof.Stop()
@@ -237,6 +241,8 @@ func run(w *app.Window) error {
curScale = 1 // no frame yet
}
curFontScale := frame.FontScale // 0 until the logic has the value
// App-local pinch font scale for the editor text (1.0 = default).
renderer.SetAppFontScale(frame.AppFontScale)
renderer.Draw(gtx, frame.Elems, curScale)
glyphLayout := renderer.GlyphLayout()
// Send search query update to the logic goroutine when it changes.
@@ -255,7 +261,19 @@ func run(w *app.Window) error {
}
newFind := findEditor.Text()
sendFind := newFind != frame.FindQuery
// On a frame that shrinks the window (the IME opening under
// adjustResize), Gio's window synthesizes a scroll-to-focus
// pointer.Scroll via RevealFocus — it reads the focused field's
// stale pre-resize bounds and nudges the editor content. Flag the
// frame so CheckGestures drains that one synthetic event before the
// scroll gesture consumes it (Renderer.ZeroWheelScroll); finger
// scroll and the flinger are unaffected, and normal frames are
// untouched.
renderer.ZeroWheelScroll = lastFrameH > 0 &&
(e.Size.Y < lastFrameH || e.Size.X < lastFrameW)
lastFrameW, lastFrameH = e.Size.X, e.Size.Y
events := renderer.CheckGestures(e.Source, gtx.Metric)
renderer.ZeroWheelScroll = false
// Keep frames flowing while a long press is pending: a stationary
// finger generates no pointer events, so without this the window
// would sleep and the long-press threshold would never be reached.
@@ -384,6 +402,7 @@ func run(w *app.Window) error {
WindowStartByte: frame.WindowStartByte,
WindowStartLine: frame.WindowStartLine,
EditSeq: frame.EditSeq,
ScrollOffset: frame.ScrollOffset,
}
}
default: