Update main for clay 0.13

Signed-off-by: jmug <u.g.a.mariano@gmail.com>
This commit is contained in:
Mariano Uvalle 2025-04-19 21:15:12 -07:00
parent 735b47aa2c
commit 5324569ac6

View file

@ -14,174 +14,184 @@ void HandleButtonInteraction(Clay_ElementId elementId, Clay_PointerData pointerD
} }
void ExpandContainer() { void ExpandContainer() {
CLAY( CLAY({
CLAY_RECTANGLE({ .color = {0, 0, 0, 0} }), .backgroundColor = {0, 0, 0, 0},
CLAY_LAYOUT({ .layout = {
.sizing = { .sizing = {
.width = CLAY_SIZING_GROW(), .width = CLAY_SIZING_GROW(),
.height = CLAY_SIZING_GROW() .height = CLAY_SIZING_GROW()
} }
}) }
) {} }) {}
} }
int main(void) Clay_RenderCommandArray CreateLayout() {
{
Clay_Raylib_Initialize(GetScreenWidth(), GetScreenHeight(), "PiAlarm", FLAG_FULLSCREEN_MODE);
uint64_t clayRequiredMemory = Clay_MinMemorySize();
Clay_Arena clayMemory = Clay_CreateArenaWithCapacityAndMemory(clayRequiredMemory, malloc(clayRequiredMemory));
Clay_Initialize(clayMemory, (Clay_Dimensions) {
.width = GetScreenWidth(),
.height = GetScreenHeight()
}, (Clay_ErrorHandler) { HandleClayErrors });
Clay_SetMeasureTextFunction(Raylib_MeasureText);
HideCursor();
while (!WindowShouldClose()) {
// Must be run once per frame.
Clay_SetLayoutDimensions((Clay_Dimensions) {
.width = GetScreenWidth(),
.height = GetScreenHeight()
});
// Update Mouse and Scroll
Vector2 mousePosition = GetMousePosition();
Vector2 scrollDelta = GetMouseWheelMoveV();
Clay_SetPointerState(
(Clay_Vector2) { mousePosition.x, mousePosition.y },
IsMouseButtonDown(0)
);
Clay_UpdateScrollContainers(
true,
(Clay_Vector2) { scrollDelta.x, scrollDelta.y },
GetFrameTime()
);
Clay_BeginLayout(); Clay_BeginLayout();
CLAY( CLAY({
CLAY_RECTANGLE({ .color = {255, 255, 255, 255} }), .backgroundColor = {255, 255, 255, 255},
CLAY_LAYOUT({ .layout = {
.sizing = { .sizing = {
.width = CLAY_SIZING_GROW(), .width = CLAY_SIZING_GROW(),
.height = CLAY_SIZING_GROW() .height = CLAY_SIZING_GROW()
}, },
.padding = {10, 10}, .padding = {10, 10, 10, 10},
.layoutDirection = CLAY_TOP_TO_BOTTOM .layoutDirection = CLAY_TOP_TO_BOTTOM
}) }
) { }) {
CLAY( CLAY({
CLAY_RECTANGLE({ .color = {200, 200, 200, 255} }), .backgroundColor = {200, 200, 200, 255},
CLAY_LAYOUT({ .layout = {
.sizing = { .sizing = {
.width = CLAY_SIZING_GROW(), .width = CLAY_SIZING_GROW(),
.height = CLAY_SIZING_PERCENT(0.7) .height = CLAY_SIZING_PERCENT(0.7)
}, },
.padding = {20, 80} .padding = {20, 20, 80, 80}
}) }
) { }) {
CLAY( CLAY({
CLAY_RECTANGLE({ .color = {200, 200, 0, 255} }), .backgroundColor = {200, 200, 0, 255},
CLAY_LAYOUT({ .layout = {
.sizing = { .sizing = {
.width = CLAY_SIZING_PERCENT(0.23), .width = CLAY_SIZING_PERCENT(0.23),
.height = CLAY_SIZING_GROW() .height = CLAY_SIZING_GROW()
} }
}), }
Clay_OnHover(HandleButtonInteraction, NULL)
) {} }) {
CLAY( Clay_OnHover(HandleButtonInteraction, NULL);
CLAY_RECTANGLE({ .color = {200, 200, 0, 255} }), }
CLAY_LAYOUT({ CLAY({
.backgroundColor = {200, 200, 0, 255},
.layout = {
.sizing = { .sizing = {
.width = CLAY_SIZING_PERCENT(0.23), .width = CLAY_SIZING_PERCENT(0.23),
.height = CLAY_SIZING_GROW() .height = CLAY_SIZING_GROW()
} }
}), }
Clay_OnHover(HandleButtonInteraction, NULL) }) {
) {} Clay_OnHover(HandleButtonInteraction, NULL);
CLAY( }
CLAY_RECTANGLE({ .color = {200, 200, 0, 0} }), CLAY({
CLAY_LAYOUT({ .backgroundColor = {200, 200, 0, 0},
.layout = {
.sizing = { .sizing = {
.width = CLAY_SIZING_GROW(), .width = CLAY_SIZING_GROW(),
.height = CLAY_SIZING_GROW() .height = CLAY_SIZING_GROW()
} }
}), }
Clay_OnHover(HandleButtonInteraction, NULL) }) {
) {} Clay_OnHover(HandleButtonInteraction, NULL);
CLAY( }
CLAY_RECTANGLE({ .color = {200, 200, 0, 255} }), CLAY({
CLAY_LAYOUT({ .backgroundColor = {200, 200, 0, 255},
.layout = {
.sizing = { .sizing = {
.width = CLAY_SIZING_PERCENT(0.23), .width = CLAY_SIZING_PERCENT(0.23),
.height = CLAY_SIZING_GROW() .height = CLAY_SIZING_GROW()
} }
}), },
Clay_OnHover(HandleButtonInteraction, NULL)
) {} }) {
CLAY( Clay_OnHover(HandleButtonInteraction, NULL);
CLAY_RECTANGLE({ .color = {200, 200, 0, 255} }), }
CLAY_LAYOUT({ CLAY({
.backgroundColor = {200, 200, 0, 255},
.layout = {
.sizing = { .sizing = {
.width = CLAY_SIZING_PERCENT(0.23), .width = CLAY_SIZING_PERCENT(0.23),
.height = CLAY_SIZING_GROW() .height = CLAY_SIZING_GROW()
} }
}),
Clay_OnHover(HandleButtonInteraction, NULL)
) {}
} }
CLAY( }) {
CLAY_RECTANGLE({ .color = {200, 200, 200, 255} }), Clay_OnHover(HandleButtonInteraction, NULL);
CLAY_LAYOUT({ }
}
CLAY({
.backgroundColor = {200, 200, 200, 255},
.layout = {
.sizing = { .sizing = {
.width = CLAY_SIZING_GROW(), .width = CLAY_SIZING_GROW(),
.height = CLAY_SIZING_GROW() .height = CLAY_SIZING_GROW()
}, },
.padding = { 20, 20 } .padding = { 20, 20 , 20, 20}
}) }
) { }) {
CLAY( CLAY({
CLAY_RECTANGLE({ .color = {200, 200, 0, 255} }), .backgroundColor = {200, 200, 0, 255},
CLAY_LAYOUT({ .layout = {
.sizing = { .sizing = {
.width = CLAY_SIZING_PERCENT(0.30), .width = CLAY_SIZING_PERCENT(0.30),
.height = CLAY_SIZING_GROW() .height = CLAY_SIZING_GROW()
} }
}), },
Clay_OnHover(HandleButtonInteraction, NULL)
) {} }) {
Clay_OnHover(HandleButtonInteraction, NULL);
}
ExpandContainer(); ExpandContainer();
CLAY( CLAY({
CLAY_RECTANGLE({ .color = {200, 200, 0, 255} }), .backgroundColor = {200, 200, 0, 255},
CLAY_LAYOUT({ .layout = {
.sizing = { .sizing = {
.width = CLAY_SIZING_PERCENT(0.30), .width = CLAY_SIZING_PERCENT(0.30),
.height = CLAY_SIZING_GROW() .height = CLAY_SIZING_GROW()
} }
}), }
Clay_OnHover(HandleButtonInteraction, NULL) }) {
) {} Clay_OnHover(HandleButtonInteraction, NULL);
}
ExpandContainer(); ExpandContainer();
CLAY( CLAY({
CLAY_RECTANGLE({ .color = {200, 200, 0, 255} }), .backgroundColor = {200, 200, 0, 255},
CLAY_LAYOUT({ .layout = {
.sizing = { .sizing = {
.width = CLAY_SIZING_PERCENT(0.30), .width = CLAY_SIZING_PERCENT(0.30),
.height = CLAY_SIZING_GROW() .height = CLAY_SIZING_GROW()
} }
}), }
Clay_OnHover(HandleButtonInteraction, NULL) }) {
) {} Clay_OnHover(HandleButtonInteraction, NULL);
}
} }
} }
Clay_RenderCommandArray renderCommands = Clay_EndLayout(); return Clay_EndLayout();
}
void UpdateDrawFrame(Font* fonts)
{
Vector2 mouseWheelDelta = GetMouseWheelMoveV();
float mouseWheelX = mouseWheelDelta.x;
float mouseWheelY = mouseWheelDelta.y;
//----------------------------------------------------------------------------------
// Handle scroll containers
Clay_Vector2 mousePosition = RAYLIB_VECTOR2_TO_CLAY_VECTOR2(GetMousePosition());
Clay_SetPointerState(mousePosition, IsMouseButtonDown(0));
Clay_SetLayoutDimensions((Clay_Dimensions) { (float)GetScreenWidth(), (float)GetScreenHeight() });
// Generate the auto layout for rendering
Clay_RenderCommandArray renderCommands = CreateLayout();
// RENDERING ---------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(BLACK); ClearBackground(BLACK);
Clay_Raylib_Render(renderCommands); Clay_Raylib_Render(renderCommands, fonts);
EndDrawing(); EndDrawing();
//----------------------------------------------------------------------------------
}
int main(void)
{
uint64_t totalMemorySize = Clay_MinMemorySize();
Clay_Arena clayMemory = Clay_CreateArenaWithCapacityAndMemory(totalMemorySize, malloc(totalMemorySize));
Clay_Initialize(clayMemory, (Clay_Dimensions) { (float)GetScreenWidth(), (float)GetScreenHeight() }, (Clay_ErrorHandler) { HandleClayErrors, 0 });
Clay_Raylib_Initialize(GetScreenWidth(), GetScreenHeight(), "PiAlarm", FLAG_VSYNC_HINT | FLAG_FULLSCREEN_MODE | FLAG_MSAA_4X_HINT);
HideCursor();
while (!WindowShouldClose()) {
UpdateDrawFrame(NULL);
} }
CloseWindow(); CloseWindow();
return 0; return 0;