[Examples/SDL3] Add demo for borders and rounded borders.

This commit is contained in:
arnau.nau 2025-01-23 04:08:41 +01:00
parent e08950c2c7
commit 302113085e
No known key found for this signature in database
GPG Key ID: 88BBBBA8921839B2

View File

@ -33,12 +33,12 @@ static inline Clay_Dimensions SDL_MeasureText(Clay_StringSlice text, Clay_TextEl
return (Clay_Dimensions) { (float) width, (float) height }; return (Clay_Dimensions) { (float) width, (float) height };
} }
static void Label(const Clay_String text) static void Label(const Clay_String text, const int cornerRadius)
{ {
CLAY(CLAY_LAYOUT({ .padding = {8, 8} }), CLAY(CLAY_LAYOUT({ .padding = {8, 8} }),
CLAY_RECTANGLE({ CLAY_RECTANGLE({
.color = Clay_Hovered() ? COLOR_BLUE : COLOR_ORANGE, .color = Clay_Hovered() ? COLOR_BLUE : COLOR_ORANGE,
.cornerRadius = (Clay_CornerRadius){ 8, 8, 8, 8 }, .cornerRadius = cornerRadius,
})) { })) {
CLAY_TEXT(text, CLAY_TEXT_CONFIG({ CLAY_TEXT(text, CLAY_TEXT_CONFIG({
.textColor = { 255, 255, 255, 255 }, .textColor = { 255, 255, 255, 255 },
@ -48,6 +48,24 @@ static void Label(const Clay_String text)
} }
} }
static void LabelBorder(const Clay_String text, const int cornerRadius)
{
CLAY(
CLAY_LAYOUT({
.padding = {8, 8} }),
CLAY_BORDER_OUTSIDE_RADIUS(
2,
COLOR_BLUE,
cornerRadius)
){
CLAY_TEXT(text, CLAY_TEXT_CONFIG({
.textColor = { 255, 255, 255, 255 },
.fontId = FONT_ID,
.fontSize = 24,
}));
}
}
static Clay_RenderCommandArray Clay_CreateLayout() static Clay_RenderCommandArray Clay_CreateLayout()
{ {
Clay_BeginLayout(); Clay_BeginLayout();
@ -65,13 +83,20 @@ static Clay_RenderCommandArray Clay_CreateLayout()
.padding = { 10, 10 }, .padding = { 10, 10 },
.layoutDirection = CLAY_TOP_TO_BOTTOM, .layoutDirection = CLAY_TOP_TO_BOTTOM,
}), }),
CLAY_BORDER({
.left = { 20, COLOR_BLUE },
.right = { 20, COLOR_BLUE },
.bottom = { 20, COLOR_BLUE }
}),
CLAY_RECTANGLE({ CLAY_RECTANGLE({
.color = COLOR_LIGHT, .color = COLOR_LIGHT,
}) })
) { ) {
Label(CLAY_STRING("Button 1")); Label(CLAY_STRING("Rounded - Button 1"), 5);
Label(CLAY_STRING("Button 2")); Label(CLAY_STRING("Straight - Button 2") , 0);
Label(CLAY_STRING("Button 3")); Label(CLAY_STRING("Rounded+ - Button 3") , 20);
LabelBorder(CLAY_STRING("Border - Button 4"), 0);
LabelBorder(CLAY_STRING("RoundedBorder - Button 5"), 10);
} }
return Clay_EndLayout(); return Clay_EndLayout();
} }