make tree recurse without recursive functions
This commit is contained in:
parent
9f8e4aff59
commit
27f14e99c2
@ -446,73 +446,101 @@ DrawNodes(UIItem* item)
|
|||||||
void
|
void
|
||||||
CalcFixedSizes(UIItem* item)
|
CalcFixedSizes(UIItem* item)
|
||||||
{
|
{
|
||||||
if (!Nil(item))
|
for(UIItem* i = item; !Nil(i); i = Recurse(i))
|
||||||
{
|
{
|
||||||
static foreach(axis; A2D.min .. A2D.max)
|
static foreach(axis; A2D.min .. A2D.max)
|
||||||
{
|
{
|
||||||
if (item.size_info[axis].type == ST.Pixels)
|
if (i.size_info[axis].type == ST.Pixels)
|
||||||
{
|
{
|
||||||
item.size.v[axis] = item.size_info[axis].value + item.adjustment.v[axis];
|
i.size.v[axis] = i.size_info[axis].value + i.adjustment.v[axis];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CalcFixedSizes(item.first);
|
|
||||||
CalcFixedSizes(item.next);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
CalcPercentageSizes(UIItem* item)
|
CalcPercentageSizes(UIItem* item)
|
||||||
{
|
{
|
||||||
if (!Nil(item))
|
for(UIItem* i = item; !Nil(i); i = Recurse(i))
|
||||||
{
|
{
|
||||||
static foreach(axis; A2D.min .. A2D.max)
|
static foreach(axis; A2D.min .. A2D.max)
|
||||||
{
|
{
|
||||||
if (item.size_info[axis].type == ST.Percentage)
|
if (i.size_info[axis].type == ST.Percentage)
|
||||||
{
|
{
|
||||||
item.size.v[axis] = (item.parent.size.v[axis]*item.size_info[axis].value) + item.adjustment.v[axis];
|
i.size.v[axis] = (i.parent.size.v[axis]*i.size_info[axis].value) + i.adjustment.v[axis];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CalcPercentageSizes(item.first);
|
|
||||||
CalcPercentageSizes(item.next);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
CalcPositions(alias axis)(UIItem* item, f32 pos = 0.0)
|
CalcPositions(alias axis)(UIItem* item)
|
||||||
{
|
{
|
||||||
if (!Nil(item))
|
f32 pos = 0.0;
|
||||||
|
for(UIItem* i = item; !Nil(i);)
|
||||||
{
|
{
|
||||||
f32 end_pos = pos + item.size.v[axis];
|
f32 end_pos = pos + i.size.v[axis];
|
||||||
item.rect.vec0.v[axis] = pos;
|
i.rect.vec0.v[axis] = pos;
|
||||||
item.rect.vec1.v[axis] = end_pos;
|
i.rect.vec1.v[axis] = end_pos;
|
||||||
|
|
||||||
f32 next_pos = item.parent.layout_axis == axis ? end_pos : pos;
|
f32 next_pos = i.parent.layout_axis == axis ? end_pos : pos;
|
||||||
|
|
||||||
CalcPositions!(axis)(item.first, pos);
|
if (!Nil(i.first))
|
||||||
CalcPositions!(axis)(item.next, next_pos);
|
{
|
||||||
|
i = i.first;
|
||||||
|
}
|
||||||
|
else if (!Nil(i.next))
|
||||||
|
{
|
||||||
|
i = i.next;
|
||||||
|
pos = next_pos;
|
||||||
|
}
|
||||||
|
else if (!Nil(i.parent.next))
|
||||||
|
{
|
||||||
|
i = i.parent.next;
|
||||||
|
pos = i.parent.layout_axis == axis ? i.prev.rect.vec1.v[axis] : i.prev.rect.vec0.v[axis];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
DrawUI(UICtx* ctx, UIItem* item)
|
DrawUI(UICtx* ctx, UIItem* item)
|
||||||
{
|
{
|
||||||
if (!Nil(item))
|
for(UIItem* i = item; !Nil(i); i = Recurse(i))
|
||||||
{
|
{
|
||||||
if (item.flags & UIF.DrawBackground)
|
if (i.flags & UIF.DrawBackground)
|
||||||
{
|
{
|
||||||
DrawRect(ctx, item);
|
DrawRect(ctx, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item.flags & UIF.DrawText)
|
if (i.flags & UIF.DrawText)
|
||||||
{
|
{
|
||||||
DrawLine(item);
|
DrawLine(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DrawUI(ctx, item.first);
|
UIItem*
|
||||||
DrawUI(ctx, item.next);
|
Recurse(UIItem* item)
|
||||||
|
{
|
||||||
|
UIItem* result = g_UI_NIL;
|
||||||
|
if (!Nil(item.first))
|
||||||
|
{
|
||||||
|
result = item.first;
|
||||||
}
|
}
|
||||||
|
else if (!Nil(item.next))
|
||||||
|
{
|
||||||
|
result = item.next;
|
||||||
|
}
|
||||||
|
else if (!Nil(item.parent.next))
|
||||||
|
{
|
||||||
|
result = item.parent.next;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user