2024-12-26 21:52:12 +00:00
# define CLAY_IMPLEMENTATION
# include "../../clay.h"
# include "../../renderers/raylib/clay_renderer_raylib.c"
2025-01-30 02:40:29 +00:00
# include "../shared-layouts/clay-video-demo.c"
2024-12-26 21:52:12 +00:00
// This function is new since the video was published
void HandleClayErrors ( Clay_ErrorData errorData ) {
printf ( " %s " , errorData . errorText . chars ) ;
}
int main ( void ) {
Clay_Raylib_Initialize ( 1024 , 768 , " Introducing Clay Demo " , FLAG_WINDOW_RESIZABLE | FLAG_WINDOW_HIGHDPI | FLAG_MSAA_4X_HINT | FLAG_VSYNC_HINT ) ; // Extra parameters to this function are new since the video was published
uint64_t clayRequiredMemory = Clay_MinMemorySize ( ) ;
2024-12-28 17:39:38 +00:00
Clay_Arena clayMemory = Clay_CreateArenaWithCapacityAndMemory ( clayRequiredMemory , malloc ( clayRequiredMemory ) ) ;
2024-12-26 21:52:12 +00:00
Clay_Initialize ( clayMemory , ( Clay_Dimensions ) {
. width = GetScreenWidth ( ) ,
. height = GetScreenHeight ( )
} , ( Clay_ErrorHandler ) { HandleClayErrors } ) ; // This final argument is new since the video was published
2025-01-19 21:59:02 +00:00
Clay_SetMeasureTextFunction ( Raylib_MeasureText , 0 ) ;
2024-12-26 21:52:12 +00:00
Raylib_fonts [ FONT_ID_BODY_16 ] = ( Raylib_Font ) {
. font = LoadFontEx ( " resources/Roboto-Regular.ttf " , 48 , 0 , 400 ) ,
. fontId = FONT_ID_BODY_16
} ;
SetTextureFilter ( Raylib_fonts [ FONT_ID_BODY_16 ] . font . texture , TEXTURE_FILTER_BILINEAR ) ;
2025-01-30 22:17:23 +00:00
ClayVideoDemo_Data data = ClayVideoDemo_Initialize ( ) ;
2025-01-30 02:40:29 +00:00
2024-12-26 21:52:12 +00:00
while ( ! WindowShouldClose ( ) ) {
// Run once per frame
Clay_SetLayoutDimensions ( ( Clay_Dimensions ) {
2025-01-30 02:40:29 +00:00
. width = GetScreenWidth ( ) ,
. height = GetScreenHeight ( )
2024-12-26 21:52:12 +00:00
} ) ;
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 ( )
) ;
2025-01-30 22:17:23 +00:00
Clay_RenderCommandArray renderCommands = ClayVideoDemo_CreateLayout ( & data ) ;
2024-12-26 21:52:12 +00:00
BeginDrawing ( ) ;
ClearBackground ( BLACK ) ;
Clay_Raylib_Render ( renderCommands ) ;
EndDrawing ( ) ;
}
2024-12-28 17:39:38 +00:00
}