diff --git a/README.md b/README.md index f730da5..eedf305 100644 --- a/README.md +++ b/README.md @@ -1234,11 +1234,11 @@ Rendering of borders and rounded corners is left up to the user. See the provide ### CLAY_FLOATING **Usage** -`CLAY_FLOATING(Clay_ElementId id, Clay_LayoutConfig *layoutConfig, Clay_FloatingElementConfig *floatingConfig);` +`CLAY(CLAY_FLOATING(...floating config)) {}` **Lifecycle** -`Clay_BeginLayout()` -> `CLAY_FLOATING()` -> `Clay_EndLayout()` +`Clay_BeginLayout()` -> `CLAY(` -> `CLAY_FLOATING()` -> `)` -> `Clay_EndLayout()` **Notes** @@ -1272,6 +1272,10 @@ Clay_FloatingElementConfig { .element = CLAY_ATTACH_POINT_LEFT_TOP (default) | CLAY_ATTACH_POINT_LEFT_CENTER | CLAY_ATTACH_POINT_LEFT_BOTTOM | CLAY_ATTACH_POINT_CENTER_TOP | CLAY_ATTACH_POINT_CENTER_CENTER | CLAY_ATTACH_POINT_CENTER_BOTTOM | CLAY_ATTACH_POINT_RIGHT_TOP | CLAY_ATTACH_POINT_RIGHT_CENTER | CLAY_ATTACH_POINT_RIGHT_BOTTOM .parent = CLAY_ATTACH_POINT_LEFT_TOP (default) | CLAY_ATTACH_POINT_LEFT_CENTER | CLAY_ATTACH_POINT_LEFT_BOTTOM | CLAY_ATTACH_POINT_CENTER_TOP | CLAY_ATTACH_POINT_CENTER_CENTER | CLAY_ATTACH_POINT_CENTER_BOTTOM | CLAY_ATTACH_POINT_RIGHT_TOP | CLAY_ATTACH_POINT_RIGHT_CENTER | CLAY_ATTACH_POINT_RIGHT_BOTTOM }; + Clay_PointerCaptureMode captureMode { + CLAY_POINTER_CAPTURE_MODE_CAPTURE (default), + CLAY_POINTER_CAPTURE_MODE_PASSTHROUGH + }; }; ``` @@ -1393,6 +1397,12 @@ For example: ![Screenshot 2024-08-23 at 11 53 24 AM](https://github.com/user-attachments/assets/ebe75e0d-1904-46b0-982d-418f929d1516) +**`.pointerCaptureMode`** - `Clay_PointerCaptureMode` + +`CLAY_FLOATING({ .pointerCaptureMode = CLAY_POINTER_CAPTURE_MODE_CAPTURE })` + +Controls whether pointer events like hover and click should pass through to content underneath this floating element, or whether the pointer should be "captured" by this floating element. Defaults to `CLAY_POINTER_CAPTURE_MODE_CAPTURE`. + **Examples** ```C diff --git a/bindings/odin/clay-odin/clay.odin b/bindings/odin/clay-odin/clay.odin index 7d114c3..fbc2c1b 100644 --- a/bindings/odin/clay-odin/clay.odin +++ b/bindings/odin/clay-odin/clay.odin @@ -154,12 +154,18 @@ FloatingAttachPoints :: struct { parent: FloatingAttachPointType, } +PointerCaptureMode :: enum EnumBackingType { + CAPTURE, + PASSTHROUGH, +} + FloatingElementConfig :: struct { - offset: Vector2, - expand: Dimensions, - zIndex: u16, - parentId: u32, - attachment: FloatingAttachPoints, + offset: Vector2, + expand: Dimensions, + zIndex: u16, + parentId: u32, + attachment: FloatingAttachPoints, + pointerCaptureMode: PointerCaptureMode, } ElementConfigUnion :: struct #raw_union { diff --git a/bindings/odin/clay-odin/linux/clay.a b/bindings/odin/clay-odin/linux/clay.a index 0789fdf..b32b0cd 100644 Binary files a/bindings/odin/clay-odin/linux/clay.a and b/bindings/odin/clay-odin/linux/clay.a differ diff --git a/bindings/odin/clay-odin/macos-arm64/clay.a b/bindings/odin/clay-odin/macos-arm64/clay.a index 0c6d92d..688da27 100644 Binary files a/bindings/odin/clay-odin/macos-arm64/clay.a and b/bindings/odin/clay-odin/macos-arm64/clay.a differ diff --git a/bindings/odin/clay-odin/macos/clay.a b/bindings/odin/clay-odin/macos/clay.a index b9a2332..bd986b5 100644 Binary files a/bindings/odin/clay-odin/macos/clay.a and b/bindings/odin/clay-odin/macos/clay.a differ diff --git a/bindings/odin/clay-odin/wasm/clay.o b/bindings/odin/clay-odin/wasm/clay.o index 8cb648e..79193c6 100644 Binary files a/bindings/odin/clay-odin/wasm/clay.o and b/bindings/odin/clay-odin/wasm/clay.o differ diff --git a/bindings/odin/clay-odin/windows/clay.lib b/bindings/odin/clay-odin/windows/clay.lib index 9f8a31d..883b47a 100644 Binary files a/bindings/odin/clay-odin/windows/clay.lib and b/bindings/odin/clay-odin/windows/clay.lib differ diff --git a/clay.h b/clay.h index 8567c54..b486669 100644 --- a/clay.h +++ b/clay.h @@ -314,6 +314,12 @@ typedef struct Clay_FloatingAttachPointType parent; } Clay_FloatingAttachPoints; +typedef enum { + CLAY_POINTER_CAPTURE_MODE_CAPTURE, +// CLAY_POINTER_CAPTURE_MODE_PARENT, TODO pass pointer through to attached parent + CLAY_POINTER_CAPTURE_MODE_PASSTHROUGH, +} Clay_PointerCaptureMode; + typedef struct { Clay_Vector2 offset; @@ -321,6 +327,7 @@ typedef struct uint16_t zIndex; uint32_t parentId; Clay_FloatingAttachPoints attachment; + Clay_PointerCaptureMode pointerCaptureMode; } Clay_FloatingElementConfig; // Custom @@ -3513,11 +3520,12 @@ void Clay_SetPointerState(Clay_Vector2 position, bool isPointerDown) { Clay__pointerInfo.position = position; Clay__pointerOverIds.length = 0; Clay__int32_tArray dfsBuffer = Clay__layoutElementChildrenBuffer; - for (int rootIndex = 0; rootIndex < Clay__layoutElementTreeRoots.length; ++rootIndex) { + for (int rootIndex = Clay__layoutElementTreeRoots.length - 1; rootIndex >= 0; --rootIndex) { dfsBuffer.length = 0; Clay__LayoutElementTreeRoot *root = Clay__LayoutElementTreeRootArray_Get(&Clay__layoutElementTreeRoots, rootIndex); Clay__int32_tArray_Add(&dfsBuffer, (int32_t)root->layoutElementIndex); Clay__treeNodeVisited.internalArray[0] = false; + bool found = false; while (dfsBuffer.length > 0) { if (Clay__treeNodeVisited.internalArray[dfsBuffer.length - 1]) { dfsBuffer.length--; @@ -3535,6 +3543,7 @@ void Clay_SetPointerState(Clay_Vector2 position, bool isPointerDown) { mapItem->onHoverFunction(mapItem->elementId, Clay__pointerInfo, mapItem->hoverFunctionUserData); } Clay__ElementIdArray_Add(&Clay__pointerOverIds, mapItem->elementId); + found = true; } if (Clay__ElementHasConfig(currentElement, CLAY__ELEMENT_CONFIG_TYPE_TEXT)) { dfsBuffer.length--; @@ -3548,6 +3557,12 @@ void Clay_SetPointerState(Clay_Vector2 position, bool isPointerDown) { dfsBuffer.length--; } } + + Clay_LayoutElement *rootElement = Clay_LayoutElementArray_Get(&Clay__layoutElements, root->layoutElementIndex); + if (found && Clay__ElementHasConfig(rootElement, CLAY__ELEMENT_CONFIG_TYPE_FLOATING_CONTAINER) && + Clay__FindElementConfigWithType(rootElement, CLAY__ELEMENT_CONFIG_TYPE_FLOATING_CONTAINER).floatingElementConfig->pointerCaptureMode == CLAY_POINTER_CAPTURE_MODE_CAPTURE) { + break; + } } if (isPointerDown) {