Tooltip functionality
This commit is contained in:
parent
dbdd0e9bab
commit
2a302f7b1d
4 changed files with 62 additions and 11 deletions
31
program.odin
31
program.odin
|
|
@ -214,6 +214,7 @@ Program :: struct {
|
|||
ui_overlay_context: ui.Context,
|
||||
ui_overlay_element_focus: ui.ElementId,
|
||||
ui_overlay_queue_focus_first: bool,
|
||||
ui_tooltip_offset: v2,
|
||||
matrix_float_pool: []f32,
|
||||
matrix_value_string_pool: []InputFloatField,
|
||||
matrix_create_dropdown_value: HotkeyTypes,
|
||||
|
|
@ -305,6 +306,7 @@ program_init :: proc(allocator := context.allocator) {
|
|||
program.ui_element_focus = ui.element_id_invalid()
|
||||
ui.init(&program.ui_overlay_context, 200, ui_measure_text, &program.font_style, allocator)
|
||||
program.ui_overlay_element_focus = ui.element_id_invalid()
|
||||
program.ui_tooltip_offset = 20.0
|
||||
|
||||
animation_init(&program.animation, program.matrix_float_pool)
|
||||
|
||||
|
|
@ -567,29 +569,31 @@ program_build_workspace_ui :: proc(ctx: ^ui.Context) ->
|
|||
top_bar_dropdown_dimensions := ui.Dimensions {ui.Size_Pixels(160.0), ui.Size_Percentage(1.0)}
|
||||
top_bar_dropdown_config := ui.ElementConfiguration {margin = top_bar_element_margin}
|
||||
{
|
||||
button_config := top_bar_button_config
|
||||
button_margin := top_bar_element_margin
|
||||
button_config: ui.ElementConfiguration
|
||||
button_dimensions := top_bar_button_dimensions
|
||||
button_data: ^UiElementData_Button
|
||||
|
||||
button_data = new(UiElementData_Button, context.temp_allocator)
|
||||
button_config.label = "I"
|
||||
button_config = {margin = button_margin, label = "I", tooltip = "Add identity\nmatrix"}
|
||||
button_data^ = {type = .AddIdentity}
|
||||
ui.element(.Button, button_dimensions, button_config, button_data)
|
||||
|
||||
button_data = new(UiElementData_Button, context.temp_allocator)
|
||||
button_config.label = "T"
|
||||
button_config = {margin = button_margin, label = "T", tooltip = "Add translation\nmatrix"}
|
||||
button_data^ = {type = .AddTranslation}
|
||||
ui.same_line()
|
||||
ui.element(.Button, button_dimensions, button_config, button_data)
|
||||
|
||||
button_data = new(UiElementData_Button, context.temp_allocator)
|
||||
button_config.label = "S"
|
||||
button_config = {margin = button_margin, label = "S", tooltip = "Add scale\nmatrix"}
|
||||
button_data^ = {type = .AddScale}
|
||||
ui.same_line()
|
||||
ui.element(.Button, button_dimensions, button_config, button_data)
|
||||
|
||||
button_data = new(UiElementData_Button, context.temp_allocator)
|
||||
button_config.label = "R"
|
||||
button_config = {margin = button_margin, label = "R", tooltip = "Add rotation\nmatrix"}
|
||||
button_data^ = {type = .AddRotation}
|
||||
ui.same_line()
|
||||
ui.element(.Button, button_dimensions, button_config, button_data)
|
||||
|
|
@ -738,6 +742,9 @@ program_handle_mouse :: proc(mouse_state: MouseState, top_bar_container, matrix_
|
|||
}
|
||||
|
||||
program_render_ui_and_handle_focus :: proc(ctx: ^ui.Context, focus_element_id: ui.ElementId, font_style: FontStyle, elements: []ui.Element) -> (focus: ui.ElementId) {
|
||||
tooltip_text: cstring
|
||||
tooltip_position: v2
|
||||
|
||||
scissor_container: ^ui.Element
|
||||
render_above: ui.Element
|
||||
render_above.id = ui.element_id_invalid()
|
||||
|
|
@ -794,7 +801,12 @@ program_render_ui_and_handle_focus :: proc(ctx: ^ui.Context, focus_element_id: u
|
|||
rl.GuiGroupBox(area, element.label)
|
||||
}
|
||||
case .Button:
|
||||
if (rl.GuiButton(area, element.label)) {
|
||||
if len(element.tooltip) > 0 && rect_has_point(area, rl.GetMousePosition()) {
|
||||
tooltip_text = element.tooltip
|
||||
// TODO (synthas): implement keeping the rectangle within screen borders
|
||||
tooltip_position = rl.GetMousePosition()
|
||||
}
|
||||
if rl.GuiButton(area, element.label) {
|
||||
if element.data == nil do break
|
||||
data := cast(^UiElementData_Button)element.data
|
||||
switch data.type {
|
||||
|
|
@ -919,6 +931,15 @@ program_render_ui_and_handle_focus :: proc(ctx: ^ui.Context, focus_element_id: u
|
|||
}
|
||||
}
|
||||
|
||||
if len(tooltip_text) > 0 {
|
||||
position := tooltip_position + program.ui_tooltip_offset
|
||||
size := measure_text(tooltip_text, program.font_style)
|
||||
bounds := rect_grow(rect_from(position, size), 4.0)
|
||||
rl.DrawRectangleRec(bounds, rl.BLACK)
|
||||
rl.DrawRectangleLinesEx(bounds, 1.0, rl.WHITE)
|
||||
draw_multiline_text_centered(tooltip_text, position, program.font_style, rl.WHITE, context.temp_allocator)
|
||||
}
|
||||
|
||||
return focus_element_id
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue