Skip to content

Commit

Permalink
Merge branch 'AntiBlueQuirk-pr_valist'
Browse files Browse the repository at this point in the history
  • Loading branch information
vurtun committed Apr 6, 2018
2 parents d230b81 + 907db51 commit bca1520
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 28 deletions.
66 changes: 52 additions & 14 deletions nuklear.h
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,10 @@ extern "C" {
#endif
#if defined(__GNUC__)
#define NK_PRINTF_VARARG_FUNC(fmtargnumber) __attribute__((format(__printf__, fmtargnumber, fmtargnumber+1)))
#define NK_PRINTF_VALIST_FUNC(fmtargnumber) __attribute__((format(__printf__, fmtargnumber, 0)))
#else
#define NK_PRINTF_VARARG_FUNC(fmtargnumber)
#define NK_PRINTF_VALIST_FUNC(fmtargnumber)
#endif
#endif

Expand Down Expand Up @@ -3014,6 +3016,10 @@ NK_API void nk_labelf(struct nk_context*, nk_flags, NK_PRINTF_FORMAT_STRING cons
NK_API void nk_labelf_colored(struct nk_context*, nk_flags, struct nk_color, NK_PRINTF_FORMAT_STRING const char*,...) NK_PRINTF_VARARG_FUNC(4);
NK_API void nk_labelf_wrap(struct nk_context*, NK_PRINTF_FORMAT_STRING const char*,...) NK_PRINTF_VARARG_FUNC(2);
NK_API void nk_labelf_colored_wrap(struct nk_context*, struct nk_color, NK_PRINTF_FORMAT_STRING const char*,...) NK_PRINTF_VARARG_FUNC(3);
NK_API void nk_labelfv(struct nk_context*, nk_flags, NK_PRINTF_FORMAT_STRING const char*, va_list) NK_PRINTF_VALIST_FUNC(3);
NK_API void nk_labelfv_colored(struct nk_context*, nk_flags, struct nk_color, NK_PRINTF_FORMAT_STRING const char*, va_list) NK_PRINTF_VALIST_FUNC(4);
NK_API void nk_labelfv_wrap(struct nk_context*, NK_PRINTF_FORMAT_STRING const char*, va_list) NK_PRINTF_VALIST_FUNC(2);
NK_API void nk_labelfv_colored_wrap(struct nk_context*, struct nk_color, NK_PRINTF_FORMAT_STRING const char*, va_list) NK_PRINTF_VALIST_FUNC(3);
NK_API void nk_value_bool(struct nk_context*, const char *prefix, int);
NK_API void nk_value_int(struct nk_context*, const char *prefix, int);
NK_API void nk_value_uint(struct nk_context*, const char *prefix, unsigned int);
Expand Down Expand Up @@ -3430,7 +3436,8 @@ NK_API void nk_contextual_end(struct nk_context*);
* ============================================================================= */
NK_API void nk_tooltip(struct nk_context*, const char*);
#ifdef NK_INCLUDE_STANDARD_VARARGS
NK_API void nk_tooltipf(struct nk_context*, const char*, ...);
NK_API void nk_tooltipf(struct nk_context*, NK_PRINTF_FORMAT_STRING const char*, ...) NK_PRINTF_VARARG_FUNC(2);
NK_API void nk_tooltipfv(struct nk_context*, NK_PRINTF_FORMAT_STRING const char*, va_list) NK_PRINTF_VALIST_FUNC(2);
#endif
NK_API int nk_tooltip_begin(struct nk_context*, float width);
NK_API void nk_tooltip_end(struct nk_context*);
Expand Down Expand Up @@ -18981,44 +18988,70 @@ NK_API void
nk_labelf_colored(struct nk_context *ctx, nk_flags flags,
struct nk_color color, const char *fmt, ...)
{
char buf[256];
va_list args;
va_start(args, fmt);
nk_strfmt(buf, NK_LEN(buf), fmt, args);
nk_label_colored(ctx, buf, flags, color);
nk_labelfv_colored(ctx, flags, color, fmt, args);
va_end(args);
}
NK_API void
nk_labelf_colored_wrap(struct nk_context *ctx, struct nk_color color,
const char *fmt, ...)
{
char buf[256];
va_list args;
va_start(args, fmt);
nk_strfmt(buf, NK_LEN(buf), fmt, args);
nk_label_colored_wrap(ctx, buf, color);
nk_labelfv_colored_wrap(ctx, color, fmt, args);
va_end(args);
}
NK_API void
nk_labelf(struct nk_context *ctx, nk_flags flags, const char *fmt, ...)
{
char buf[256];
va_list args;
va_start(args, fmt);
nk_strfmt(buf, NK_LEN(buf), fmt, args);
nk_label(ctx, buf, flags);
nk_labelfv(ctx, flags, fmt, args);
va_end(args);
}
NK_API void
nk_labelf_wrap(struct nk_context *ctx, const char *fmt,...)
{
char buf[256];
va_list args;
va_start(args, fmt);
nk_labelfv_wrap(ctx, fmt, args);
va_end(args);
}
NK_API void
nk_labelfv_colored(struct nk_context *ctx, nk_flags flags,
struct nk_color color, const char *fmt, va_list args)
{
char buf[256];
nk_strfmt(buf, NK_LEN(buf), fmt, args);
nk_label_colored(ctx, buf, flags, color);
}

NK_API void
nk_labelfv_colored_wrap(struct nk_context *ctx, struct nk_color color,
const char *fmt, va_list args)
{
char buf[256];
nk_strfmt(buf, NK_LEN(buf), fmt, args);
nk_label_colored_wrap(ctx, buf, color);
}

NK_API void
nk_labelfv(struct nk_context *ctx, nk_flags flags, const char *fmt, va_list args)
{
char buf[256];
nk_strfmt(buf, NK_LEN(buf), fmt, args);
nk_label(ctx, buf, flags);
}

NK_API void
nk_labelfv_wrap(struct nk_context *ctx, const char *fmt, va_list args)
{
char buf[256];
nk_strfmt(buf, NK_LEN(buf), fmt, args);
nk_label_wrap(ctx, buf);
va_end(args);
}

NK_API void
nk_value_bool(struct nk_context *ctx, const char *prefix, int value)
{
Expand Down Expand Up @@ -24857,11 +24890,16 @@ nk_tooltip(struct nk_context *ctx, const char *text)
NK_API void
nk_tooltipf(struct nk_context *ctx, const char *fmt, ...)
{
char buf[256];
va_list args;
va_start(args, fmt);
nk_strfmt(buf, NK_LEN(buf), fmt, args);
nk_tooltipfv(ctx, fmt, args);
va_end(args);
}
NK_API void
nk_tooltipfv(struct nk_context *ctx, const char *fmt, va_list args)
{
char buf[256];
nk_strfmt(buf, NK_LEN(buf), fmt, args);
nk_tooltip(ctx, buf);
}
#endif
Expand Down
9 changes: 8 additions & 1 deletion src/nuklear.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,10 @@ extern "C" {
#endif
#if defined(__GNUC__)
#define NK_PRINTF_VARARG_FUNC(fmtargnumber) __attribute__((format(__printf__, fmtargnumber, fmtargnumber+1)))
#define NK_PRINTF_VALIST_FUNC(fmtargnumber) __attribute__((format(__printf__, fmtargnumber, 0)))
#else
#define NK_PRINTF_VARARG_FUNC(fmtargnumber)
#define NK_PRINTF_VALIST_FUNC(fmtargnumber)
#endif
#endif

Expand Down Expand Up @@ -2798,6 +2800,10 @@ NK_API void nk_labelf(struct nk_context*, nk_flags, NK_PRINTF_FORMAT_STRING cons
NK_API void nk_labelf_colored(struct nk_context*, nk_flags, struct nk_color, NK_PRINTF_FORMAT_STRING const char*,...) NK_PRINTF_VARARG_FUNC(4);
NK_API void nk_labelf_wrap(struct nk_context*, NK_PRINTF_FORMAT_STRING const char*,...) NK_PRINTF_VARARG_FUNC(2);
NK_API void nk_labelf_colored_wrap(struct nk_context*, struct nk_color, NK_PRINTF_FORMAT_STRING const char*,...) NK_PRINTF_VARARG_FUNC(3);
NK_API void nk_labelfv(struct nk_context*, nk_flags, NK_PRINTF_FORMAT_STRING const char*, va_list) NK_PRINTF_VALIST_FUNC(3);
NK_API void nk_labelfv_colored(struct nk_context*, nk_flags, struct nk_color, NK_PRINTF_FORMAT_STRING const char*, va_list) NK_PRINTF_VALIST_FUNC(4);
NK_API void nk_labelfv_wrap(struct nk_context*, NK_PRINTF_FORMAT_STRING const char*, va_list) NK_PRINTF_VALIST_FUNC(2);
NK_API void nk_labelfv_colored_wrap(struct nk_context*, struct nk_color, NK_PRINTF_FORMAT_STRING const char*, va_list) NK_PRINTF_VALIST_FUNC(3);
NK_API void nk_value_bool(struct nk_context*, const char *prefix, int);
NK_API void nk_value_int(struct nk_context*, const char *prefix, int);
NK_API void nk_value_uint(struct nk_context*, const char *prefix, unsigned int);
Expand Down Expand Up @@ -3214,7 +3220,8 @@ NK_API void nk_contextual_end(struct nk_context*);
* ============================================================================= */
NK_API void nk_tooltip(struct nk_context*, const char*);
#ifdef NK_INCLUDE_STANDARD_VARARGS
NK_API void nk_tooltipf(struct nk_context*, const char*, ...);
NK_API void nk_tooltipf(struct nk_context*, NK_PRINTF_FORMAT_STRING const char*, ...) NK_PRINTF_VARARG_FUNC(2);
NK_API void nk_tooltipfv(struct nk_context*, NK_PRINTF_FORMAT_STRING const char*, va_list) NK_PRINTF_VALIST_FUNC(2);
#endif
NK_API int nk_tooltip_begin(struct nk_context*, float width);
NK_API void nk_tooltip_end(struct nk_context*);
Expand Down
48 changes: 37 additions & 11 deletions src/nuklear_text.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,44 +150,70 @@ NK_API void
nk_labelf_colored(struct nk_context *ctx, nk_flags flags,
struct nk_color color, const char *fmt, ...)
{
char buf[256];
va_list args;
va_start(args, fmt);
nk_strfmt(buf, NK_LEN(buf), fmt, args);
nk_label_colored(ctx, buf, flags, color);
nk_labelfv_colored(ctx, flags, color, fmt, args);
va_end(args);
}
NK_API void
nk_labelf_colored_wrap(struct nk_context *ctx, struct nk_color color,
const char *fmt, ...)
{
char buf[256];
va_list args;
va_start(args, fmt);
nk_strfmt(buf, NK_LEN(buf), fmt, args);
nk_label_colored_wrap(ctx, buf, color);
nk_labelfv_colored_wrap(ctx, color, fmt, args);
va_end(args);
}
NK_API void
nk_labelf(struct nk_context *ctx, nk_flags flags, const char *fmt, ...)
{
char buf[256];
va_list args;
va_start(args, fmt);
nk_strfmt(buf, NK_LEN(buf), fmt, args);
nk_label(ctx, buf, flags);
nk_labelfv(ctx, flags, fmt, args);
va_end(args);
}
NK_API void
nk_labelf_wrap(struct nk_context *ctx, const char *fmt,...)
{
char buf[256];
va_list args;
va_start(args, fmt);
nk_labelfv_wrap(ctx, fmt, args);
va_end(args);
}
NK_API void
nk_labelfv_colored(struct nk_context *ctx, nk_flags flags,
struct nk_color color, const char *fmt, va_list args)
{
char buf[256];
nk_strfmt(buf, NK_LEN(buf), fmt, args);
nk_label_colored(ctx, buf, flags, color);
}

NK_API void
nk_labelfv_colored_wrap(struct nk_context *ctx, struct nk_color color,
const char *fmt, va_list args)
{
char buf[256];
nk_strfmt(buf, NK_LEN(buf), fmt, args);
nk_label_colored_wrap(ctx, buf, color);
}

NK_API void
nk_labelfv(struct nk_context *ctx, nk_flags flags, const char *fmt, va_list args)
{
char buf[256];
nk_strfmt(buf, NK_LEN(buf), fmt, args);
nk_label(ctx, buf, flags);
}

NK_API void
nk_labelfv_wrap(struct nk_context *ctx, const char *fmt, va_list args)
{
char buf[256];
nk_strfmt(buf, NK_LEN(buf), fmt, args);
nk_label_wrap(ctx, buf);
va_end(args);
}

NK_API void
nk_value_bool(struct nk_context *ctx, const char *prefix, int value)
{
Expand Down
9 changes: 7 additions & 2 deletions src/nuklear_tooltip.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,16 @@ nk_tooltip(struct nk_context *ctx, const char *text)
NK_API void
nk_tooltipf(struct nk_context *ctx, const char *fmt, ...)
{
char buf[256];
va_list args;
va_start(args, fmt);
nk_strfmt(buf, NK_LEN(buf), fmt, args);
nk_tooltipfv(ctx, fmt, args);
va_end(args);
}
NK_API void
nk_tooltipfv(struct nk_context *ctx, const char *fmt, va_list args)
{
char buf[256];
nk_strfmt(buf, NK_LEN(buf), fmt, args);
nk_tooltip(ctx, buf);
}
#endif
Expand Down

0 comments on commit bca1520

Please sign in to comment.