From 983bd95f2d80e5bb89fb79d7b7e8f58901e6ae29 Mon Sep 17 00:00:00 2001 From: elmfrain Date: Sat, 5 Jul 2025 02:13:13 -0500 Subject: [PATCH 1/2] Fix Clay_Hovered() not working with floating elements --- clay.h | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/clay.h b/clay.h index f50abcd..b315734 100644 --- a/clay.h +++ b/clay.h @@ -1133,6 +1133,7 @@ typedef struct { Clay__LayoutElementChildren children; Clay__TextElementData *textElementData; } childrenOrTextContent; + uint16_t floatingChildrenCount; Clay_Dimensions dimensions; Clay_Dimensions minDimensions; Clay_LayoutConfig *layoutConfig; @@ -1755,7 +1756,8 @@ Clay_LayoutElementHashMapItem *Clay__GetHashMapItem(uint32_t id) { Clay_ElementId Clay__GenerateIdForAnonymousElement(Clay_LayoutElement *openLayoutElement) { Clay_Context* context = Clay_GetCurrentContext(); Clay_LayoutElement *parentElement = Clay_LayoutElementArray_Get(&context->layoutElements, Clay__int32_tArray_GetValue(&context->openLayoutElementStack, context->openLayoutElementStack.length - 2)); - Clay_ElementId elementId = Clay__HashNumber(parentElement->childrenOrTextContent.children.length, parentElement->id); + uint32_t offset = parentElement->childrenOrTextContent.children.length + parentElement->floatingChildrenCount; + Clay_ElementId elementId = Clay__HashNumber(offset, parentElement->id); openLayoutElement->id = elementId.id; Clay__AddHashMapItem(elementId, openLayoutElement, 0); Clay__StringArray_Add(&context->layoutElementIdStrings, elementId.stringId); @@ -1892,9 +1894,15 @@ void Clay__CloseElement(void) { // Close the currently open element int32_t closingElementIndex = Clay__int32_tArray_RemoveSwapback(&context->openLayoutElementStack, (int)context->openLayoutElementStack.length - 1); + + // Get the currently open parent openLayoutElement = Clay__GetOpenLayoutElement(); - if (!elementIsFloating && context->openLayoutElementStack.length > 1) { + if (context->openLayoutElementStack.length > 1) { + if(elementIsFloating) { + openLayoutElement->floatingChildrenCount++; + return; + } openLayoutElement->childrenOrTextContent.children.length++; Clay__int32_tArray_Add(&context->layoutElementChildrenBuffer, closingElementIndex); } @@ -4396,7 +4404,7 @@ void Clay_ResetMeasureTextCache(void) { context->measureTextHashMap.length = 0; context->measuredWords.length = 0; context->measuredWordsFreeList.length = 0; - + for (int32_t i = 0; i < context->measureTextHashMap.capacity; ++i) { context->measureTextHashMap.internalArray[i] = 0; } @@ -4430,3 +4438,4 @@ freely, subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ + From a9576fff82a98808f608a5ec77b5a1f3660011bd Mon Sep 17 00:00:00 2001 From: elmfrain Date: Sat, 5 Jul 2025 02:21:05 -0500 Subject: [PATCH 2/2] Fix changed whitespace --- clay.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/clay.h b/clay.h index b315734..fb1494f 100644 --- a/clay.h +++ b/clay.h @@ -4404,7 +4404,7 @@ void Clay_ResetMeasureTextCache(void) { context->measureTextHashMap.length = 0; context->measuredWords.length = 0; context->measuredWordsFreeList.length = 0; - + for (int32_t i = 0; i < context->measureTextHashMap.capacity; ++i) { context->measureTextHashMap.internalArray[i] = 0; } @@ -4438,4 +4438,3 @@ freely, subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -