From 977ef87b92874364746740e7303b9a3a86a88d58 Mon Sep 17 00:00:00 2001 From: Michael Savage Date: Mon, 17 Feb 2025 21:06:17 +0000 Subject: [PATCH 1/3] [Core] Add a userData pointer to Clay_TextElementConfig --- clay.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/clay.h b/clay.h index 65d2854..73aa22a 100644 --- a/clay.h +++ b/clay.h @@ -360,6 +360,8 @@ typedef struct { // CLAY_TEXT_ALIGN_CENTER - Horizontally aligns wrapped lines of text to the center of their bounding box. // CLAY_TEXT_ALIGN_RIGHT - Horizontally aligns wrapped lines of text to the right hand side of their bounding box. Clay_TextAlignment textAlignment; + // A pointer that will be transparently passed through to the resulting render command. + void *userData; // When set to true, clay will hash the entire text contents of this string as an identifier for its internal // text measurement cache, rather than just the pointer and length. This will incur significant performance cost for // long bodies of text. @@ -2660,7 +2662,7 @@ void Clay__CalculateFinalLayout(void) { .letterSpacing = textElementConfig->letterSpacing, .lineHeight = textElementConfig->lineHeight, }}, - .userData = sharedConfig->userData, + .userData = textElementConfig->userData, .id = Clay__HashNumber(lineIndex, currentElement->id).id, .zIndex = root->zIndex, .commandType = CLAY_RENDER_COMMAND_TYPE_TEXT, From d60b491c293421a432099de9d3fb143ac584544b Mon Sep 17 00:00:00 2001 From: Nic Barker Date: Mon, 24 Feb 2025 09:00:09 +1300 Subject: [PATCH 2/3] Move userdata pointer to top of text element config --- clay.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clay.h b/clay.h index 73aa22a..d39ce86 100644 --- a/clay.h +++ b/clay.h @@ -339,6 +339,8 @@ typedef CLAY_PACKED_ENUM { // Controls various functionality related to text elements. typedef struct { + // A pointer that will be transparently passed through to the resulting render command. + void *userData; // The RGBA color of the font to render, conventionally specified as 0-255. Clay_Color textColor; // An integer transparently passed to Clay_MeasureText to identify the font to use. @@ -360,8 +362,6 @@ typedef struct { // CLAY_TEXT_ALIGN_CENTER - Horizontally aligns wrapped lines of text to the center of their bounding box. // CLAY_TEXT_ALIGN_RIGHT - Horizontally aligns wrapped lines of text to the right hand side of their bounding box. Clay_TextAlignment textAlignment; - // A pointer that will be transparently passed through to the resulting render command. - void *userData; // When set to true, clay will hash the entire text contents of this string as an identifier for its internal // text measurement cache, rather than just the pointer and length. This will incur significant performance cost for // long bodies of text. From 77be6d6ae399fd15875f9bd663ddee5a9386fbfc Mon Sep 17 00:00:00 2001 From: Nic Barker Date: Tue, 25 Feb 2025 08:54:20 +1300 Subject: [PATCH 3/3] [Core] Fix bug where hover state didnt take clip rectangles into account --- clay.h | 4 +++- examples/raylib-sidebar-scrolling-container/main.c | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/clay.h b/clay.h index d39ce86..c4e55d7 100644 --- a/clay.h +++ b/clay.h @@ -3650,11 +3650,13 @@ void Clay_SetPointerState(Clay_Vector2 position, bool isPointerDown) { context->treeNodeVisited.internalArray[dfsBuffer.length - 1] = true; Clay_LayoutElement *currentElement = Clay_LayoutElementArray_Get(&context->layoutElements, Clay__int32_tArray_GetValue(&dfsBuffer, (int)dfsBuffer.length - 1)); Clay_LayoutElementHashMapItem *mapItem = Clay__GetHashMapItem(currentElement->id); // TODO think of a way around this, maybe the fact that it's essentially a binary tree limits the cost, but the worst case is not great + int32_t clipElementId = Clay__int32_tArray_GetValue(&context->layoutElementClipElementIds, currentElement - context->layoutElements.internalArray); + Clay_LayoutElementHashMapItem *clipItem = Clay__GetHashMapItem(clipElementId); Clay_BoundingBox elementBox = mapItem->boundingBox; elementBox.x -= root->pointerOffset.x; elementBox.y -= root->pointerOffset.y; if (mapItem) { - if ((Clay__PointIsInsideRect(position, elementBox))) { + if ((Clay__PointIsInsideRect(position, elementBox)) && (clipElementId == 0 || (Clay__PointIsInsideRect(position, clipItem->boundingBox)))) { if (mapItem->onHoverFunction) { mapItem->onHoverFunction(mapItem->elementId, context->pointerInfo, mapItem->hoverFunctionUserData); } diff --git a/examples/raylib-sidebar-scrolling-container/main.c b/examples/raylib-sidebar-scrolling-container/main.c index a2f773b..4ea1cb7 100644 --- a/examples/raylib-sidebar-scrolling-container/main.c +++ b/examples/raylib-sidebar-scrolling-container/main.c @@ -80,7 +80,7 @@ Clay_RenderCommandArray CreateLayout(void) { CLAY_TEXT(CLAY_STRING("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt."), CLAY_TEXT_CONFIG({ .fontId = FONT_ID_BODY_24, .fontSize = 24, .textColor = {0,0,0,255} })); - CLAY({ .id = CLAY_ID("Photos2"), .layout = { .childGap = 16, .padding = { 16, 16, 16, 16 }}, .backgroundColor = {180, 180, 220, 255} }) { + CLAY({ .id = CLAY_ID("Photos2"), .layout = { .childGap = 16, .padding = { 16, 16, 16, 16 }}, .backgroundColor = {180, 180, 220, Clay_Hovered() ? 120 : 255} }) { CLAY({ .id = CLAY_ID("Picture4"), .layout = { .sizing = { .width = CLAY_SIZING_FIXED(120), .height = CLAY_SIZING_FIXED(120) }}, .image = { .imageData = &profilePicture, .sourceDimensions = {120, 120} }}) {} CLAY({ .id = CLAY_ID("Picture5"), .layout = { .sizing = { .width = CLAY_SIZING_FIXED(120), .height = CLAY_SIZING_FIXED(120) }}, .image = { .imageData = &profilePicture, .sourceDimensions = {120, 120} }}) {} CLAY({ .id = CLAY_ID("Picture6"), .layout = { .sizing = { .width = CLAY_SIZING_FIXED(120), .height = CLAY_SIZING_FIXED(120) }}, .image = { .imageData = &profilePicture, .sourceDimensions = {120, 120} }}) {}