Browse Source

Fix drawing fields containing empty lines

main
Trevor Slocum 2 months ago
parent
commit
be02667790
  1. 4
      examples/messeji/game/game.go
  2. 7
      textfield.go

4
examples/messeji/game/game.go

@ -72,13 +72,13 @@ func NewDemoGame() *game {
},
}
g.buffer.SetText(strings.TrimSpace(initialText) + "\n")
g.buffer.SetText(strings.TrimSpace(initialText))
g.input.SetHandleKeyboard(true)
g.input.SetSelectedFunc(func() (accept bool) {
log.Printf("Input: %s", g.input.Text())
g.buffer.Write([]byte(fmt.Sprintf("Input: %s\n", g.input.Text())))
g.buffer.Write([]byte(fmt.Sprintf("\nInput: %s", g.input.Text())))
return true
})

7
textfield.go

@ -534,6 +534,13 @@ func (f *TextField) wrapContent(withScrollBar bool) {
}
f.bufferWrapped = f.bufferWrapped[:0]
for _, line := range strings.Split(buffer, "\n") {
// BoundString returns 0 for strings containing only whitespace.
if strings.TrimSpace(line) == "" {
f.bufferWrapped = append(f.bufferWrapped, "")
f.lineWidths = append(f.lineWidths, 0)
continue
}
l := len(line)
var start int
var end int

Loading…
Cancel
Save