exp/textinput: clarify the bounds for HandleInputWithBounds

This commit is contained in:
Hajime Hoshi
2025-05-12 22:52:45 +09:00
parent c112eb1752
commit dde281b93b
2 changed files with 3 additions and 1 deletions

View File

@@ -136,7 +136,7 @@ func (t *TextField) Update() error {
cx, cy := t.cursorPos()
px, py := textFieldPadding()
x0 := x + cx + px
x1 := x + cx + px + 6 // To be exact, this should be the width of the current character.
x1 := x0 + 1
y0 := y + cy + py
y1 := y0 + int(fontFace.Metrics().HLineGap+fontFace.Metrics().HAscent+fontFace.Metrics().HDescent)
handled, err := t.field.HandleInputWithBounds(image.Rect(x0, y0, x1, y1))

View File

@@ -109,6 +109,8 @@ func (f *Field) HandleInput(x, y int) (handled bool, err error) {
// HandleInputWithBounds updates the field state.
// HandleInputWithBounds must be called every tick, i.e., every Update, when Field is focused.
// HandleInputWithBounds takes a character bounds, which decides the position where an IME window is shown if needed.
// The bounds width doesn't matter very much as long as it is greater than 0.
// The bounds height should be the text height like a cursor height.
//
// HandleInputWithBounds returns whether the text inputting is handled or not.
// If HandleInputWithBounds returns true, a Field user should not handle further input events.