From b9e29dd7abd3c24fb13870eed35c86f5927c4793 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Madar=C3=A1sz?= Date: Mon, 16 Jan 2023 10:02:58 +0100 Subject: [PATCH] improve tooltips --- code/foundation/src/dev/debug_ui_tools.c | 5 ++--- code/foundation/src/gui/tooltip.c | 13 +++++++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/code/foundation/src/dev/debug_ui_tools.c b/code/foundation/src/dev/debug_ui_tools.c index 26a052a..405db09 100644 --- a/code/foundation/src/dev/debug_ui_tools.c +++ b/code/foundation/src/dev/debug_ui_tools.c @@ -3,7 +3,7 @@ #include "world/blocks.h" #include "models/items.h" -extern void tooltip_show(const char* name, float xpos, float ypos); +extern void tooltip_show_cursor(const char* name); void ToolAssetInspector(void) { if (nk_begin(dev_ui, "Asset Inspector", nk_rect(400, 100, 240, 800), @@ -19,8 +19,7 @@ void ToolAssetInspector(void) { nk_labelf(dev_ui, NK_TEXT_LEFT, "spawnable entity: %s", entity_spawn_provided(i) ? "true" : "false"); if (nk_button_label(dev_ui, "show tooltip")) { - Vector2 mpos = GetMousePosition(); - tooltip_show(asset_names[i] , mpos.x + 5, mpos.y + 5); + tooltip_show_cursor(asset_names[i]); } // draw block diff --git a/code/foundation/src/gui/tooltip.c b/code/foundation/src/gui/tooltip.c index 713546a..9113f0f 100644 --- a/code/foundation/src/gui/tooltip.c +++ b/code/foundation/src/gui/tooltip.c @@ -85,12 +85,16 @@ tooltip *tooltip__find_desc(const char *name) { return 0; } +void tooltip_clear(void); + void tooltip_show(const char* name, float xpos, float ypos) { if (!tooltips) return; tooltip *desc = tooltip__find_desc(name); if (!name) return; + tooltip_clear(); + main_tooltip = (tooltip_node) { .xpos = xpos, .ypos = ypos, @@ -99,6 +103,11 @@ void tooltip_show(const char* name, float xpos, float ypos) { }; } +void tooltip_show_cursor(const char* name) { + Vector2 mpos = GetMousePosition(); + tooltip_show(name, mpos.x + 15, mpos.y + 15); +} + void tooltip__clear_node(tooltip_node *node) { if (node->next) { tooltip__clear_node(node->next); @@ -132,8 +141,8 @@ void tooltip__draw_node(tooltip_node *node) { if (node->next) tooltip__clear_node(node->next); if (!node->next) node->next = zpl_malloc(sizeof(tooltip_node)); *node->next = (tooltip_node) { - .xpos = mpos.x+5, - .ypos = mpos.y+5, + .xpos = mpos.x+15, + .ypos = mpos.y+15, .desc = tooltip__find_desc(desc->links[i]), .next = 0 };