GUI fields now trim leading and trailing whitespace:
This commit is contained in:
@@ -7,6 +7,13 @@ import (
|
||||
cimgui "github.com/AllenDang/cimgui-go/imgui"
|
||||
)
|
||||
|
||||
const (
|
||||
sdlKModShift uint16 = 0x0001 | 0x0002
|
||||
sdlKModCtrl uint16 = 0x0040 | 0x0080
|
||||
sdlKModAlt uint16 = 0x0100 | 0x0200
|
||||
sdlKModGUI uint16 = 0x0400 | 0x0800
|
||||
)
|
||||
|
||||
// SDL3 event (128 byte raw buffer) -> imgui
|
||||
func (c *Context) ProcessEvent(event *[128]byte) {
|
||||
eventType := *(*uint32)(unsafe.Pointer(&event[0]))
|
||||
@@ -15,7 +22,9 @@ func (c *Context) ProcessEvent(event *[128]byte) {
|
||||
switch eventType {
|
||||
case sdl.EventKeyDown, sdl.EventKeyUp:
|
||||
scancode := *(*uint32)(unsafe.Pointer(&event[24]))
|
||||
modifiers := *(*uint16)(unsafe.Pointer(&event[32]))
|
||||
down := eventType == sdl.EventKeyDown
|
||||
c.addKeyModifiers(modifiers)
|
||||
key := sdlScancodeToImGuiKey(scancode)
|
||||
if key >= 0 {
|
||||
c.io.AddKeyEvent(key, down)
|
||||
@@ -47,6 +56,13 @@ func (c *Context) ProcessEvent(event *[128]byte) {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Context) addKeyModifiers(modifiers uint16) {
|
||||
c.io.AddKeyEvent(cimgui.ModCtrl, modifiers&sdlKModCtrl != 0)
|
||||
c.io.AddKeyEvent(cimgui.ModShift, modifiers&sdlKModShift != 0)
|
||||
c.io.AddKeyEvent(cimgui.ModAlt, modifiers&sdlKModAlt != 0)
|
||||
c.io.AddKeyEvent(cimgui.ModSuper, modifiers&sdlKModGUI != 0)
|
||||
}
|
||||
|
||||
func sdlScancodeToImGuiKey(scancode uint32) cimgui.Key {
|
||||
switch scancode {
|
||||
case 40: // SDL_SCANCODE_RETURN
|
||||
@@ -79,6 +95,10 @@ func sdlScancodeToImGuiKey(scancode uint32) cimgui.Key {
|
||||
return cimgui.KeyLeftAlt
|
||||
case 230: // SDL_SCANCODE_RALT
|
||||
return cimgui.KeyRightAlt
|
||||
case 227: // SDL_SCANCODE_LGUI
|
||||
return cimgui.KeyLeftSuper
|
||||
case 231: // SDL_SCANCODE_RGUI
|
||||
return cimgui.KeyRightSuper
|
||||
default:
|
||||
// Letters A-Z: scancodes 4-29 map to ImGui KeyA-KeyZ
|
||||
if scancode >= 4 && scancode <= 29 {
|
||||
|
||||
Reference in New Issue
Block a user