Add pointer capture mode to floating config

This commit is contained in:
Nic Barker 2024-12-21 06:01:59 +13:00
parent 44c2e0652e
commit 418579e376

15
clay.h
View File

@ -311,6 +311,12 @@ typedef struct
Clay_FloatingAttachPointType parent; Clay_FloatingAttachPointType parent;
} Clay_FloatingAttachPoints; } Clay_FloatingAttachPoints;
typedef enum {
CLAY_POINTER_CAPTURE_MODE_CAPTURE,
CLAY_POINTER_CAPTURE_MODE_PARENT,
CLAY_POINTER_CAPTURE_MODE_PASSTHROUGH,
} Clay_PointerCaptureMode;
typedef struct typedef struct
{ {
Clay_Vector2 offset; Clay_Vector2 offset;
@ -318,6 +324,7 @@ typedef struct
uint16_t zIndex; uint16_t zIndex;
uint32_t parentId; uint32_t parentId;
Clay_FloatingAttachPoints attachment; Clay_FloatingAttachPoints attachment;
Clay_PointerCaptureMode capturePointer;
} Clay_FloatingElementConfig; } Clay_FloatingElementConfig;
// Custom // Custom
@ -3518,6 +3525,7 @@ void Clay_SetPointerState(Clay_Vector2 position, bool isPointerDown) {
Clay__LayoutElementTreeRoot *root = Clay__LayoutElementTreeRootArray_Get(&Clay__layoutElementTreeRoots, rootIndex); Clay__LayoutElementTreeRoot *root = Clay__LayoutElementTreeRootArray_Get(&Clay__layoutElementTreeRoots, rootIndex);
Clay__int32_tArray_Add(&dfsBuffer, (int32_t)root->layoutElementIndex); Clay__int32_tArray_Add(&dfsBuffer, (int32_t)root->layoutElementIndex);
Clay__treeNodeVisited.internalArray[0] = false; Clay__treeNodeVisited.internalArray[0] = false;
bool found = false;
while (dfsBuffer.length > 0) { while (dfsBuffer.length > 0) {
if (Clay__treeNodeVisited.internalArray[dfsBuffer.length - 1]) { if (Clay__treeNodeVisited.internalArray[dfsBuffer.length - 1]) {
dfsBuffer.length--; dfsBuffer.length--;
@ -3535,6 +3543,7 @@ void Clay_SetPointerState(Clay_Vector2 position, bool isPointerDown) {
mapItem->onHoverFunction(mapItem->elementId, Clay__pointerInfo, mapItem->hoverFunctionUserData); mapItem->onHoverFunction(mapItem->elementId, Clay__pointerInfo, mapItem->hoverFunctionUserData);
} }
Clay__ElementIdArray_Add(&Clay__pointerOverIds, mapItem->elementId); Clay__ElementIdArray_Add(&Clay__pointerOverIds, mapItem->elementId);
found = true;
} }
if (Clay__ElementHasConfig(currentElement, CLAY__ELEMENT_CONFIG_TYPE_TEXT)) { if (Clay__ElementHasConfig(currentElement, CLAY__ELEMENT_CONFIG_TYPE_TEXT)) {
dfsBuffer.length--; dfsBuffer.length--;
@ -3548,6 +3557,12 @@ void Clay_SetPointerState(Clay_Vector2 position, bool isPointerDown) {
dfsBuffer.length--; dfsBuffer.length--;
} }
} }
Clay_LayoutElement *rootElement = Clay_LayoutElementArray_Get(&Clay__layoutElements, Clay__int32_tArray_Get(&dfsBuffer, (int)dfsBuffer.length - 1));
if (found && Clay__ElementHasConfig(rootElement, CLAY__ELEMENT_CONFIG_TYPE_FLOATING_CONTAINER) &&
Clay__FindElementConfigWithType(rootElement, CLAY__ELEMENT_CONFIG_TYPE_FLOATING_CONTAINER).floatingElementConfig->capturePointer == CLAY_POINTER_CAPTURE_MODE_CAPTURE) {
break;
}
} }
if (isPointerDown) { if (isPointerDown) {