2#include "nuklear_internal.h"
10nk_tooltip_begin(
struct nk_context *ctx,
float width)
13 return nk_tooltip_begin_offset(ctx, width, ctx->style.window.tooltip_origin, ctx->style.window.tooltip_offset);
17nk_tooltip_begin_offset(
struct nk_context *ctx,
float width,
enum nk_tooltip_pos position,
struct nk_vec2 offset)
26 NK_ASSERT(ctx->current);
27 NK_ASSERT(ctx->current->layout);
28 if (!ctx || !ctx->current || !ctx->current->layout)
34 if (win->popup.win && ((
int)win->popup.type & (
int)NK_PANEL_SET_NONBLOCK))
38 h = (int)NK_MAX(win->layout->row.min_height, ctx->style.font->
height+2*ctx->style.window.padding.y);
41 x = nk_ifloorf(in->mouse.pos.x + 1) - (int)win->layout->clip.x + (
int)offset.x;
42 y = nk_ifloorf(in->mouse.pos.y + 1) - (int)win->layout->clip.y + (
int)offset.y;
59 case NK_MIDDLE_CENTER:
71 case NK_BOTTOM_CENTER:
80 NK_ASSERT(0 &&
"Invalid tooltip position");
85 float known_h = (float)h;
86 float clip_x = win->layout->clip.x;
87 float clip_y = win->layout->clip.y;
89 if (win->popup.win && win->popup.type == NK_PANEL_TOOLTIP &&
90 win->popup.
last_h > known_h)
91 known_h = win->popup.
last_h;
93 screen.x = (float)x + clip_x;
94 screen.y = (float)y + clip_y;
97 anchor.x = in->mouse.pos.x;
98 anchor.y = in->mouse.pos.y;
101 screen = nk_fit_popup_rect(ctx, screen, anchor, NK_POPUP_FIT_TOOLTIP, known_h, nk_false);
103 bounds.x = screen.x - clip_x;
104 bounds.y = screen.y - clip_y;
108 bounds.h = (screen.h + 0.5f < known_h) ? screen.h : (float)nk_iceilf(nk_null_rect.h);}
110 ret = nk_popup_begin(ctx, NK_POPUP_DYNAMIC,
111 "__##Tooltip##__", NK_WINDOW_NO_SCROLLBAR|NK_WINDOW_BORDER, bounds);
112 if (ret) win->layout->flags &= ~(nk_flags)NK_WINDOW_ROM;
113 win->popup.type = NK_PANEL_TOOLTIP;
114 ctx->current->layout->type = NK_PANEL_TOOLTIP;
122 NK_ASSERT(ctx->current);
123 if (!ctx || !ctx->current)
return;
136 if (nk_input_is_mouse_hovering_rect(&ctx->input, bounds)) {
137 nk_tooltip_offset(ctx, text, ctx->style.window.tooltip_origin, ctx->style.window.tooltip_offset);
146nk_do_tooltip_delay(
struct nk_context* ctx,
const char* text,
struct nk_rect bounds,
float* timer)
149 if (nk_input_is_mouse_hovering_still_delay_rect(ctx, bounds, timer, ctx->style.window.tooltip_delay)) {
150 nk_tooltip_offset(ctx, text, ctx->style.window.tooltip_origin, ctx->style.window.tooltip_offset);
160nk_do_tooltip_delay_clicked(
struct nk_context* ctx,
const char* text,
struct nk_rect bounds,
float* timer, nk_bool* clicked)
163 if (nk_input_is_mouse_hovering_still_delay_clicked_rect(ctx, bounds, timer, ctx->style.window.tooltip_delay, clicked)) {
164 nk_tooltip_offset(ctx, text, ctx->style.window.tooltip_origin, ctx->style.window.tooltip_offset);
169nk_tooltip_offset(
struct nk_context *ctx,
const char *text,
enum nk_tooltip_pos position,
struct nk_vec2 offset)
179 NK_ASSERT(ctx->current);
180 NK_ASSERT(ctx->current->layout);
182 if (!ctx || !ctx->current || !ctx->current->layout || !text)
187 padding = style->window.padding;
190 text_len = nk_strlen(text);
191 text_width = style->font->
width(style->font->userdata,
192 style->font->
height, text, text_len);
194 text_width += 2 * style->window.popup_padding.x;
195 text_width += 2 * style->window.popup_border;
196 text_height = (style->font->
height + 2 * padding.y);
199 if (nk_tooltip_begin_offset(ctx, (
float)text_width, position, offset)) {
200 nk_layout_row_dynamic(ctx, (
float)text_height, 1);
201 nk_text(ctx, text, text_len, NK_TEXT_LEFT);
207nk_tooltip(
struct nk_context *ctx,
const char *text)
210 nk_tooltip_offset(ctx, text, ctx->style.window.tooltip_origin, ctx->style.window.tooltip_offset);
212#ifdef NK_INCLUDE_STANDARD_VARARGS
214nk_tooltipf_offset(
struct nk_context *ctx,
enum nk_tooltip_pos position,
struct nk_vec2 offset,
const char *fmt, ...)
218 nk_tooltipfv_offset(ctx, position, offset, fmt, args);
222nk_tooltipf(
struct nk_context *ctx,
const char *fmt, ...)
226 nk_tooltipfv(ctx, fmt, args);
230nk_tooltipfv_offset(
struct nk_context *ctx,
enum nk_tooltip_pos position,
struct nk_vec2 offset,
const char *fmt, va_list args)
233 nk_strfmt(buf, NK_LEN(buf), fmt, args);
234 nk_tooltip_offset(ctx, buf, position, offset);
237nk_tooltipfv(
struct nk_context *ctx,
const char *fmt, va_list args)
240 nk_strfmt(buf, NK_LEN(buf), fmt, args);
241 nk_tooltip(ctx, buf);
nk_text_width_f width
!< max height of the font
float height
!< user provided font handle