Add bool Clay_GetElementHovered(Clay_ElementId)

This commit is contained in:
Iaroslav Erokhin 2025-03-05 08:31:24 +01:00
parent 5009146c65
commit 642eedaa30

15
clay.h
View File

@ -832,6 +832,8 @@ CLAY_DLL_EXPORT Clay_ElementData Clay_GetElementData(Clay_ElementId id);
// Returns true if the pointer position provided by Clay_SetPointerState is within the current element's bounding box. // Returns true if the pointer position provided by Clay_SetPointerState is within the current element's bounding box.
// Works during element declaration, e.g. CLAY({ .backgroundColor = Clay_Hovered() ? BLUE : RED }); // Works during element declaration, e.g. CLAY({ .backgroundColor = Clay_Hovered() ? BLUE : RED });
CLAY_DLL_EXPORT bool Clay_Hovered(void); CLAY_DLL_EXPORT bool Clay_Hovered(void);
// Returns true if an element with the specified id is found and if the pointer position provided by Clay_SetPointerState is within the element's bounding box.
CLAY_DLL_EXPORT bool Clay_GetElementHovered(Clay_ElementId elementId);
// Bind a callback that will be called when the pointer position provided by Clay_SetPointerState is within the current element's bounding box. // Bind a callback that will be called when the pointer position provided by Clay_SetPointerState is within the current element's bounding box.
// - onHoverFunction is a function pointer to a user defined function. // - onHoverFunction is a function pointer to a user defined function.
// - userData is a pointer that will be transparently passed through when the onHoverFunction is called. // - userData is a pointer that will be transparently passed through when the onHoverFunction is called.
@ -3960,6 +3962,19 @@ bool Clay_Hovered(void) {
return false; return false;
} }
bool Clay_GetElementHovered(Clay_ElementId elementId) {
Clay_Context* context = Clay_GetCurrentContext();
if (context->booleanWarnings.maxElementsExceeded) {
return false;
}
for (int32_t i = 0; i < context->pointerOverIds.length; ++i) {
if (Clay__ElementIdArray_Get(&context->pointerOverIds, i)->id == elementId.id) {
return true;
}
}
return false;
}
void Clay_OnHover(void (*onHoverFunction)(Clay_ElementId elementId, Clay_PointerData pointerInfo, intptr_t userData), intptr_t userData) { void Clay_OnHover(void (*onHoverFunction)(Clay_ElementId elementId, Clay_PointerData pointerInfo, intptr_t userData), intptr_t userData) {
Clay_Context* context = Clay_GetCurrentContext(); Clay_Context* context = Clay_GetCurrentContext();
if (context->booleanWarnings.maxElementsExceeded) { if (context->booleanWarnings.maxElementsExceeded) {