Styling
Set backgrounds, corner radius, borders, shadows, and aspect ratio as top-level element fields alongside .layout. For texture rendering, see Images.
Colors
Color(r, g, b, a) constructs a CC_Color with 0 to 255 channels, alpha included:
Color(18, 18, 20, 255) // opaque near-black
Color(255, 0, 0, 128) // translucent red
Color expands to a compound literal wherever a CC_Color is expected, including element declarations, text styles, borders, and overlays. CC_Color is a typedef of Clay_Color.
Hex form
ColorHex(rgb) and ColorHexA(rgba) take CSS-style hex literals and unpack them into a CC_Color at compile time. Use them when you want to paste palette values straight out of a design tool.
.backgroundColor = ColorHex(0x1E1E22), // opaque, alpha = 255
.textColor = ColorHex(0xECECEC),
.overlayColor = ColorHexA(0x00000020), // 12.5% black wash
ColorHex(0xRRGGBB): three-byte RGB, alpha forced to255.ColorHexA(0xRRGGBBAA): four-byte RGBA, alpha in the bottom byte.
Use ColorHex for RGB literals and ColorHexA for RGBA literals. The macro determines whether the value includes alpha.
Both macros expand to CC_Color compound literals, work in headless builds, and have no runtime cost. raylib's GetColor returns its own Color type, so use the ccompose macros for CC_Color fields.
Background and overlay
Box("Card",
.backgroundColor = Color(28, 28, 34, 255),
.overlayColor = Color(0, 0, 0, 32)) // 12% black wash over everything
.backgroundColorfills the element. OnImage, it tints the texture. See Images..overlayColorblends over the element and all its descendants. Use it to dim a panel without changing each child's colors.
Corner radius
.cornerRadius is a CC_CornerRadius. ccompose ships four sugar helpers following the same shape as PadAll / PadSymmetric / PadOnly:
| Helper | Meaning |
|---|---|
RadiusAll(n) | All four corners = n. Use large values (e.g. 999) for a pill/circle shape on a square element. |
RadiusTopBottom(t, b) | Top corners = t, bottom corners = b. Cards with a rounded top edge and flat bottom. |
RadiusLeftRight(l, r) | Left corners = l, right corners = r. |
RadiusOnly(.topLeft = ..., .topRight = ..., .bottomLeft = ..., .bottomRight = ...) | Designated init. Unspecified corners default to 0. |
.cornerRadius = RadiusAll(8)
.cornerRadius = RadiusAll(999) // pill / circle for square elements
.cornerRadius = RadiusTopBottom(8, 0) // rounded top, flat bottom
.cornerRadius = RadiusLeftRight(0, 12) // rounded right side only
.cornerRadius = RadiusOnly(.topLeft = 8, .topRight = 8)
Borders
Set .border = { ... } with two fields: .color takes a CC_Color, and .width takes a CC_BorderWidth. Use these helpers to set edge widths:
| Helper | Meaning |
|---|---|
BorderAll(n) | n pixels on all four sides, no between-children divider. |
BorderSymmetric(h, v) | h on left/right, v on top/bottom, no between-children divider. |
BorderOnly(.left = ..., .right = ..., .top = ..., .bottom = ..., .betweenChildren = ...) | Designated init. Unspecified default to 0. |
Column("Panel",
.layout = { .padding = PadAll(16) },
.backgroundColor = Color(28, 28, 34, 255),
.cornerRadius = RadiusAll(8),
.border = { .color = Color(60, 60, 70, 255), .width = BorderAll(1) }) {
Text("panel content", .textColor = Color(236,236,236,255), .fontSize = 14);
}
A rounded border with the same width on every side is drawn by a distance-field shader: the outline is anti-aliased with no seams where the corners meet the sides, and each corner radius is clamped to half the element's shorter side, so a narrow pill never folds into an oval. Borders whose sides differ in width use plain rectangles and arcs.
Border width fields
CC_BorderWidth contains four edge widths and .betweenChildren. Set .betweenChildren with BorderOnly or a literal struct:
| Field | Effect |
|---|---|
.left | Left edge thickness, in px |
.right | Right edge thickness |
.top | Top edge thickness |
.bottom | Bottom edge thickness |
.betweenChildren | Divider thickness between adjacent children |
Clay draws .betweenChildren as a line between each pair of siblings, oriented along the container's layout direction:
Column("List",
.layout = { .childGap = 0 }, // rows touch each other
.border = { .color = Color(50, 50, 50, 255),
.width = BorderOnly(.betweenChildren = 1) }) {
Text("Home", .textColor = Color(236,236,236,255), .fontSize = 14);
Text("Settings", .textColor = Color(236,236,236,255), .fontSize = 14);
Text("About", .textColor = Color(236,236,236,255), .fontSize = 14);
}
Borders follow the element's .cornerRadius.
Shadow
Added in
v0.1.5.
Shadow(...) gives an element a drop shadow. It goes in the element's .custom field and follows the element's own .cornerRadius:
Column("Card",
.layout = { .padding = PadAll(16) },
.backgroundColor = Color(28, 28, 34, 255),
.cornerRadius = RadiusAll(10),
.custom = Shadow(.offset = {0, 4}, .blur = 14,
.color = Color(0, 0, 0, 110))) {
Text("card content", .textColor = Color(236,236,236,255), .fontSize = 14);
}
| Field | Effect | Default |
|---|---|---|
.offset | CC_Vector2 shift in px. {0, 4} drops the shadow down. | {0, 0} |
.blur | Width of the soft edge in px. 0 gives a hard edge, a negative value counts as 0. | 0 |
.spread | Grows (positive) or shrinks (negative) the shadow before the blur. | 0 |
.color | Shadow color. Alpha 0 falls back to the default. | Color(0, 0, 0, 64) |
.custom = Shadow(.blur = 12) // soft, centered, default color
.custom = Shadow(.offset = {6, 6}, .color = Color(0,0,0,160)) // hard offset shadow
.custom = Shadow(.offset = {0, 8}, .blur = 24, .spread = -4) // tighter, lifted card
How it draws:
- The shadow sits behind the element and above earlier siblings. On an
Imageelement it stays behind the picture. - The raylib renderer fakes the blur with 8 rounded rectangles that grow and fade. It uses no shader, so desktop and web builds draw it the same way. Very large blurs (60 px and up) can show faint banding.
- A clipping parent (a scroll view) clips the shadow too.
Limits:
- An element has one
.customslot, so it can't have both a shadow and aDrawcallback.Draw/DrawRow/DrawColumnoverwrite.custom, so aShadowpassed to them is dropped. Wrap the drawn element in a parent that carries the shadow instead. See Custom drawing. - Shadows use a per-frame pool of
CC_SHADOW_POOL_SIZE(128) entries, reset byCC_Begin(). When the pool is full,Shadow()returns{.customData = NULL}and the element has no shadow. - Clay skips fully off-screen elements, including their shadows, even when a shadow would extend on-screen.
- Headless builds emit a CUSTOM render command tagged
CC_SHADOW_TAG, which tests can inspect. No renderer draws it.
Images
Use Image("id", CC_ImageRef*, ...) for textures. See Images for scale modes, rounded corners, tinting, and loading.
Texture2D avatar = CC_LoadImage("resources/avatar.png");
/* ... */
Image("Avatar", ImgCrop(&avatar),
.layout = {.sizing = {Fixed(64), Fixed(64)}},
.cornerRadius = RadiusAll(999));
Aspect ratio
.aspectRatio forces a width/height ratio:
Box("Video",
.layout = { .sizing = { Grow(), Fit() } },
.aspectRatio = { .aspectRatio = 16.0f / 9.0f },
.backgroundColor = Color(0, 0, 0, 255)) { }
- The value is width / height:
16.0f / 9.0fgives a landscape 16:9 shape. - Common values:
1.0f(square),16.0f/9.0f,4.0f/3.0f,9.0f/16.0f(portrait). - Pair with an explicit
Grow()orFixed(px)on one axis so Clay has a stable constraint to drive the other axis from.
Putting it all together
Box("HeroCard",
.layout = { .sizing = { Grow(), Fit() },
.padding = PadAll(24),
.childAlignment = { .x = AlignXCenter(),
.y = AlignYCenter() } },
.backgroundColor = Color(28, 28, 34, 255),
.cornerRadius = RadiusAll(16),
.border = { .color = Color(60, 60, 70, 255),
.width = { .left = 1, .right = 1,
.top = 1, .bottom = 1 } },
.aspectRatio = { .aspectRatio = 16.0f / 9.0f }) {
Text("Hello",
.textColor = Color(255, 255, 255, 255),
.fontSize = 42);
}