@@ -3828,14 +3828,13 @@ NK_API void nk_contextual_end(struct nk_context*);
38283828 *
38293829 * ============================================================================= */
38303830NK_API void nk_tooltip(struct nk_context*, const char*);
3831- NK_API void nk_tooltip_positioned(struct nk_context*, const char*, enum nk_tooltip_pos);
3832- NK_API void nk_tooltip_offset(struct nk_context*, const char*, struct nk_vec2);
3831+ NK_API void nk_tooltip_pos_offset(struct nk_context *ctx, const char *text, enum nk_tooltip_pos position, struct nk_vec2 offset);
38333832#ifdef NK_INCLUDE_STANDARD_VARARGS
38343833NK_API void nk_tooltipf(struct nk_context*, NK_PRINTF_FORMAT_STRING const char*, ...) NK_PRINTF_VARARG_FUNC(2);
38353834NK_API void nk_tooltipfv(struct nk_context*, NK_PRINTF_FORMAT_STRING const char*, va_list) NK_PRINTF_VALIST_FUNC(2);
38363835#endif
38373836NK_API nk_bool nk_tooltip_begin(struct nk_context*, float width);
3838- NK_API nk_bool nk_tooltip_begin_offset (struct nk_context*, float, struct nk_vec2);
3837+ NK_API nk_bool nk_tooltip_begin_pos_offset (struct nk_context*, float, enum nk_tooltip_pos , struct nk_vec2);
38393838NK_API void nk_tooltip_end(struct nk_context*);
38403839/* =============================================================================
38413840 *
@@ -30611,11 +30610,11 @@ NK_API nk_bool
3061130610nk_tooltip_begin(struct nk_context *ctx, float width)
3061230611{
3061330612 struct nk_vec2 offset = {0};
30614- return nk_tooltip_begin_offset (ctx, width, offset);
30613+ return nk_tooltip_begin_pos_offset (ctx, width, NK_TOP_LEFT , offset);
3061530614}
3061630615
3061730616NK_API nk_bool
30618- nk_tooltip_begin_offset (struct nk_context *ctx, float width, struct nk_vec2 offset)
30617+ nk_tooltip_begin_pos_offset (struct nk_context *ctx, float width, enum nk_tooltip_pos position , struct nk_vec2 offset)
3061930618{
3062030619 int x,y,w,h;
3062130620 struct nk_window *win;
@@ -30636,14 +30635,43 @@ nk_tooltip_begin_offset(struct nk_context *ctx, float width, struct nk_vec2 offs
3063630635 return 0;
3063730636
3063830637 w = nk_iceilf(width);
30639- h = nk_iceilf(nk_null_rect.h);
30638+ /* Should I use text_height? Any difference? */
30639+ h = ctx->current->layout->row.min_height;
30640+
30641+ /* Default origin is top left, plus user offset */
3064030642 x = nk_ifloorf(in->mouse.pos.x + 1) - (int)win->layout->clip.x + offset.x;
3064130643 y = nk_ifloorf(in->mouse.pos.y + 1) - (int)win->layout->clip.y + offset.y;
3064230644
30645+ /* Adjust origin based on enum */
30646+ switch (position) {
30647+ case NK_TOP_LEFT:
30648+ /* no change */
30649+ break;
30650+ case NK_BOTTOM_LEFT:
30651+ y -= h;
30652+ break;
30653+ case NK_TOP_RIGHT:
30654+ x -= w;
30655+ break;
30656+ case NK_BOTTOM_RIGHT:
30657+ x -= w;
30658+ y -= h;
30659+ break;
30660+ case NK_TOP_MIDDLE:
30661+ x -= w/2;
30662+ break;
30663+ case NK_BOTTOM_MIDDLE:
30664+ x -= w/2;
30665+ y -= h;
30666+ break;
30667+ default:
30668+ NK_ASSERT(0 && "Invalid tooltip position");
30669+ }
30670+
3064330671 bounds.x = (float)x;
3064430672 bounds.y = (float)y;
3064530673 bounds.w = (float)w;
30646- bounds.h = (float)h ;
30674+ bounds.h = (float)nk_iceilf(nk_null_rect.h) ;
3064730675
3064830676 ret = nk_popup_begin(ctx, NK_POPUP_DYNAMIC,
3064930677 "__##Tooltip##__", NK_WINDOW_NO_SCROLLBAR|NK_WINDOW_BORDER, bounds);
@@ -30665,7 +30693,7 @@ nk_tooltip_end(struct nk_context *ctx)
3066530693}
3066630694
3066730695NK_API void
30668- nk_tooltip_offset (struct nk_context *ctx, const char *text, struct nk_vec2 offset)
30696+ nk_tooltip_pos_offset (struct nk_context *ctx, const char *text, enum nk_tooltip_pos position , struct nk_vec2 offset)
3066930697{
3067030698 const struct nk_style *style;
3067130699 struct nk_vec2 padding;
@@ -30693,80 +30721,7 @@ nk_tooltip_offset(struct nk_context *ctx, const char *text, struct nk_vec2 offse
3069330721 text_height = (style->font->height + 2 * padding.y);
3069430722
3069530723 /* execute tooltip and fill with text */
30696- if (nk_tooltip_begin_offset(ctx, (float)text_width, offset)) {
30697- nk_layout_row_dynamic(ctx, (float)text_height, 1);
30698- nk_text(ctx, text, text_len, NK_TEXT_LEFT);
30699- nk_tooltip_end(ctx);
30700- }
30701- }
30702-
30703- NK_API void
30704- nk_tooltip_positioned(struct nk_context *ctx, const char *text, enum nk_tooltip_pos position)
30705- {
30706- const struct nk_style *style;
30707- struct nk_vec2 padding;
30708-
30709- int text_len;
30710- float text_width;
30711- float text_height;
30712-
30713- struct nk_vec2 offset = { 0 };
30714- int w,h;
30715-
30716- NK_ASSERT(ctx);
30717- NK_ASSERT(ctx->current);
30718- NK_ASSERT(ctx->current->layout);
30719- NK_ASSERT(text);
30720- if (!ctx || !ctx->current || !ctx->current->layout || !text)
30721- return;
30722-
30723- /* fetch configuration data */
30724- style = &ctx->style;
30725- padding = style->window.padding;
30726-
30727- /* calculate size of the text and tooltip */
30728- text_len = nk_strlen(text);
30729- text_width = style->font->width(style->font->userdata,
30730- style->font->height, text, text_len);
30731- text_width += (4 * padding.x);
30732- text_height = (style->font->height + 2 * padding.y);
30733-
30734- /* Should I use text_height? Any difference? */
30735- h = ctx->current->layout->row.min_height;
30736- w = nk_iceilf(text_width);
30737-
30738- switch (position) {
30739- case NK_TOP_LEFT:
30740- offset.x = 0;
30741- offset.y = 0;
30742- break;
30743- case NK_BOTTOM_LEFT:
30744- offset.x = 0;
30745- offset.y = -h;
30746- break;
30747- case NK_TOP_RIGHT:
30748- offset.x = -w;
30749- offset.y = 0;
30750- break;
30751- case NK_BOTTOM_RIGHT:
30752- offset.x = -w;
30753- offset.y = -h;
30754- break;
30755- case NK_TOP_MIDDLE:
30756- offset.x = -w/2;
30757- offset.y = 0;
30758- break;
30759- case NK_BOTTOM_MIDDLE:
30760- offset.x = -w/2;
30761- offset.y = -h;
30762- break;
30763- default:
30764- offset.x = 0;
30765- offset.y = 0;
30766- }
30767-
30768- /* execute tooltip and fill with text */
30769- if (nk_tooltip_begin_offset(ctx, (float)text_width, offset)) {
30724+ if (nk_tooltip_begin_pos_offset(ctx, (float)text_width, position, offset)) {
3077030725 nk_layout_row_dynamic(ctx, (float)text_height, 1);
3077130726 nk_text(ctx, text, text_len, NK_TEXT_LEFT);
3077230727 nk_tooltip_end(ctx);
0 commit comments