[ui, layout] Add UI_FLAG_ALLOW_OVERFLOW_X/Y

This commit is contained in:
Martin Fouilleul 2023-03-11 16:27:21 +01:00
parent c7d5cf113e
commit da7e0f402b
2 changed files with 44 additions and 32 deletions

View File

@ -915,6 +915,9 @@ void ui_styling_prepass(ui_context* ui, ui_box* box, list_info* before, list_inf
ui_style_rule_match(ui, box, rule, before, &tmpBefore);
}
//////////////////////////////////////////////////////////////////
//TODO: shouldn't this be reversed???
//////////////////////////////////////////////////////////////////
list_info tmpAfter = {0};
for_list(after, rule, ui_style_rule, buildElt)
{
@ -1059,6 +1062,7 @@ void ui_layout_upward_dependent_size(ui_context* ui, ui_box* box, int axis)
}
//NOTE: solve downard conflicts
int overflowFlag = (UI_FLAG_ALLOW_OVERFLOW_X << axis);
f32 sum = 0;
if(box->style.layout.axis == axis)
@ -1077,6 +1081,8 @@ void ui_layout_upward_dependent_size(ui_context* ui, ui_box* box, int axis)
}
}
if(!(box->flags & overflowFlag))
{
//NOTE: then remove excess proportionally to each box slack, and recompute children sum.
f32 totalContents = sum + box->spacing[axis] + 2*box->style.layout.margin.c[axis];
f32 excess = ClampLowBound(totalContents - box->rect.c[2+axis], 0);
@ -1090,6 +1096,7 @@ void ui_layout_upward_dependent_size(ui_context* ui, ui_box* box, int axis)
sum += child->rect.c[2+axis];
}
}
}
else
{
//NOTE: if we're solving on the secondary axis, we remove excess to each box individually
@ -1098,13 +1105,14 @@ void ui_layout_upward_dependent_size(ui_context* ui, ui_box* box, int axis)
for_list(&box->children, child, ui_box, listElt)
{
if(!ui_box_hidden(child) && !child->style.floating.c[axis])
{
if(!(box->flags & overflowFlag))
{
f32 totalContents = child->rect.c[2+axis] + 2*box->style.layout.margin.c[axis];
f32 excess = ClampLowBound(totalContents - box->rect.c[2+axis], 0);
f32 relax = child->style.size.c[axis].relax;
child->rect.c[2+axis] -= minimum(excess, child->rect.c[2+axis]*relax);
}
sum = maximum(sum, child->rect.c[2+axis]);
}
}

View File

@ -17,22 +17,6 @@
extern "C" {
#endif
typedef enum
{
UI_FLAG_CLICKABLE = (1<<0),
UI_FLAG_SCROLLABLE = (1<<1),
UI_FLAG_BLOCK_MOUSE = (1<<2),
UI_FLAG_HOT_ANIMATION = (1<<3),
UI_FLAG_ACTIVE_ANIMATION = (1<<4),
UI_FLAG_CLIP = (1<<5),
UI_FLAG_DRAW_BACKGROUND = (1<<6),
UI_FLAG_DRAW_FOREGROUND = (1<<7),
UI_FLAG_DRAW_BORDER = (1<<8),
UI_FLAG_DRAW_TEXT = (1<<9),
UI_FLAG_DRAW_RENDER_PROC = (1<<10),
} ui_flags;
typedef struct ui_key
{
u64 hash;
@ -271,6 +255,26 @@ typedef struct ui_sig
typedef void(*ui_box_render_proc)(ui_box* box, void* data);
typedef enum
{
UI_FLAG_CLICKABLE = (1<<0),
UI_FLAG_SCROLLABLE = (1<<1),
UI_FLAG_BLOCK_MOUSE = (1<<2),
UI_FLAG_HOT_ANIMATION = (1<<3),
UI_FLAG_ACTIVE_ANIMATION = (1<<4),
//WARN: these two following flags need to be kept as consecutive bits to
// play well with axis-agnostic functions
UI_FLAG_ALLOW_OVERFLOW_X = (1<<5),
UI_FLAG_ALLOW_OVERFLOW_Y = (1<<6),
UI_FLAG_CLIP = (1<<7),
UI_FLAG_DRAW_BACKGROUND = (1<<8),
UI_FLAG_DRAW_FOREGROUND = (1<<9),
UI_FLAG_DRAW_BORDER = (1<<10),
UI_FLAG_DRAW_TEXT = (1<<11),
UI_FLAG_DRAW_RENDER_PROC = (1<<12),
} ui_flags;
struct ui_box
{
// hierarchy