mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-10 15:22:04 +00:00
[ui] Add inactive labels and a style api
Labels are always good and the style api allows pushing/popping and modifying the current style.
This commit is contained in:
parent
b58c373f3e
commit
d4b11923b9
2 changed files with 56 additions and 0 deletions
|
@ -93,6 +93,12 @@ void IMUI_PopLayout (imui_ctx_t *ctx);
|
|||
void IMUI_Layout_SetXSize (imui_ctx_t *ctx, imui_size_t size, int value);
|
||||
void IMUI_Layout_SetYSize (imui_ctx_t *ctx, imui_size_t size, int value);
|
||||
|
||||
void IMUI_PushStyle (imui_ctx_t *ctx, const imui_style_t *style);
|
||||
void IMUI_PopStyle (imui_ctx_t *ctx);
|
||||
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);
|
||||
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);
|
||||
|
@ -102,11 +108,15 @@ void IMUI_FlexibleSpace (imui_ctx_t *ctx);
|
|||
|
||||
void IMUI_StartWindow (imui_ctx_t *ctx, imui_window_t *window);
|
||||
void IMUI_EndWindow (imui_ctx_t *ctx);
|
||||
|
||||
#define IMUI_DeferLoop(begin, end) \
|
||||
for (int _i_ = ((begin), 0); !_i_; _i_++, (end))
|
||||
|
||||
// #define IMUI_context to an imui_ctx_t * variable
|
||||
|
||||
#define UI_Label(label) \
|
||||
IMUI_Label(IMUI_context, label)
|
||||
|
||||
#define UI_Button(label) \
|
||||
IMUI_Button(IMUI_context, label)
|
||||
|
||||
|
@ -130,6 +140,10 @@ void IMUI_EndWindow (imui_ctx_t *ctx);
|
|||
IMUI_DeferLoop (IMUI_StartWindow (IMUI_context, window), \
|
||||
IMUI_EndWindow (IMUI_context))
|
||||
|
||||
#define UI_Style(style) \
|
||||
IMUI_DeferLoop (IMUI_PushStyle (IMUI_context, style), \
|
||||
IMUI_PopStyle (IMUI_context ))
|
||||
|
||||
#define UI_Horizontal UI_Layout(false)
|
||||
#define UI_Vertical UI_Layout(true)
|
||||
|
||||
|
|
|
@ -108,6 +108,7 @@ struct imui_ctx_s {
|
|||
int unicode;
|
||||
|
||||
imui_style_t style;
|
||||
struct DARRAY_TYPE(imui_style_t) style_stack;
|
||||
};
|
||||
|
||||
static imui_state_t *
|
||||
|
@ -185,6 +186,7 @@ IMUI_NewContext (canvas_system_t canvas_sys, const char *font, float fontsize)
|
|||
.hot = nullent,
|
||||
.active = nullent,
|
||||
.mouse_position = {-1, -1},
|
||||
.style_stack = DARRAY_STATIC_INIT (8),
|
||||
.style = {
|
||||
.background = {
|
||||
.normal = 0x04,
|
||||
|
@ -640,6 +642,33 @@ IMUI_Layout_SetYSize (imui_ctx_t *ctx, imui_size_t size, int value)
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
IMUI_PushStyle (imui_ctx_t *ctx, const imui_style_t *style)
|
||||
{
|
||||
DARRAY_APPEND (&ctx->style_stack, ctx->style);
|
||||
if (style) {
|
||||
ctx->style = *style;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
IMUI_PopStyle (imui_ctx_t *ctx)
|
||||
{
|
||||
ctx->style = DARRAY_REMOVE (&ctx->style_stack);
|
||||
}
|
||||
|
||||
void
|
||||
IMUI_Style_Update (imui_ctx_t *ctx, const imui_style_t *style)
|
||||
{
|
||||
ctx->style = *style;
|
||||
}
|
||||
|
||||
void
|
||||
IMUI_Style_Fetch (const imui_ctx_t *ctx, imui_style_t *style)
|
||||
{
|
||||
*style = ctx->style;
|
||||
}
|
||||
|
||||
static bool
|
||||
check_button_state (imui_ctx_t *ctx, uint32_t entity)
|
||||
{
|
||||
|
@ -752,6 +781,19 @@ set_expand_x (imui_ctx_t *ctx, view_t view, int weight)
|
|||
*(int *) Ent_AddComponent(view.id, c_percent_x, ctx->csys.reg) = weight;
|
||||
}
|
||||
|
||||
void
|
||||
IMUI_Label (imui_ctx_t *ctx, const char *label)
|
||||
{
|
||||
auto state = imui_get_state (ctx, label);
|
||||
|
||||
auto view = View_New (ctx->vsys, ctx->current_parent);
|
||||
state->entity = view.id;
|
||||
|
||||
set_control (ctx, view, true);
|
||||
set_fill (ctx, view, ctx->style.background.normal);
|
||||
add_text (ctx, view, state, 0);
|
||||
}
|
||||
|
||||
bool
|
||||
IMUI_Button (imui_ctx_t *ctx, const char *label)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue