Skip to content

fix(textfield): cursor rounding, horizontal scroll, hinted advances (#211, #212) - #213

Merged
kolkov merged 6 commits into
mainfrom
fix/cursor-rounding-211
Aug 7, 2026
Merged

fix(textfield): cursor rounding, horizontal scroll, hinted advances (#211, #212)#213
kolkov merged 6 commits into
mainfrom
fix/cursor-rounding-211

Conversation

@kolkov

@kolkov kolkov commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Summary

Details

Cursor rounding (#211)

DrawText rounds text origin with math.Round(x), but CursorX used raw contentRect.Min.X — up to 0.5px constant offset.

Horizontal scroll (#212)

TextField now scrolls text horizontally when content exceeds visible width. ensureCursorVisible() adjusts scrollOffsetX to keep cursor within the visible content area. TextRect in PaintState separates text drawing origin from clip rect (ContentRect).

Cursor-scroll sync (Flutter/Qt pattern)

Root cause of cursor drift: CursorX clamped to scrolledRect.Max.X (shifted far left) instead of the visible area. Fix: compute cursor in text-local coordinates (unshifted contentRect), then apply scrollOffsetX uniformly to cursor and selection — matching Flutter _paintOffset and Qt topLeft patterns.

Hinted advances (gg#479)

gg v0.50.13: Face.Advance() now returns hinted advances matching drawGlyphs positioning. Eliminates per-glyph cursor drift on wide Cyrillic characters.

Test plan

  • go build ./...
  • go test ./... -count=1 (61 packages, 0 fail)
  • golangci-lint run --timeout=5m (0 issues)
  • Visual: hello, gallery, ide, taskmanager, signals examples verified
  • Visual: cursor stays at right edge during typing
  • Visual: arrow keys move cursor freely within visible zone
  • 14 scroll-specific tests

kolkov added 6 commits August 6, 2026 18:10
…ext (#211)

DrawText rounds text origin with math.Round(x), but CursorX used raw
contentRect.Min.X — up to 0.5px constant offset. Now both agree.
TextField scrolls text horizontally when content exceeds visible width.
Cursor stays near right edge via ensureCursorVisible (Flutter pattern).
TextRect in PaintState separates text origin from clip rect.
All 4 theme painters use TextRect for DrawText, ContentRect for PushClip.

Known: cursor-scroll sync has drift on fast input (investigating).
…ern (#211, #212)

Root cause: CursorX clamped to scrolledRect.Max.X instead of letting
PushClip handle visibility. Cursor computed in text-local coords now,
scrollOffsetX applied uniformly to cursor/selection/text (Flutter
_paintOffset, Qt topLeft pattern). Removed CursorX clamp.
@codecov

codecov Bot commented Aug 6, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 89.36170% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
core/textfield/widget.go 94.11% 1 Missing and 1 partial ⚠️
theme/cupertino/textfield.go 0.00% 1 Missing ⚠️
theme/fluent/textfield.go 0.00% 1 Missing ⚠️
theme/material3/textfield.go 0.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@kolkov
kolkov merged commit e2f8050 into main Aug 7, 2026
14 of 17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant