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");
86 bounds.h = (float)nk_iceilf(nk_null_rect.h);
88 ret = nk_popup_begin(ctx, NK_POPUP_DYNAMIC,
89 "__##Tooltip##__", NK_WINDOW_NO_SCROLLBAR|NK_WINDOW_BORDER, bounds);
90 if (ret) win->layout->flags &= ~(nk_flags)NK_WINDOW_ROM;
91 win->popup.type = NK_PANEL_TOOLTIP;
92 ctx->current->layout->type = NK_PANEL_TOOLTIP;
100 NK_ASSERT(ctx->current);
101 if (!ctx || !ctx->current)
return;
114 if (nk_input_is_mouse_hovering_rect(&ctx->input, bounds)) {
115 nk_tooltip_offset(ctx, text, ctx->style.window.tooltip_origin, ctx->style.window.tooltip_offset);
124nk_do_tooltip_delay(
struct nk_context* ctx,
const char* text,
struct nk_rect bounds,
float* timer)
127 if (nk_input_is_mouse_hovering_still_delay_rect(ctx, bounds, timer, ctx->style.window.tooltip_delay)) {
128 nk_tooltip_offset(ctx, text, ctx->style.window.tooltip_origin, ctx->style.window.tooltip_offset);
138nk_do_tooltip_delay_clicked(
struct nk_context* ctx,
const char* text,
struct nk_rect bounds,
float* timer, nk_bool* clicked)
141 if (nk_input_is_mouse_hovering_still_delay_clicked_rect(ctx, bounds, timer, ctx->style.window.tooltip_delay, clicked)) {
142 nk_tooltip_offset(ctx, text, ctx->style.window.tooltip_origin, ctx->style.window.tooltip_offset);
147nk_tooltip_offset(
struct nk_context *ctx,
const char *text,
enum nk_tooltip_pos position,
struct nk_vec2 offset)
157 NK_ASSERT(ctx->current);
158 NK_ASSERT(ctx->current->layout);
160 if (!ctx || !ctx->current || !ctx->current->layout || !text)
165 padding = style->window.padding;
168 text_len = nk_strlen(text);
169 text_width = style->font->
width(style->font->userdata,
170 style->font->
height, text, text_len);
171 text_width += (4 * padding.x);
172 text_height = (style->font->
height + 2 * padding.y);
175 if (nk_tooltip_begin_offset(ctx, (
float)text_width, position, offset)) {
176 nk_layout_row_dynamic(ctx, (
float)text_height, 1);
177 nk_text(ctx, text, text_len, NK_TEXT_LEFT);
183nk_tooltip(
struct nk_context *ctx,
const char *text)
186 nk_tooltip_offset(ctx, text, ctx->style.window.tooltip_origin, ctx->style.window.tooltip_offset);
188#ifdef NK_INCLUDE_STANDARD_VARARGS
190nk_tooltipf_offset(
struct nk_context *ctx,
enum nk_tooltip_pos position,
struct nk_vec2 offset,
const char *fmt, ...)
194 nk_tooltipfv_offset(ctx, position, offset, fmt, args);
198nk_tooltipf(
struct nk_context *ctx,
const char *fmt, ...)
202 nk_tooltipfv(ctx, fmt, args);
206nk_tooltipfv_offset(
struct nk_context *ctx,
enum nk_tooltip_pos position,
struct nk_vec2 offset,
const char *fmt, va_list args)
209 nk_strfmt(buf, NK_LEN(buf), fmt, args);
210 nk_tooltip_offset(ctx, buf, position, offset);
213nk_tooltipfv(
struct nk_context *ctx,
const char *fmt, va_list args)
216 nk_strfmt(buf, NK_LEN(buf), fmt, args);
217 nk_tooltip(ctx, buf);
nk_text_width_f width
!< max height of the font
float height
!< user provided font handle