veandco / go-sdl2

SDL2 binding for Go
https://godoc.org/github.com/veandco/go-sdl2
BSD 3-Clause "New" or "Revised" License
2.2k stars 218 forks source link

how to get text from sdl.TextInputEvent.Text??? #384

Closed dedalqq closed 5 years ago

dedalqq commented 5 years ago
type TextInputEvent struct {
         .......................
    Text      [C.SDL_TEXTINPUTEVENT_TEXT_SIZE]byte // the null-terminated input text in UTF-8 encoding
}

i do not found examples for this. =(

gonutz commented 5 years ago

You can go through the Text variable until you find a 0. This marks the end of the string, say that i is the index at which the 0 occurs, then you would get the text string like this: s := string(event.Text[:i]).

veeableful commented 5 years ago

Hi @dedalqq, I added GetText() method to get the text as string from the TextEditingEvent and TextInputEvent. Let me know if it works!

gonutz commented 5 years ago

Don't you want to close this issue? I have tested the code and it works fine :-)

veeableful commented 5 years ago

Thanks for testing it @gonutz! I shall close this issue then~