Changed: Use GetCharPressed to get UTF-8 characters
Fixed: Backspace should remove last UTF-8 character
This commit is contained in:
parent
25ea53bfbb
commit
247567494f
1 changed files with 6 additions and 6 deletions
|
@ -3,6 +3,7 @@ package raygui
|
|||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
"unicode/utf8"
|
||||
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
@ -29,11 +30,9 @@ func TextBox(bounds rl.Rectangle, text string) string {
|
|||
borderColor = ToggleActiveBorderColor
|
||||
|
||||
framesCounter2++
|
||||
letter = rl.GetKeyPressed()
|
||||
if letter != -1 {
|
||||
if letter >= 32 && letter < 127 {
|
||||
text = fmt.Sprintf("%s%c", text, letter)
|
||||
}
|
||||
letter = rl.GetCharPressed()
|
||||
if letter != -1 && letter >= 32 {
|
||||
text = fmt.Sprintf("%s%c", text, letter)
|
||||
}
|
||||
|
||||
backspacing := rl.IsKeyPressed(rl.KeyBackspace)
|
||||
|
@ -46,7 +45,8 @@ func TextBox(bounds rl.Rectangle, text string) string {
|
|||
}
|
||||
}
|
||||
if backspacing && len(text) > 0 {
|
||||
text = text[:len(text)-1]
|
||||
_, size := utf8.DecodeLastRuneInString(text)
|
||||
text = text[:len(text)-size]
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue