mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-23 04:42:32 +00:00
[ui] Add a formatted label (like printf)
Formatted printing is just too handy, and having to use va all the time is a bit of a pain.
This commit is contained in:
parent
a8b80c4be5
commit
f359f47e54
2 changed files with 20 additions and 0 deletions
|
@ -99,6 +99,7 @@ void IMUI_Style_Update (imui_ctx_t *ctx, const imui_style_t *style);
|
|||
void IMUI_Style_Fetch (const imui_ctx_t *ctx, imui_style_t *style);
|
||||
|
||||
void IMUI_Label (imui_ctx_t *ctx, const char *label);
|
||||
void IMUI_Labelf (imui_ctx_t *ctx, const char *fmt, ...)__attribute__((format(PRINTF,2,3)));
|
||||
bool IMUI_Button (imui_ctx_t *ctx, const char *label);
|
||||
bool IMUI_Checkbox (imui_ctx_t *ctx, bool *flag, const char *label);
|
||||
void IMUI_Radio (imui_ctx_t *ctx, int *curvalue, int value, const char *label);
|
||||
|
@ -117,6 +118,9 @@ void IMUI_EndWindow (imui_ctx_t *ctx);
|
|||
#define UI_Label(label) \
|
||||
IMUI_Label(IMUI_context, label)
|
||||
|
||||
#define UI_Labelf(fmt...) \
|
||||
IMUI_Labelf(IMUI_context, fmt)
|
||||
|
||||
#define UI_Button(label) \
|
||||
IMUI_Button(IMUI_context, label)
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
#include <string.h>
|
||||
|
||||
#include "QF/darray.h"
|
||||
#include "QF/dstring.h"
|
||||
#include "QF/ecs.h"
|
||||
#include "QF/hash.h"
|
||||
#include "QF/mathlib.h"
|
||||
|
@ -100,6 +101,8 @@ struct imui_ctx_s {
|
|||
view_t current_parent;
|
||||
struct DARRAY_TYPE(view_t) parent_stack;
|
||||
|
||||
dstring_t *dstr;
|
||||
|
||||
uint32_t hot;
|
||||
uint32_t active;
|
||||
view_pos_t mouse_active;
|
||||
|
@ -188,6 +191,7 @@ IMUI_NewContext (canvas_system_t canvas_sys, const char *font, float fontsize)
|
|||
.shaper = Shaper_New (),
|
||||
.root_view = Canvas_GetRootView (canvas_sys, canvas),
|
||||
.parent_stack = DARRAY_STATIC_INIT (8),
|
||||
.dstr = dstring_newstr (),
|
||||
.hot = nullent,
|
||||
.active = nullent,
|
||||
.mouse_position = {-1, -1},
|
||||
|
@ -237,6 +241,8 @@ IMUI_DestroyContext (imui_ctx_t *ctx)
|
|||
Font_Free (ctx->font);
|
||||
}
|
||||
|
||||
dstring_delete (ctx->dstr);
|
||||
|
||||
Hash_DelTable (ctx->tab);
|
||||
Hash_DelContext (ctx->hashctx);
|
||||
Shaper_Delete (ctx->shaper);
|
||||
|
@ -805,6 +811,16 @@ IMUI_Label (imui_ctx_t *ctx, const char *label)
|
|||
add_text (ctx, view, state, 0);
|
||||
}
|
||||
|
||||
void
|
||||
IMUI_Labelf (imui_ctx_t *ctx, const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start (args, fmt);
|
||||
dvsprintf (ctx->dstr, fmt, args);
|
||||
va_end (args);
|
||||
IMUI_Label (ctx, ctx->dstr->str);
|
||||
}
|
||||
|
||||
bool
|
||||
IMUI_Button (imui_ctx_t *ctx, const char *label)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue