GUI fields now trim leading and trailing whitespace:

This commit is contained in:
Dmitry Sergeev
2026-09-02 00:23:03 +03:00
parent e7b032ce77
commit da5ff8ea4a
9 changed files with 200 additions and 15 deletions
+13
View File
@@ -3,6 +3,8 @@ package imgui
import (
"time"
"mxl-player/internal/sdl"
cimgui "github.com/AllenDang/cimgui-go/imgui"
)
@@ -17,9 +19,20 @@ func New() *Context {
ctx := cimgui.CreateContext()
cimgui.SetCurrentContext(ctx)
io := cimgui.CurrentIO()
cimgui.CurrentPlatformIO().SetClipboardHandler(sdlClipboardHandler{})
return &Context{ctx: ctx, io: io}
}
type sdlClipboardHandler struct{}
func (sdlClipboardHandler) GetClipboard() string {
return sdl.GetClipboardText()
}
func (sdlClipboardHandler) SetClipboard(text string) {
sdl.SetClipboardText(text)
}
func (c *Context) Destroy() {
cimgui.DestroyContext()
}
+20
View File
@@ -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 {