[ui] Allow the parent layout rules to be modified

This makes it easy to control whether a window is a fixed size or fits
its children (or any other scheme, though those are the two most
likely).
This commit is contained in:
Bill Currie 2023-07-06 19:24:23 +09:00
parent 9b81ac1d38
commit 08cd03e632
3 changed files with 33 additions and 6 deletions

View file

@ -90,8 +90,8 @@ void IMUI_Draw (imui_ctx_t *ctx);
void IMUI_PushLayout (imui_ctx_t *ctx, bool vertical);
void IMUI_PopLayout (imui_ctx_t *ctx);
void IMUI_StartWindow (imui_ctx_t *ctx, imui_window_t *window);
void IMUI_EndWindow (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);
bool IMUI_Button (imui_ctx_t *ctx, const char *label);
bool IMUI_Checkbox (imui_ctx_t *ctx, bool *flag, const char *label);
@ -100,6 +100,8 @@ void IMUI_Slider (imui_ctx_t *ctx, float *value, float minval, float maxval,
const char *label);
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))

View file

@ -85,6 +85,8 @@ typedef struct viewcont_s {
unsigned flow_size:1; ///< If true, view's size is adjusted to flow.
unsigned semantic_x:3; ///< layout size control (IMUI_SizeKind)
unsigned semantic_y:3; ///< layout size control (IMUI_SizeKind)
unsigned free_x:1; ///< don't set position automatically
unsigned free_y:1; ///< don't set position automatically
unsigned vertical:1; ///< true: layout is vertical, else horizontal
unsigned active:1; ///< can respond to the mouse
} viewcont_t;

View file

@ -533,12 +533,11 @@ layout_objects (imui_ctx_t *ctx)
cur_parent = parent[i];
cpos = (view_pos_t) {};
}
if (cont[i].semantic_x != imui_size_none
&& cont[i].semantic_y != imui_size_none) {
if (!cont[i].free_x && !cont[i].free_y) {
pos[i] = cpos;
} else if (cont[i].semantic_x != imui_size_none) {
} else if (!cont[i].free_x) {
pos[i].x = cpos.x;
} else if (cont[i].semantic_y != imui_size_none) {
} else if (!cont[i].free_y) {
pos[i].y = cpos.y;
}
if (cont[parent[i]].vertical) {
@ -617,6 +616,28 @@ IMUI_PopLayout (imui_ctx_t *ctx)
ctx->current_parent = DARRAY_REMOVE (&ctx->parent_stack);
}
void
IMUI_Layout_SetXSize (imui_ctx_t *ctx, imui_size_t size, int value)
{
auto pcont = View_Control (ctx->current_parent);
uint32_t id = ctx->current_parent.id;
pcont->semantic_x = size;
if (size == imui_size_percent || imui_size_expand) {
*(int *) Ent_AddComponent(id, c_percent_x, ctx->csys.reg) = value;
}
}
void
IMUI_Layout_SetYSize (imui_ctx_t *ctx, imui_size_t size, int value)
{
auto pcont = View_Control (ctx->current_parent);
uint32_t id = ctx->current_parent.id;
pcont->semantic_y = size;
if (size == imui_size_percent || imui_size_expand) {
*(int *) Ent_AddComponent(id, c_percent_y, ctx->csys.reg) = value;
}
}
static bool
check_button_state (imui_ctx_t *ctx, uint32_t entity)
{
@ -863,6 +884,8 @@ IMUI_StartWindow (imui_ctx_t *ctx, imui_window_t *window)
.visible = 1,
.semantic_x = imui_size_none,
.semantic_y = imui_size_none,
.free_x = 1,
.free_y = 1,
.vertical = true,
.active = 1,
};