improve tooltips

efd/v1
Dominik Madarász 2023-01-16 10:02:58 +01:00
parent c8b21e86b5
commit b9e29dd7ab
2 changed files with 13 additions and 5 deletions

View File

@ -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

View File

@ -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
};