text/v2: swap the arguments of Advance for consistency

This commit is contained in:
Hajime Hoshi 2023-11-15 03:16:59 +09:00
parent 1e78c2e6b0
commit 46600b42f9
2 changed files with 4 additions and 4 deletions

View File

@ -97,7 +97,7 @@ func (t *TextField) textIndexByCursorPosition(x, y int) (int, bool) {
var prevAdvance float64 var prevAdvance float64
for i, r := range t.text { for i, r := range t.text {
var x0, x1 int var x0, x1 int
currentAdvance := text.Advance(fontFace, t.text[lineStart:i]) currentAdvance := text.Advance(t.text[lineStart:i], fontFace)
if lineStart < i { if lineStart < i {
x0 = int((prevAdvance + currentAdvance) / 2) x0 = int((prevAdvance + currentAdvance) / 2)
} }
@ -108,7 +108,7 @@ func (t *TextField) textIndexByCursorPosition(x, y int) (int, bool) {
for !utf8.ValidString(t.text[i:nextI]) { for !utf8.ValidString(t.text[i:nextI]) {
nextI++ nextI++
} }
nextAdvance := text.Advance(fontFace, t.text[lineStart:nextI]) nextAdvance := text.Advance(t.text[lineStart:nextI], fontFace)
x1 = int((currentAdvance + nextAdvance) / 2) x1 = int((currentAdvance + nextAdvance) / 2)
} else { } else {
x1 = int(currentAdvance) x1 = int(currentAdvance)
@ -255,7 +255,7 @@ func (t *TextField) cursorPos() (int, int) {
if t.state.Text != "" { if t.state.Text != "" {
txt += t.state.Text[:t.state.CompositionSelectionStartInBytes] txt += t.state.Text[:t.state.CompositionSelectionStartInBytes]
} }
x := int(text.Advance(fontFace, txt)) x := int(text.Advance(txt, fontFace))
y := nlCount * int(fontFace.Metrics().Height) y := nlCount * int(fontFace.Metrics().Height)
return x, y return x, y
} }

View File

@ -120,7 +120,7 @@ type Glyph struct {
// Advance doesn't treat multiple lines. // Advance doesn't treat multiple lines.
// //
// Advance is concurrent-safe. // Advance is concurrent-safe.
func Advance(face Face, text string) float64 { func Advance(text string, face Face) float64 {
return face.advance(text) return face.advance(text)
} }