Allow floating configuration to capture pointer (#66)

This commit is contained in:
Nic Barker 2024-12-21 06:36:34 +13:00 committed by GitHub
parent b2dba60711
commit 712a79c473
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 39 additions and 8 deletions

View File

@ -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

View File

@ -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 {

Binary file not shown.

Binary file not shown.

Binary file not shown.

17
clay.h
View File

@ -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) {