Focus bugfix

This commit is contained in:
Synthasmagoria 2026-08-01 14:14:51 +02:00
commit 16d456a10f
2 changed files with 12 additions and 11 deletions

View file

@ -1,6 +1,7 @@
package main package main
import rl "raylib" import rl "raylib"
import back "back"
import ui ".." import ui ".."
import "core:fmt" import "core:fmt"
@ -39,6 +40,9 @@ UiElementData_FloatInput :: struct {
} }
main :: proc() { main :: proc() {
back.register_segfault_handler()
_register_illegal_instruction_handler()
rl.SetTraceLogLevel(.WARNING) rl.SetTraceLogLevel(.WARNING)
rl.InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_CAPTION) rl.InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_CAPTION)
defer rl.CloseWindow() defer rl.CloseWindow()
@ -57,6 +61,7 @@ main :: proc() {
button_margin_value_string_x := cstring(make([^]u8, INPUT_FLOAT_CHARACTERS)) button_margin_value_string_x := cstring(make([^]u8, INPUT_FLOAT_CHARACTERS))
button_margin_value_string_y := cstring(make([^]u8, INPUT_FLOAT_CHARACTERS)) button_margin_value_string_y := cstring(make([^]u8, INPUT_FLOAT_CHARACTERS))
element_focus_id := ui.element_id_invalid() element_focus_id := ui.element_id_invalid()
debug_element_focus_id := ui.element_id_invalid()
for !rl.WindowShouldClose() { for !rl.WindowShouldClose() {
ui.start(&ctx, origin = {0, 0}, size = {WINDOW_WIDTH, WINDOW_HEIGHT}) ui.start(&ctx, origin = {0, 0}, size = {WINDOW_WIDTH, WINDOW_HEIGHT})
@ -119,10 +124,10 @@ main :: proc() {
debug_elements := ui.end() debug_elements := ui.end()
if rl.IsKeyPressed(.TAB) { if rl.IsKeyPressed(.TAB) {
element_focus_id = ui.focus_next_element(element_focus_id, {.InputFloat}) debug_element_focus_id = ui.focus_next_element(debug_element_focus_id, debug_elements, {.InputFloat})
} }
render_ui_elements(&ctx, &element_focus_id, debug_elements) render_ui_elements(&ctx, &debug_element_focus_id, debug_elements)
} }
} }
@ -151,7 +156,7 @@ ui_input_float_2d :: proc(width, height: ui.Size_Percentage, config: ui.ElementC
ui.same_line() ui.same_line()
data = new(UiElementData_FloatInput, allocator) data = new(UiElementData_FloatInput, allocator)
data^ = {value_string = value_string_x, value = &value.x} data^ = {value_string = value_string_y, value = &value.y}
ui.element(.InputFloat, dimensions, {margin = config.margin}, data) ui.element(.InputFloat, dimensions, {margin = config.margin}, data)
ui.container_end() ui.container_end()
return container return container

12
ui.odin
View file

@ -119,18 +119,14 @@ same_line :: proc() {
ctx.same_line = true ctx.same_line = true
} }
focus_next_element :: proc(id: ElementId, allowed_focus: bit_set[ElementType]) -> ElementId { focus_next_element :: proc(id: ElementId, elements: []Element, allowed_focus: bit_set[ElementType]) -> ElementId {
if id == element_id_invalid() { if id == element_id_invalid() {
return element_id_invalid() return element_id_invalid()
} }
element_index := int(id.element_index) element_index := int(id.element_index)
if element_index + 1 >= len(ctx.elements) { for element_index < len(elements) {
return element_id_invalid() if elements[element_index].type in allowed_focus {
} return elements[element_index].id
element_index += 1
for element_index < len(ctx.elements) {
if ctx.elements[element_index].type in allowed_focus {
return ctx.elements[element_index].id
} }
element_index += 1 element_index += 1
} }