Skip to content

Commit 29e834c

Browse files
committed
Add examples to overview, fix vararg versions
1 parent 43de49a commit 29e834c

4 files changed

Lines changed: 56 additions & 3 deletions

File tree

demo/common/overview.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -842,9 +842,28 @@ overview(struct nk_context *ctx)
842842
/* tooltip */
843843
nk_layout_row_static(ctx, 30, 150, 1);
844844
bounds = nk_widget_bounds(ctx);
845-
nk_label(ctx, "Hover me for tooltip", NK_TEXT_LEFT);
846-
if (nk_input_is_mouse_hovering_rect(in, bounds))
847-
nk_tooltip_positioned(ctx, "This is a tooltip", NK_BOTTOM_LEFT);
845+
nk_label(ctx, "Hover for tooltip", NK_TEXT_LEFT);
846+
if (nk_input_is_mouse_hovering_rect(in, bounds)) {
847+
nk_tooltip(ctx, "This is a default tooltip");
848+
}
849+
bounds = nk_widget_bounds(ctx);
850+
nk_label(ctx, "Chrome-like tooltip", NK_TEXT_LEFT);
851+
if (nk_input_is_mouse_hovering_rect(in, bounds)) {
852+
struct nk_vec2 offset = { 8, 8 };
853+
nk_tooltip_pos_offset(ctx, "Chrome offsets just a bit", NK_TOP_LEFT, offset);
854+
}
855+
bounds = nk_widget_bounds(ctx);
856+
nk_label(ctx, "Gnome-like tooltip", NK_TEXT_LEFT);
857+
if (nk_input_is_mouse_hovering_rect(in, bounds)) {
858+
struct nk_vec2 offset = { 0, -15 };
859+
nk_tooltip_pos_offset(ctx, "Gnome centers with greater y offset", NK_BOTTOM_MIDDLE, offset);
860+
}
861+
bounds = nk_widget_bounds(ctx);
862+
nk_label(ctx, "Bottom left tooltip", NK_TEXT_LEFT);
863+
if (nk_input_is_mouse_hovering_rect(in, bounds)) {
864+
struct nk_vec2 offset = { 0, 0 };
865+
nk_tooltip_pos_offset(ctx, "Bottom left positioning", NK_BOTTOM_LEFT, offset);
866+
}
848867

849868
nk_tree_pop(ctx);
850869
}

