Element ids and strings
Elements are identified by a hash of their id string. Use a string literal for fixed elements, CC_IDI for rows generated in a loop, and CC_SID for ids built at runtime.
Example
static void rows(int count) {
Column("Rows") {
for (int i = 0; i < count; ++i) {
char id[16];
snprintf(id, sizeof id, "row-%d", i); // unique id per row
Row(id, .layout = { .padding = PadAll(4) }) { Text(id); }
}
}
// Hit-test row 3 without building its string again
if (CC_PointerOver(CC_IDI("row", 3))) { /* ... */ }
}
Reference
| Name | Form | What it does | Page |
|---|---|---|---|
CC_IDI | CC_ElementId CC_IDI("label", index) | Id from a literal plus an index, for rows in a loop. | Containers |
CC_SID | CC_ElementId CC_SID(CC_String s) | Id from a runtime string. | Containers |
CLAY_ID | CC_ElementId CLAY_ID("label") | Clay's id from a literal. Use .id for .floating.parentId. | Floating |
CC_StrIntern | CC_String (const char *s) | Copy a runtime string into permanent storage, so it stays valid after your buffer is reused. | Architecture |