From cbfa75e310abdb2e7e8c3c40a9575b1bb76593f7 Mon Sep 17 00:00:00 2001 From: Hailey Date: Thu, 26 Dec 2024 08:31:30 -0600 Subject: [PATCH] [Core] Access bounding boxes of scrolling containers --- clay.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/clay.h b/clay.h index 48b5e32..7a71195 100644 --- a/clay.h +++ b/clay.h @@ -393,6 +393,14 @@ typedef struct bool found; } Clay_ScrollContainerData; +typedef struct +{ + Clay_BoundingBox elementLocation; + + // Indicates whether an actual Element matched the provided ID or if the default struct was returned. + bool found; +} Clay_ElementLocationData; + typedef enum { CLAY_RENDER_COMMAND_TYPE_NONE, CLAY_RENDER_COMMAND_TYPE_RECTANGLE, @@ -479,6 +487,7 @@ void Clay_SetDebugModeEnabled(bool enabled); void Clay_SetCullingEnabled(bool enabled); void Clay_SetMaxElementCount(uint32_t maxElementCount); void Clay_SetMaxMeasureTextCacheWordCount(uint32_t maxMeasureTextCacheWordCount); +Clay_ElementLocationData Clay_GetElementLocationData (Clay_ElementId id); // Internal API functions required by macros void Clay__OpenElement(); @@ -3811,6 +3820,22 @@ Clay_ScrollContainerData Clay_GetScrollContainerData(Clay_ElementId id) { return CLAY__INIT(Clay_ScrollContainerData) {}; } +CLAY_WASM_EXPORT("Clay_GetElementLocationData") +Clay_ElementLocationData Clay_GetElementLocationData(Clay_ElementId id){ + Clay_LayoutElementHashMapItem * item =Clay__GetHashMapItem(id.id); + if(item == &CLAY__LAYOUT_ELEMENT_HASH_MAP_ITEM_DEFAULT) { + return CLAY__INIT(Clay_ElementLocationData){ + .found=false, + .elementLocation=CLAY__INIT(Clay_BoundingBox){} + }; + } + + return CLAY__INIT(Clay_ElementLocationData){ + .elementLocation=item->boundingBox, + .found = true + }; +} + CLAY_WASM_EXPORT("Clay_SetDebugModeEnabled") void Clay_SetDebugModeEnabled(bool enabled) { Clay__debugModeEnabled = enabled;