-
Notifications
You must be signed in to change notification settings - Fork 675
Add tooltip positioning V2 #900
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -839,12 +839,85 @@ overview(struct nk_context *ctx) | |
| } else popup_active = nk_false; | ||
| } | ||
|
|
||
| /* tooltip */ | ||
| nk_layout_row_static(ctx, 30, 150, 1); | ||
| /* tooltips */ | ||
| nk_layout_row_static(ctx, 30, 400, 1); | ||
| bounds = nk_widget_bounds(ctx); | ||
| nk_label(ctx, "Hover me for tooltip", NK_TEXT_LEFT); | ||
| if (nk_input_is_mouse_hovering_rect(in, bounds)) | ||
| nk_tooltip(ctx, "This is a tooltip"); | ||
| nk_label(ctx, "Hover for default tooltip", NK_TEXT_LEFT); | ||
| if (nk_input_is_mouse_hovering_rect(in, bounds)) { | ||
| nk_tooltip(ctx, "This is very boring default tooltip..."); | ||
| } | ||
| bounds = nk_widget_bounds(ctx); | ||
| nk_label(ctx, "Hover for Gnome-like tooltip", NK_TEXT_LEFT); | ||
| if (nk_input_is_mouse_hovering_rect(in, bounds)) { | ||
| struct nk_vec2 offset = { 0, 15 }; | ||
| nk_tooltip_offset(ctx, "Gnome centers above cursor with greater y offset", NK_TOOLTIP_ABOVE, offset); | ||
| } | ||
| bounds = nk_widget_bounds(ctx); | ||
| nk_label(ctx, "Hover for above-on-left tooltip", NK_TEXT_LEFT); | ||
| if (nk_input_is_mouse_hovering_rect(in, bounds)) { | ||
| struct nk_vec2 offset = { 0, 0 }; | ||
| nk_tooltip_offset(ctx, "above-on-left from cursor with 0:0 offset", NK_TOOLTIP_ABOVE|NK_TOOLTIP_ON_LEFT, offset); | ||
| } | ||
| bounds = nk_widget_bounds(ctx); | ||
| nk_label(ctx, "Hover for MAGIC!", NK_TEXT_LEFT); | ||
| if (nk_input_is_mouse_hovering_rect(in, bounds)) { | ||
| static double accum_time_seconds = 0.0; | ||
| const double speed = 3.0, radius = 50.0; | ||
| struct nk_vec2 offset; | ||
| offset.x = radius * cos(accum_time_seconds * speed); | ||
| offset.y = radius * sin(accum_time_seconds * speed); | ||
| nk_tooltip_offset(ctx, "WOW!", NK_TOOLTIP_ABS_OFFSET, offset); | ||
| accum_time_seconds += (double)(ctx->delta_time_seconds); | ||
| } | ||
|
|
||
| /* editor for custom tooltip */ | ||
| { | ||
| static char text_buf[64] = {0}; | ||
| static int text_len = 0; | ||
| static int text_initialized = 0; | ||
| static nk_flags tooltip = 0; | ||
| static struct nk_vec2 offset = {0}; | ||
| if (!text_initialized) { | ||
| const char text_default[] = "you can customize this!"; | ||
| NK_ASSERT(sizeof(text_default) < sizeof(text_buf)); | ||
| memcpy(text_buf, text_default, sizeof(text_default)); | ||
| text_len = sizeof(text_default) - 1; | ||
| text_initialized = 1; | ||
| } | ||
| bounds = nk_widget_bounds(ctx); | ||
| nk_label(ctx, "Hover for custom tooltip (you can customize it below)", NK_TEXT_LEFT); | ||
| if (nk_input_is_mouse_hovering_rect(in, bounds)) { | ||
| nk_tooltip_offset(ctx, text_buf, tooltip, offset); | ||
| } | ||
| nk_layout_row_dynamic(ctx, 1, 1); | ||
| nk_rule_horizontal(ctx, nk_white, nk_true); | ||
| nk_layout_row_dynamic(ctx, 30, 2); | ||
| nk_label(ctx, "custom tooltip text:", NK_TEXT_LEFT); | ||
| nk_edit_string(ctx, NK_EDIT_FIELD, text_buf, &text_len, sizeof(text_buf), nk_filter_default); | ||
| NK_ASSERT(text_len < (int)sizeof(text_buf)); | ||
| text_buf[text_len] = '\0'; /* TODO: why nk_edit_string is NOT setting this on its own? */ | ||
|
Comment on lines
+896
to
+898
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (from bottom of #900 (comment))
I think I've also seen this. I'm not entirely sure where this issue comes from (maybe two widgets get the same hash?) but given the fact that I was already confused by nk_edit_string behavior (the todo note), maybe I did something wrong here. |
||
| nk_layout_row_dynamic(ctx, 30, 1); | ||
| #define TOOLTIP_FOREACH_FLAG(BODY) \ | ||
| BODY(ABOVE) \ | ||
| BODY(BELOW) \ | ||
| BODY(ON_LEFT) \ | ||
| BODY(ON_RIGHT) \ | ||
| BODY(ABS_OFFSET) | ||
| #define TOOLTIP_CHECKBOX_FLAG(FLAG) \ | ||
| { \ | ||
| nk_bool checked = !!(tooltip & NK_TOOLTIP_##FLAG); \ | ||
| nk_checkbox_label_align(ctx, "custom tooltip flag: " #FLAG, &checked, NK_WIDGET_RIGHT, NK_TEXT_LEFT);\ | ||
| tooltip = checked ? (tooltip | NK_TOOLTIP_##FLAG) : (tooltip & ~NK_TOOLTIP_##FLAG); \ | ||
| } | ||
| TOOLTIP_FOREACH_FLAG(TOOLTIP_CHECKBOX_FLAG) | ||
| #undef TOOLTIP_FOREACH_FLAG | ||
| #undef TOOLTIP_CHECKBOX_FLAG | ||
|
Comment on lines
+899
to
+914
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this XMACRO is a bit overcomplicated. I wanted to save on space. Not sure, if it was worth it. (note: this can be changed to array and for-loop, maybe? but it would be a ton of code) |
||
| nk_layout_row_dynamic(ctx, 30, 2); | ||
| nk_label(ctx, "custom tooltip offset", NK_TEXT_LEFT); | ||
| nk_property_float(ctx, "x", -100.0f, &offset.x, 100.0f, 5.0f, 0.5f); | ||
| nk_label(ctx, "custom tooltip offset", NK_TEXT_LEFT); | ||
| nk_property_float(ctx, "y", -100.0f, &offset.y, 100.0f, 5.0f, 0.5f); | ||
| } | ||
|
|
||
| nk_tree_pop(ctx); | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was wondering, how do we fix the bug, where hovering a rect always triggers the tooltip to appear, even though there is another nk_window above it? [screenshot below]
I did not attempt to fix it as I thought maybe you guys know a more reliable way to trigger these? My idea was to simply check, if this branch runs on currently active nk_window, but I'm not so sure about it.
EDIT: for comparison, "chart" does not have this issue because it activates tooltip based on active chart index:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is similar to the bug where a scrollbar will activate (when you have AUTO_HIDE on) even if your mouse is in a popup on in front of the window.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmn... Tried to reproduce this with nk_window that comes with demo/overview but I couldn't. Though the scrollbar does not seem to be hiding as it should, so maybe I'm doing something wrong.
However, this does feel like the same bug. I've checked the code and it seems to be doing a similar thing:
Nuklear/src/nuklear_scrollbar.c
Lines 29 to 30 in 3bcdec2
If you could provide me with a repro I would just move it into a different task. This really feels like a bigger problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just tested and I get the bug at least with the sdl2 and sd3_renderer backends with the standard demo. Here's a video of the sdl2 renderer, sorry it doesn't record my cursor but I swear I keep it in the menu popup and the second window for the test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Screencast.from.2026-02-21.14-30-52.mp4
Forgot the video, oops.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Few notes:
There is
nk_widget_is_hoveredbut from what I see it needs active layout (?) and grepping for this shows no use inside of the repo. Strange...Nuklear/src/nuklear_widget.c
Lines 68 to 90 in 7295164
On the other hand, the chart is storing its own hover state based on
NK_WINDOW_ROM(which few other widgets also seem to be doing) and given how this flag was documented, this seems to be a hack, like it expects that active windows will always have this flag NOT set (which is correct but hacky)Nuklear/src/nuklear.h
Line 5509 in 7295164
Nuklear/src/nuklear_chart.c
Lines 173 to 181 in 7295164
I think, this is a refactor angle... Right now, every widget is trying to reimplement the wheel...