From f8bdf01b45feed9d2b7b9a61c2d77e4c116d79c5 Mon Sep 17 00:00:00 2001 From: Nic Barker Date: Thu, 6 Mar 2025 09:36:24 +1300 Subject: [PATCH] Add tree depth to render commands --- clay.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/clay.h b/clay.h index ea17971..4fff245 100644 --- a/clay.h +++ b/clay.h @@ -666,6 +666,7 @@ typedef struct { // Note: the render command array is already sorted in ascending order, and will produce correct results if drawn in naive order. // This field is intended for use in batching renderers for improved performance. int16_t zIndex; + int16_t treeDepth; // Specifies how to handle rendering of this command. // CLAY_RENDER_COMMAND_TYPE_RECTANGLE - The renderer should draw a solid color rectangle. // CLAY_RENDER_COMMAND_TYPE_BORDER - The renderer should draw a colored border inset into the bounding box. @@ -1168,6 +1169,7 @@ typedef struct { Clay_LayoutElement *layoutElement; Clay_Vector2 position; Clay_Vector2 nextChildOffset; + uint16_t treeDepth; } Clay__LayoutElementTreeNode; CLAY__ARRAY_DEFINE(Clay__LayoutElementTreeNode, Clay__LayoutElementTreeNodeArray) @@ -2752,6 +2754,7 @@ void Clay__CalculateFinalLayout(void) { .boundingBox = currentElementBoundingBox, .userData = sharedConfig->userData, .id = currentElement->id, + .treeDepth = currentElementTreeNode->treeDepth, }; bool offscreen = Clay__ElementIsOffscreen(¤tElementBoundingBox); @@ -2824,6 +2827,7 @@ void Clay__CalculateFinalLayout(void) { .userData = textElementConfig->userData, .id = Clay__HashNumber(lineIndex, currentElement->id).id, .zIndex = root->zIndex, + .treeDepth = currentElementTreeNode->treeDepth, .commandType = CLAY_RENDER_COMMAND_TYPE_TEXT, }); yPosition += finalLineHeight; @@ -2868,6 +2872,7 @@ void Clay__CalculateFinalLayout(void) { .userData = sharedConfig->userData, .id = currentElement->id, .zIndex = root->zIndex, + .treeDepth = currentElementTreeNode->treeDepth, .commandType = CLAY_RENDER_COMMAND_TYPE_RECTANGLE, }); } @@ -2946,6 +2951,7 @@ void Clay__CalculateFinalLayout(void) { }}, .userData = sharedConfig->userData, .id = Clay__HashNumber(currentElement->id, currentElement->childrenOrTextContent.children.length).id, + .treeDepth = currentElementTreeNode->treeDepth, .commandType = CLAY_RENDER_COMMAND_TYPE_BORDER, }; Clay__AddRenderCommand(renderCommand); @@ -2963,6 +2969,7 @@ void Clay__CalculateFinalLayout(void) { } }, .userData = sharedConfig->userData, .id = Clay__HashNumber(currentElement->id, currentElement->childrenOrTextContent.children.length + 1 + i).id, + .treeDepth = currentElementTreeNode->treeDepth, .commandType = CLAY_RENDER_COMMAND_TYPE_RECTANGLE, }); } @@ -2979,6 +2986,7 @@ void Clay__CalculateFinalLayout(void) { } }, .userData = sharedConfig->userData, .id = Clay__HashNumber(currentElement->id, currentElement->childrenOrTextContent.children.length + 1 + i).id, + .treeDepth = currentElementTreeNode->treeDepth, .commandType = CLAY_RENDER_COMMAND_TYPE_RECTANGLE, }); } @@ -3035,6 +3043,7 @@ void Clay__CalculateFinalLayout(void) { .layoutElement = childElement, .position = { childPosition.x, childPosition.y }, .nextChildOffset = { .x = (float)childElement->layoutConfig->padding.left, .y = (float)childElement->layoutConfig->padding.top }, + .treeDepth = currentElementTreeNode->treeDepth + 1 }; context->treeNodeVisited.internalArray[newNodeIndex] = false;