Interaction
Ask about pointer state by element id. CC_Hovered is true while the mouse is over an element and CC_Clicked is true on the frame it is clicked. CC_ElementDataOf returns an element's position and size. All of them read the previous frame's layout, so a query can come before or after the element it names.
Example
static int count;
static void counter(void) {
if (CC_Clicked("Add")) count++;
Button("Add", .layout = { .padding = PadAll(12) },
.backgroundColor = CC_Hovered("Add") ? ColorHex(0x3A7BEF)
: ColorHex(0x2D6CDF)) {
Text("Add one");
}
CC_ElementData add = CC_ElementDataOf("Add");
if (add.found)
printf("button is %.0f px wide\n", add.boundingBox.width);
}
Reference
| Name | Form | What it does | Page |
|---|---|---|---|
CC_Hovered | bool CC_Hovered("id") | True while the pointer is over the element. Uses the previous frame's layout. | Interaction |
CC_Clicked | bool CC_Clicked("id") | True on the one frame the left button goes down over the element. Always false headless. | Interaction |
CC_PointerOver | bool (CC_ElementId id) | Clay's hit test, for ids built with CC_IDI or CC_SID. | Interaction |
CC_ElementDataOf | CC_ElementData CC_ElementDataOf("id") | The element's bounding box from the last finished layout, and .found. Same id rules as CC_Hovered. | Interaction |
CC_GetElementData | CC_ElementData (CC_ElementId id) | Same, for ids built with CC_IDI or CC_SID. | Interaction |
CC_BUTTON_HOVER_ALPHA | 0.85f | Background alpha multiplier while a Button is hovered. Override with -D or a #define before the include. | Interaction |
CC_BUTTON_PRESS_ALPHA | 0.70f | Same, while pressed. | Interaction |