Skip to content

Commit

Permalink
Add numeric rounding to final bounding box output
Browse files Browse the repository at this point in the history
  • Loading branch information
nicbarker committed Oct 6, 2024
1 parent 51082d2 commit 843b5bf
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions clay.h
Original file line number Diff line number Diff line change
Expand Up @@ -1950,6 +1950,15 @@ void Clay__SizeContainersAlongAxis(bool xAxis) {
}
}

static inline Clay_BoundingBox Clay__BoundingBoxWithRoundedValues(float x, float y, float width, float height) {
return CLAY__INIT(Clay_BoundingBox) {
(int32_t)(x + (x > 0 ? 0.5f : -0.5f)),
(int32_t)(y + (y > 0 ? 0.5f : -0.5f)),
(int32_t)(width + (width > 0 ? 0.5f : -0.5f)),
(int32_t)(height + (height > 0 ? 0.5f : -0.5f))
};
}

void Clay__CalculateFinalLayout() {
// Calculate sizing along the X axis
Clay__SizeContainersAlongAxis(true);
Expand Down Expand Up @@ -2198,7 +2207,7 @@ void Clay__CalculateFinalLayout() {
if (!Clay__treeNodeVisited.internalArray[dfsBuffer.length - 1]) {
Clay__treeNodeVisited.internalArray[dfsBuffer.length - 1] = true;

Clay_BoundingBox currentElementBoundingBox = CLAY__INIT(Clay_BoundingBox) { currentElementTreeNode->position.x, currentElementTreeNode->position.y, currentElement->dimensions.width, currentElement->dimensions.height };
Clay_BoundingBox currentElementBoundingBox = Clay__BoundingBoxWithRoundedValues(currentElementTreeNode->position.x, currentElementTreeNode->position.y, currentElement->dimensions.width, currentElement->dimensions.height);
if (currentElement->elementType == CLAY__LAYOUT_ELEMENT_TYPE_FLOATING_CONTAINER) {
Clay_FloatingElementConfig *floatingElementConfig = currentElement->elementConfig.floatingElementConfig;
Clay_Dimensions expand = floatingElementConfig->expand;
Expand Down Expand Up @@ -2330,7 +2339,7 @@ void Clay__CalculateFinalLayout() {
});
// Borders between elements are expressed as additional rectangle render commands
} else if (currentElement->elementType == CLAY__LAYOUT_ELEMENT_TYPE_BORDER_CONTAINER) {
Clay_BoundingBox currentElementBoundingBox = CLAY__INIT(Clay_BoundingBox) { currentElementTreeNode->position.x, currentElementTreeNode->position.y, currentElement->dimensions.width, currentElement->dimensions.height };
Clay_BoundingBox currentElementBoundingBox = Clay__BoundingBoxWithRoundedValues(currentElementTreeNode->position.x, currentElementTreeNode->position.y, currentElement->dimensions.width, currentElement->dimensions.height);
#ifndef CLAY_DISABLE_CULLING
bool offscreen = currentElementBoundingBox.x > (float)Clay__layoutDimensions.width || currentElementBoundingBox.y > (float)Clay__layoutDimensions.height || currentElementBoundingBox.x + currentElementBoundingBox.width < 0 || currentElementBoundingBox.y + currentElementBoundingBox.height < 0;
if (offscreen) {
Expand Down

0 comments on commit 843b5bf

Please sign in to comment.