diff --git a/src/ui.c b/src/ui.c index a22e87e..6f4a79c 100644 --- a/src/ui.c +++ b/src/ui.c @@ -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,17 +1081,20 @@ void ui_layout_upward_dependent_size(ui_context* ui, ui_box* box, int axis) } } - //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); - f32 alpha = Clamp(excess / slack, 0, 1); - - sum = 0; - for_list(&box->children, child, ui_box, listElt) + if(!(box->flags & overflowFlag)) { - f32 relax = child->style.size.c[axis].relax; - child->rect.c[2+axis] -= alpha * child->rect.c[2+axis] * relax; - sum += child->rect.c[2+axis]; + //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); + f32 alpha = Clamp(excess / slack, 0, 1); + + sum = 0; + for_list(&box->children, child, ui_box, listElt) + { + f32 relax = child->style.size.c[axis].relax; + child->rect.c[2+axis] -= alpha * child->rect.c[2+axis] * relax; + sum += child->rect.c[2+axis]; + } } } else @@ -1099,12 +1106,13 @@ void ui_layout_upward_dependent_size(ui_context* ui, ui_box* box, int axis) { if(!ui_box_hidden(child) && !child->style.floating.c[axis]) { - 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); - + 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]); } } diff --git a/src/ui.h b/src/ui.h index fda363a..a2c466f 100644 --- a/src/ui.h +++ b/src/ui.h @@ -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