Render above
This commit is contained in:
parent
aee31e8f3a
commit
a90cfcae06
1 changed files with 45 additions and 11 deletions
56
program.odin
56
program.odin
|
|
@ -26,6 +26,10 @@ UiElementData_FloatInput :: struct {
|
|||
value_string: cstring,
|
||||
}
|
||||
|
||||
UiElementData_Dropdown :: struct {
|
||||
value: ^i32,
|
||||
}
|
||||
|
||||
UiButtonType :: enum {
|
||||
Button,
|
||||
Dropdown,
|
||||
|
|
@ -93,6 +97,7 @@ Program :: struct {
|
|||
ui_element_focus: ui.ElementId,
|
||||
matrix_float_pool: []f32,
|
||||
matrix_value_string_pool: []InputFloatField,
|
||||
matrix_create_dropdown_value: MatrixTypes,
|
||||
matrix_count: int,
|
||||
matrix_scroll: f32,
|
||||
matrix_scroll_speed: f32,
|
||||
|
|
@ -216,10 +221,9 @@ program_build_ui :: proc() -> (elements: []ui.Element, matrix_container: ^ui.Ele
|
|||
ui.same_line()
|
||||
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_data := new(UiElementData_Button, context.temp_allocator)
|
||||
matrix_dropdown_data^ = {type = .Dropdown}
|
||||
|
||||
ui.element(.Button, top_bar_dropdown_dimensions, matrix_dropdown_config)
|
||||
matrix_dropdown_data := new(UiElementData_Dropdown, context.temp_allocator)
|
||||
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.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) {
|
||||
scissor_container: ^ui.Element
|
||||
|
||||
defer {
|
||||
if scissor_container != nil {
|
||||
rl.EndScissorMode()
|
||||
scissor_container = nil
|
||||
}
|
||||
}
|
||||
render_above: ui.Element
|
||||
render_above.id = ui.element_id_invalid()
|
||||
|
||||
for &element in elements {
|
||||
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 {
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue