Render above

This commit is contained in:
Synthasmagoria 2026-08-01 15:06:25 +02:00
commit a90cfcae06

View file

@ -26,6 +26,10 @@ UiElementData_FloatInput :: struct {
value_string: cstring, value_string: cstring,
} }
UiElementData_Dropdown :: struct {
value: ^i32,
}
UiButtonType :: enum { UiButtonType :: enum {
Button, Button,
Dropdown, Dropdown,
@ -93,6 +97,7 @@ Program :: struct {
ui_element_focus: ui.ElementId, ui_element_focus: ui.ElementId,
matrix_float_pool: []f32, matrix_float_pool: []f32,
matrix_value_string_pool: []InputFloatField, matrix_value_string_pool: []InputFloatField,
matrix_create_dropdown_value: MatrixTypes,
matrix_count: int, matrix_count: int,
matrix_scroll: f32, matrix_scroll: f32,
matrix_scroll_speed: f32, matrix_scroll_speed: f32,
@ -216,10 +221,9 @@ program_build_ui :: proc() -> (elements: []ui.Element, matrix_container: ^ui.Ele
ui.same_line() ui.same_line()
matrix_dropdown_config := top_bar_dropdown_config matrix_dropdown_config := top_bar_dropdown_config
matrix_dropdown_config.label = enum_to_raygui_options_string_hotkey(MatrixTypes, &matrix_add_hotkeys, context.temp_allocator) matrix_dropdown_config.label = enum_to_raygui_options_string_hotkey(MatrixTypes, &matrix_add_hotkeys, context.temp_allocator)
matrix_dropdown_data := new(UiElementData_Button, context.temp_allocator) matrix_dropdown_data := new(UiElementData_Dropdown, context.temp_allocator)
matrix_dropdown_data^ = {type = .Dropdown} matrix_dropdown_data^ = {value = cast(^i32)&program.matrix_create_dropdown_value}
ui.element(.Dropdown, top_bar_dropdown_dimensions, matrix_dropdown_config, matrix_dropdown_data)
ui.element(.Button, top_bar_dropdown_dimensions, matrix_dropdown_config)
} }
ui.container_end() ui.container_end()
@ -260,13 +264,8 @@ ui_mat3 :: proc(mat: []f32, value_strings: []InputFloatField, dimensions: ui.Dim
program_render_ui :: proc(ctx: ^ui.Context, elements: []ui.Element) { program_render_ui :: proc(ctx: ^ui.Context, elements: []ui.Element) {
scissor_container: ^ui.Element scissor_container: ^ui.Element
render_above: ui.Element
defer { render_above.id = ui.element_id_invalid()
if scissor_container != nil {
rl.EndScissorMode()
scissor_container = nil
}
}
for &element in elements { for &element in elements {
offset: v2 offset: v2
@ -320,6 +319,41 @@ program_render_ui :: proc(ctx: ^ui.Context, elements: []ui.Element) {
if rl.GuiValueBoxFloat(area, element.label, data.value_string, data.value, program.ui_element_focus == element.id) == 1 { if rl.GuiValueBoxFloat(area, element.label, data.value_string, data.value, program.ui_element_focus == element.id) == 1 {
program.ui_element_focus = element.id program.ui_element_focus = element.id
} }
case .Dropdown:
assert(element.data != nil, "Element data cannot be nil when creating a dropdown")
data := cast(^UiElementData_Dropdown)element.data
if program.ui_element_focus == element.id {
render_above = element
} else {
if rl.GuiDropdownBox(area, element.label, data.value, program.ui_element_focus == element.id) {
if program.ui_element_focus == element.id {
program.ui_element_focus = ui.element_id_invalid()
} else {
program.ui_element_focus = element.id
}
}
}
case:
rl.DrawRectangleRec(area, rl.MAGENTA)
}
}
if scissor_container != nil {
rl.EndScissorMode()
scissor_container = nil
}
if render_above.id != ui.element_id_invalid() {
#partial switch render_above.type {
case .Dropdown:
data := cast(^UiElementData_Dropdown)render_above.data
if rl.GuiDropdownBox(rl.Rectangle(render_above.area), render_above.label, data.value, program.ui_element_focus == render_above.id) {
if program.ui_element_focus == render_above.id {
program.ui_element_focus = ui.element_id_invalid()
} else {
program.ui_element_focus = render_above.id
}
}
} }
} }
} }