mirror of
https://github.com/Ed94/raddebugger.git
synced 2026-08-06 22:08:41 +00:00
eliminate recursion from ui size calculation pass, replace with iterative equivalents
This commit is contained in:
+56
-77
@@ -1616,29 +1616,23 @@ internal void
|
|||||||
ui_calc_sizes_standalone__in_place_rec(UI_Box *root, Axis2 axis)
|
ui_calc_sizes_standalone__in_place_rec(UI_Box *root, Axis2 axis)
|
||||||
{
|
{
|
||||||
ProfBeginFunction();
|
ProfBeginFunction();
|
||||||
|
for(UI_Box *b = root; !ui_box_is_nil(b); b = ui_box_rec_df_pre(b, root).next)
|
||||||
switch(root->pref_size[axis].kind)
|
|
||||||
{
|
{
|
||||||
default:{}break;
|
switch(b->pref_size[axis].kind)
|
||||||
case UI_SizeKind_Pixels:
|
|
||||||
{
|
{
|
||||||
root->fixed_size.v[axis] = root->pref_size[axis].value;
|
default:{}break;
|
||||||
}break;
|
case UI_SizeKind_Pixels:
|
||||||
|
{
|
||||||
case UI_SizeKind_TextContent:
|
b->fixed_size.v[axis] = b->pref_size[axis].value;
|
||||||
{
|
}break;
|
||||||
F32 padding = root->pref_size[axis].value;
|
case UI_SizeKind_TextContent:
|
||||||
F32 text_size = root->display_fruns.dim.x;
|
{
|
||||||
root->fixed_size.v[axis] = padding + text_size + root->text_padding*2;
|
F32 padding = b->pref_size[axis].value;
|
||||||
}break;
|
F32 text_size = b->display_fruns.dim.x;
|
||||||
|
b->fixed_size.v[axis] = padding + text_size + b->text_padding*2;
|
||||||
|
}break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//- rjf: recurse
|
|
||||||
for(UI_Box *child = root->first; !ui_box_is_nil(child); child = child->next)
|
|
||||||
{
|
|
||||||
ui_calc_sizes_standalone__in_place_rec(child, axis);
|
|
||||||
}
|
|
||||||
|
|
||||||
ProfEnd();
|
ProfEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1646,43 +1640,35 @@ internal void
|
|||||||
ui_calc_sizes_upwards_dependent__in_place_rec(UI_Box *root, Axis2 axis)
|
ui_calc_sizes_upwards_dependent__in_place_rec(UI_Box *root, Axis2 axis)
|
||||||
{
|
{
|
||||||
ProfBeginFunction();
|
ProfBeginFunction();
|
||||||
|
for(UI_Box *b = root; !ui_box_is_nil(b); b = ui_box_rec_df_pre(b, root).next)
|
||||||
//- rjf: solve for all kinds that are upwards-dependent
|
|
||||||
switch(root->pref_size[axis].kind)
|
|
||||||
{
|
{
|
||||||
default: break;
|
switch(b->pref_size[axis].kind)
|
||||||
|
|
||||||
// rjf: if root has a parent percentage, figure out its size
|
|
||||||
case UI_SizeKind_ParentPct:
|
|
||||||
{
|
{
|
||||||
// rjf: find parent that has a fixed size
|
default:{}break;
|
||||||
UI_Box *fixed_parent = &ui_nil_box;
|
case UI_SizeKind_ParentPct:
|
||||||
for(UI_Box *p = root->parent; !ui_box_is_nil(p); p = p->parent)
|
|
||||||
{
|
{
|
||||||
if(p->flags & (UI_BoxFlag_FixedWidth<<axis) ||
|
// rjf: find parent that has a fixed size
|
||||||
p->pref_size[axis].kind == UI_SizeKind_Pixels ||
|
UI_Box *fixed_parent = &ui_nil_box;
|
||||||
p->pref_size[axis].kind == UI_SizeKind_TextContent ||
|
for(UI_Box *p = b->parent; !ui_box_is_nil(p); p = p->parent)
|
||||||
p->pref_size[axis].kind == UI_SizeKind_ParentPct)
|
|
||||||
{
|
{
|
||||||
fixed_parent = p;
|
if(p->flags & (UI_BoxFlag_FixedWidth<<axis) ||
|
||||||
break;
|
p->pref_size[axis].kind == UI_SizeKind_Pixels ||
|
||||||
|
p->pref_size[axis].kind == UI_SizeKind_TextContent ||
|
||||||
|
p->pref_size[axis].kind == UI_SizeKind_ParentPct)
|
||||||
|
{
|
||||||
|
fixed_parent = p;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// rjf: figure out root's size on this axis
|
// rjf: figure out box's size on this axis
|
||||||
F32 size = fixed_parent->fixed_size.v[axis] * root->pref_size[axis].value;
|
F32 size = fixed_parent->fixed_size.v[axis] * b->pref_size[axis].value;
|
||||||
|
|
||||||
// rjf: mutate root to have this size
|
// rjf: mutate box to have this size
|
||||||
root->fixed_size.v[axis] = size;
|
b->fixed_size.v[axis] = size;
|
||||||
}break;
|
}break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//- rjf: recurse
|
|
||||||
for(UI_Box *child = root->first; !ui_box_is_nil(child); child = child->next)
|
|
||||||
{
|
|
||||||
ui_calc_sizes_upwards_dependent__in_place_rec(child, axis);
|
|
||||||
}
|
|
||||||
|
|
||||||
ProfEnd();
|
ProfEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1690,43 +1676,36 @@ internal void
|
|||||||
ui_calc_sizes_downwards_dependent__in_place_rec(UI_Box *root, Axis2 axis)
|
ui_calc_sizes_downwards_dependent__in_place_rec(UI_Box *root, Axis2 axis)
|
||||||
{
|
{
|
||||||
ProfBeginFunction();
|
ProfBeginFunction();
|
||||||
|
UI_BoxRec rec = {0};
|
||||||
//- rjf: recurse first. we may depend on children that have
|
for(UI_Box *box = root; !ui_box_is_nil(box); box = rec.next)
|
||||||
// the same property
|
|
||||||
for(UI_Box *child = root->first; !ui_box_is_nil(child); child = child->next)
|
|
||||||
{
|
{
|
||||||
ui_calc_sizes_downwards_dependent__in_place_rec(child, axis);
|
rec = ui_box_rec_df_pre(box, root);
|
||||||
}
|
S32 pop_idx = 0;
|
||||||
|
for(UI_Box *b = box;
|
||||||
//- rjf: solve for all kinds that are downwards-dependent
|
!ui_box_is_nil(b) && pop_idx <= rec.pop_count;
|
||||||
switch(root->pref_size[axis].kind)
|
b = b->parent, pop_idx += 1)
|
||||||
{
|
|
||||||
default: break;
|
|
||||||
|
|
||||||
// rjf: sum children
|
|
||||||
case UI_SizeKind_ChildrenSum:
|
|
||||||
{
|
{
|
||||||
F32 sum = 0;
|
if(b->pref_size[axis].kind == UI_SizeKind_ChildrenSum)
|
||||||
for(UI_Box *child = root->first; !ui_box_is_nil(child); child = child->next)
|
|
||||||
{
|
{
|
||||||
if(!(child->flags & (UI_BoxFlag_FloatingX<<axis)))
|
F32 sum = 0;
|
||||||
|
for(UI_Box *child = b->first; !ui_box_is_nil(child); child = child->next)
|
||||||
{
|
{
|
||||||
if(axis == root->child_layout_axis)
|
if(!(child->flags & (UI_BoxFlag_FloatingX<<axis)))
|
||||||
{
|
{
|
||||||
sum += child->fixed_size.v[axis];
|
if(axis == b->child_layout_axis)
|
||||||
}
|
{
|
||||||
else
|
sum += child->fixed_size.v[axis];
|
||||||
{
|
}
|
||||||
sum = Max(sum, child->fixed_size.v[axis]);
|
else
|
||||||
|
{
|
||||||
|
sum = Max(sum, child->fixed_size.v[axis]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
b->fixed_size.v[axis] = sum;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// rjf: figure out root's size on this axis
|
|
||||||
root->fixed_size.v[axis] = sum;
|
|
||||||
}break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ProfEnd();
|
ProfEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user