Documentation
¶
Overview ¶
Package textmetrics provides text-to-pixel coordinate mapping for text editing widgets. It is the single source of truth for cursor positioning, selection highlighting, and mouse-click-to-rune conversion.
All methods use widget.Canvas.MeasureText for accurate measurement, replacing the approximate charWidthRatio constants that were previously hardcoded in individual theme painters.
This package is INTERNAL — not part of the public API. Widget implementations (TextField, future Editor) use it; theme painters do not.
Index ¶
- type Metrics
- func (m *Metrics) CursorRect(contentRect geometry.Rect, displayText string, runePos int, ...) geometry.Rect
- func (m *Metrics) CursorX(contentRect geometry.Rect, displayText string, runePos int) float32
- func (m *Metrics) RuneIndexFromX(contentRect geometry.Rect, displayText string, x float32) int
- func (m *Metrics) SelectionRect(contentRect geometry.Rect, displayText string, start, end int) geometry.Rect
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Metrics ¶
Metrics provides text measurement for a specific canvas and font size.
func (*Metrics) CursorRect ¶
func (m *Metrics) CursorRect(contentRect geometry.Rect, displayText string, runePos int, cursorWidth float32) geometry.Rect
CursorRect returns the cursor line rectangle for the given rune position. Height is based on fontSize * lineHeightRatio minus caretHeightOffset on each side (Flutter _kCaretHeightOffset pattern), vertically centered in contentRect.
func (*Metrics) CursorX ¶
CursorX returns the X coordinate for a cursor at the given rune position within the content rect. Uses MeasureText for accurate positioning.
func (*Metrics) RuneIndexFromX ¶
RuneIndexFromX converts an X coordinate to a rune index (for hit-testing). Returns the rune position closest to the given X within the content rect.