nuklear.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3832,6 +3832,8 @@ NK_API void nk_tooltip_pos_offset(struct nk_context *ctx, const char *text, enum
38323832
#ifdef NK_INCLUDE_STANDARD_VARARGS
38333833
NK_API void nk_tooltipf(struct nk_context*, NK_PRINTF_FORMAT_STRING const char*, ...) NK_PRINTF_VARARG_FUNC(2);
38343834
NK_API void nk_tooltipfv(struct nk_context*, NK_PRINTF_FORMAT_STRING const char*, va_list) NK_PRINTF_VALIST_FUNC(2);
3835+
NK_API void nk_tooltipf_pos_offset(struct nk_context*, enum nk_tooltip_pos, struct nk_vec2, NK_PRINTF_FORMAT_STRING const char*, ...) NK_PRINTF_VARARG_FUNC(4);
3836+
NK_API void nk_tooltipfv_pos_offset(struct nk_context*, enum nk_tooltip_pos, struct nk_vec2, NK_PRINTF_FORMAT_STRING const char*, va_list) NK_PRINTF_VALIST_FUNC(4);
38353837
#endif
38363838
NK_API nk_bool nk_tooltip_begin(struct nk_context*, float width);
38373839
NK_API nk_bool nk_tooltip_begin_pos_offset(struct nk_context*, float, enum nk_tooltip_pos, struct nk_vec2);
@@ -30765,6 +30767,14 @@ nk_tooltip(struct nk_context *ctx, const char *text)
3076530767
}
3076630768
#ifdef NK_INCLUDE_STANDARD_VARARGS
3076730769
NK_API void
30770+
nk_tooltipf_pos_offset(struct nk_context *ctx, enum nk_tooltip_pos position, struct nk_vec2 offset, const char *fmt, ...)
30771+
{
30772+
va_list args;
30773+
va_start(args, fmt);
30774+
nk_tooltipfv_pos_offset(ctx, position, offset, fmt, args);
30775+
va_end(args);
30776+
}
30777+
NK_API void
3076830778
nk_tooltipf(struct nk_context *ctx, const char *fmt, ...)
3076930779
{
3077030780
va_list args;
@@ -30773,6 +30783,13 @@ nk_tooltipf(struct nk_context *ctx, const char *fmt, ...)
3077330783
va_end(args);
3077430784
}
3077530785
NK_API void
30786+
nk_tooltipfv_pos_offset(struct nk_context *ctx, enum nk_tooltip_pos position, struct nk_vec2 offset, const char *fmt, va_list args)
30787+
{
30788+
char buf[256];
30789+
nk_strfmt(buf, NK_LEN(buf), fmt, args);
30790+
nk_tooltip_pos_offset(ctx, buf, position, offset);
30791+
}
30792+
NK_API void
3077630793
nk_tooltipfv(struct nk_context *ctx, const char *fmt, va_list args)
3077730794
{
3077830795
char buf[256];

src/nuklear.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3609,6 +3609,8 @@ NK_API void nk_tooltip_pos_offset(struct nk_context *ctx, const char *text, enum
36093609
#ifdef NK_INCLUDE_STANDARD_VARARGS
36103610
NK_API void nk_tooltipf(struct nk_context*, NK_PRINTF_FORMAT_STRING const char*, ...) NK_PRINTF_VARARG_FUNC(2);
36113611
NK_API void nk_tooltipfv(struct nk_context*, NK_PRINTF_FORMAT_STRING const char*, va_list) NK_PRINTF_VALIST_FUNC(2);
3612+
NK_API void nk_tooltipf_pos_offset(struct nk_context*, enum nk_tooltip_pos, struct nk_vec2, NK_PRINTF_FORMAT_STRING const char*, ...) NK_PRINTF_VARARG_FUNC(4);
3613+
NK_API void nk_tooltipfv_pos_offset(struct nk_context*, enum nk_tooltip_pos, struct nk_vec2, NK_PRINTF_FORMAT_STRING const char*, va_list) NK_PRINTF_VALIST_FUNC(4);
36123614
#endif
36133615
NK_API nk_bool nk_tooltip_begin(struct nk_context*, float width);
36143616
NK_API nk_bool nk_tooltip_begin_pos_offset(struct nk_context*, float, enum nk_tooltip_pos, struct nk_vec2);

src/nuklear_tooltip.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,14 @@ nk_tooltip(struct nk_context *ctx, const char *text)
165165
}
166166
#ifdef NK_INCLUDE_STANDARD_VARARGS
167167
NK_API void
168+
nk_tooltipf_pos_offset(struct nk_context *ctx, enum nk_tooltip_pos position, struct nk_vec2 offset, const char *fmt, ...)
169+
{
170+
va_list args;
171+
va_start(args, fmt);
172+
nk_tooltipfv_pos_offset(ctx, position, offset, fmt, args);
173+
va_end(args);
174+
}
175+
NK_API void
168176
nk_tooltipf(struct nk_context *ctx, const char *fmt, ...)
169177
{
170178
va_list args;
@@ -173,6 +181,13 @@ nk_tooltipf(struct nk_context *ctx, const char *fmt, ...)
173181
va_end(args);
174182
}
175183
NK_API void
184+
nk_tooltipfv_pos_offset(struct nk_context *ctx, enum nk_tooltip_pos position, struct nk_vec2 offset, const char *fmt, va_list args)
185+
{
186+
char buf[256];
187+
nk_strfmt(buf, NK_LEN(buf), fmt, args);
188+
nk_tooltip_pos_offset(ctx, buf, position, offset);
189+
}
190+
NK_API void
176191
nk_tooltipfv(struct nk_context *ctx, const char *fmt, va_list args)
177192
{
178193
char buf[256];

0 commit comments

Comments
 (0)