Commit Graph

3 Commits

Author SHA1 Message Date
fd508e4a68 fix: UITextInput focus and keyboard input - hitTest + dispatch handlers
Fixed three critical bugs preventing UITextInput from working:

1. **hitTest() missing textinput handler**: The hit test function only checked
   for button, slider, and checkbox types. Clicks on text input fields were
   never detected.

   FIX: Added textinput case to hitTest() in UIContext.cpp

2. **dispatchMouseButton() missing textinput handler**: Even if hit test worked,
   mouse button events were not dispatched to text input widgets.

   FIX: Added textinput case to dispatchMouseButton() in UIContext.cpp

3. **Keyboard event collision**: SDL_KEYDOWN was publishing events for printable
   characters with char=0, which were rejected by UITextInput. Printable chars
   should only come from SDL_TEXTINPUT.

   FIX: Only publish SDL_KEYDOWN for special keys (Backspace, Delete, arrows, etc.)
   Printable characters come exclusively from SDL_TEXTINPUT events.

Changes:
- UIContext.cpp: Added textinput handlers to hitTest() and dispatchMouseButton()
- UITextInput.cpp: Added debug logging for gainFocus() and render()
- UIModule.cpp: Added debug logging for widget clicks
- test_ui_showcase.cpp: Fixed keyboard event handling (KEYDOWN vs TEXTINPUT)

Tested: Text input now gains focus (border turns blue), accepts keyboard input,
and displays typed text correctly.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-14 14:36:49 +07:00
63751d6f91 fix: Multi-texture sprite rendering - setState per batch + transient buffers
Fixed two critical bugs preventing multiple textured sprites from rendering correctly:

1. **setState consumed by submit**: Render state was set once at the beginning,
   but bgfx consumes state at each submit(). Batches 2+ had no state → invisible.

   FIX: Call setState() before EACH batch, not once globally.

2. **Buffer overwrite race condition**: updateBuffer() is immediate but submit()
   is deferred. When batch 2 called updateBuffer(), it overwrote batch 1's data
   BEFORE bgfx executed the draw calls. All batches used the last batch's data
   → all sprites rendered at the same position (superimposed).

   FIX: Use transient buffers (one per batch, frame-local) instead of reusing
   the same dynamic buffer. Each batch gets its own isolated memory.

Changes:
- SpritePass: setState before each batch + transient buffer allocation per batch
- UIRenderer: Retained mode rendering (render:sprite:add/update/remove)
- test_ui_showcase: Added 3 textured buttons demo section
- test_3buttons_minimal: Minimal test case for multi-texture debugging

Tested: 3 textured buttons now render at correct positions with correct textures.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-14 14:05:56 +07:00
5cef0e25b0 fix: UIModule button interaction + JsonDataNode array children support
- Fix JsonDataNode::getChildReadOnly() to handle JSON array access by numeric index
- Fix test_ui_showcase to use JSON array for children (matching test_single_button pattern)
- Add visual test files: test_single_button, test_ui_showcase, test_sprite_debug
- Clean up debug logging from SpritePass, SceneCollector, UIButton, BgfxDevice

The root cause was that UITree couldn't access array children in JSON layouts.
UIButton hover/click now works correctly in both test files.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-05 18:23:16 +07:00