Skip to main content

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​

NameFormWhat it doesPage
CC_Hoveredbool CC_Hovered("id")True while the pointer is over the element. Uses the previous frame's layout.Interaction
CC_Clickedbool CC_Clicked("id")True on the one frame the left button goes down over the element. Always false headless.Interaction
CC_PointerOverbool (CC_ElementId id)Clay's hit test, for ids built with CC_IDI or CC_SID.Interaction
CC_ElementDataOfCC_ElementData CC_ElementDataOf("id")The element's bounding box from the last finished layout, and .found. Same id rules as CC_Hovered.Interaction
CC_GetElementDataCC_ElementData (CC_ElementId id)Same, for ids built with CC_IDI or CC_SID.Interaction
CC_BUTTON_HOVER_ALPHA0.85fBackground alpha multiplier while a Button is hovered. Override with -D or a #define before the include.Interaction
CC_BUTTON_PRESS_ALPHA0.70fSame, while pressed.Interaction