Fix UI size calculation
This commit is contained in:
@@ -185,52 +185,57 @@ static void calculateAxisSizePreorder(const BzUI *ui, const BzUIAxis axis, BzUIN
|
||||
break;
|
||||
case BZ_UI_SIZE_NULL:
|
||||
default:
|
||||
break;
|
||||
return;
|
||||
}
|
||||
if (node->computedSize[axis] != compSize) {
|
||||
node->canInteract = true;
|
||||
node->canInteract = false;
|
||||
}
|
||||
node->computedSize[axis] = compSize;
|
||||
}
|
||||
static void calculateAxisSizePostorder(const BzUI *ui, const BzUIAxis axis, const BzUINode *node) {
|
||||
static void calculateAxisSizePostorder(const BzUI *ui, const BzUIAxis axis, BzUINode *node) {
|
||||
f32 compSize = 0;
|
||||
switch (node->semanticSize[axis].kind) {
|
||||
case BZ_UI_SIZE_CHILD_SUM:
|
||||
BZ_ASSERT(node->first);
|
||||
for (BzUINode *child = node->first; child; child = child->next) {
|
||||
compSize += child->computedSize[axis];
|
||||
compSize += child->computedSize[axis] + child->margin[axis] + child->margin[axis * 2];
|
||||
}
|
||||
break;
|
||||
case BZ_UI_SIZE_CHILD_MAX:
|
||||
BZ_ASSERT(node->first);
|
||||
for (BzUINode *child = node->first; child; child = child->next) {
|
||||
compSize = BZ_MAX(compSize, child->computedSize[axis]);
|
||||
f32 childSize = child->computedSize[axis] + child->margin[axis] + child->margin[axis * 2];
|
||||
compSize = BZ_MAX(compSize, childSize);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
return;
|
||||
}
|
||||
if (node->computedSize[axis] != compSize) {
|
||||
node->canInteract = false;
|
||||
node->computedSize[axis] = compSize;
|
||||
}
|
||||
}
|
||||
static void calculateSizes(const BzUI *ui, BzUINode *node) {
|
||||
BzUINode *child = node->first;
|
||||
|
||||
calculateAxisSizePreorder(ui, BZ_UI_AXIS_X, node);
|
||||
calculateAxisSizePreorder(ui, BZ_UI_AXIS_Y, node);
|
||||
while (child != NULL) {
|
||||
calculateSizes(ui, child);
|
||||
child = child->next;
|
||||
}
|
||||
calculateAxisSizePostorder(ui, BZ_UI_AXIS_X, node);
|
||||
calculateAxisSizePostorder(ui, BZ_UI_AXIS_Y, node);
|
||||
|
||||
node->computedSize[BZ_UI_AXIS_X] += node->padding[BZ_UI_AXIS_X] + node->padding[BZ_UI_AXIS_X + 2];
|
||||
node->computedSize[BZ_UI_AXIS_Y] += node->padding[BZ_UI_AXIS_Y] + node->padding[BZ_UI_AXIS_Y + 2];
|
||||
// Border thickness counts as margin
|
||||
if (node->flags & BZ_UI_DRAW_BORDER) {
|
||||
BzUIBorderStyle style = bzUIGetBorderStyle(ui, node);
|
||||
node->margin[BZ_UI_AXIS_X] += style.thickness * 2;
|
||||
node->margin[BZ_UI_AXIS_Y] += style.thickness * 2;
|
||||
}
|
||||
|
||||
calculateAxisSizePreorder(ui, BZ_UI_AXIS_X, node);
|
||||
calculateAxisSizePreorder(ui, BZ_UI_AXIS_Y, node);
|
||||
|
||||
node->computedSize[BZ_UI_AXIS_X] += node->padding[BZ_UI_AXIS_X] + node->padding[BZ_UI_AXIS_X + 2];
|
||||
node->computedSize[BZ_UI_AXIS_Y] += node->padding[BZ_UI_AXIS_Y] + node->padding[BZ_UI_AXIS_Y + 2];
|
||||
|
||||
for (BzUINode *child = node->first; child; child = child->next) {
|
||||
calculateSizes(ui, child);
|
||||
}
|
||||
|
||||
calculateAxisSizePostorder(ui, BZ_UI_AXIS_X, node);
|
||||
calculateAxisSizePostorder(ui, BZ_UI_AXIS_Y, node);
|
||||
}
|
||||
|
||||
static void calculatePositions(BzUI *ui, BzUINode *node, f32 x, f32 y);
|
||||
@@ -428,8 +433,11 @@ static void renderNode(BzUI *ui, BzUINode *node) {
|
||||
drawRect.x, drawRect.y
|
||||
}, style.fontSize, style.fontSpacing, color);
|
||||
}
|
||||
if (node->flags & BZ_UI_DRAW_DEBUG) {
|
||||
DrawRectangleLines(rect.x, rect.y, rect.width, rect.height, RED);
|
||||
}
|
||||
|
||||
node->canInteract = false;
|
||||
node->canInteract = true;
|
||||
|
||||
BzUINode *child = node->first;
|
||||
while (child != NULL) {
|
||||
|
||||
Reference in New Issue
Block a user