From 77bc75fc8b0ddeb0b746d524dce8e0e888dd98b0 Mon Sep 17 00:00:00 2001
From: peterc-s <pjcsmail@gmail.com>
Date: Sat, 28 Dec 2024 13:56:54 +0000
Subject: [PATCH 1/4] move raylib renderer to header file

Author:    peterc-s <pjcsmail@gmail.com>
---
 ...renderer_raylib.c => clay_renderer_raylib.h} | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
 rename renderers/raylib/{clay_renderer_raylib.c => clay_renderer_raylib.h} (98%)

diff --git a/renderers/raylib/clay_renderer_raylib.c b/renderers/raylib/clay_renderer_raylib.h
similarity index 98%
rename from renderers/raylib/clay_renderer_raylib.c
rename to renderers/raylib/clay_renderer_raylib.h
index 0fe545a..fb01e73 100644
--- a/renderers/raylib/clay_renderer_raylib.c
+++ b/renderers/raylib/clay_renderer_raylib.h
@@ -1,3 +1,6 @@
+#ifndef CLAY_RENDERER_RAYLIB_H
+#define CLAY_RENDERER_RAYLIB_H
+
 #include "raylib.h"
 #include "raymath.h"
 #include "stdint.h"
@@ -14,8 +17,6 @@ typedef struct
     Font font;
 } Raylib_Font;
 
-Raylib_Font Raylib_fonts[10];
-Camera Raylib_camera;
 
 typedef enum
 {
@@ -38,6 +39,12 @@ typedef struct
     };
 } CustomLayoutElement;
 
+#ifdef CLAY_RAYLIB_IMPLEMENTATION
+// Global state
+Raylib_Font Raylib_fonts[10];
+Camera Raylib_camera;
+uint32_t measureCalls = 0;
+
 // Get a ray trace from the screen position (i.e mouse) within a specific section of the screen
 Ray GetScreenToWorldPointWithZDistance(Vector2 position, Camera camera, int screenWidth, int screenHeight, float zDistance)
 {
@@ -87,8 +94,6 @@ Ray GetScreenToWorldPointWithZDistance(Vector2 position, Camera camera, int scre
     return ray;
 }
 
-uint32_t measureCalls = 0;
-
 static inline Clay_Dimensions Raylib_MeasureText(Clay_String *text, Clay_TextElementConfig *config) {
     measureCalls++;
     // Measure string size for Font
@@ -122,6 +127,7 @@ static inline Clay_Dimensions Raylib_MeasureText(Clay_String *text, Clay_TextEle
 }
 
 void Clay_Raylib_Initialize(int width, int height, const char *title, unsigned int flags) {
+    measureCalls = 0;
     SetConfigFlags(flags);
     InitWindow(width, height, title);
 //    EnableEventWaiting();
@@ -231,3 +237,6 @@ void Clay_Raylib_Render(Clay_RenderCommandArray renderCommands)
         }
     }
 }
+
+#endif // CLAY_RAYLIB_IMPLEMENTATION
+#endif // CLAY_RENDERER_RAYLIB_H

From 10f1565f6f99fc5f64490d5bbb01b921859acb23 Mon Sep 17 00:00:00 2001
From: peterc-s <pjcsmail@gmail.com>
Date: Sat, 28 Dec 2024 13:58:31 +0000
Subject: [PATCH 2/4] update raylib scrolling sidebar example

Author:    peterc-s <pjcsmail@gmail.com>
---
 examples/raylib-sidebar-scrolling-container/main.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/examples/raylib-sidebar-scrolling-container/main.c b/examples/raylib-sidebar-scrolling-container/main.c
index 5a39fc1..4b51324 100644
--- a/examples/raylib-sidebar-scrolling-container/main.c
+++ b/examples/raylib-sidebar-scrolling-container/main.c
@@ -1,6 +1,7 @@
 #define CLAY_IMPLEMENTATION
 #include "../../clay.h"
-#include "../../renderers/raylib/clay_renderer_raylib.c"
+#define CLAY_RAYLIB_IMPLEMENTATION
+#include "../../renderers/raylib/clay_renderer_raylib.h"
 
 const uint32_t FONT_ID_BODY_24 = 0;
 const uint32_t FONT_ID_BODY_16 = 1;

From 974af1e61c9142ca8b294876429efb4e6f0eda70 Mon Sep 17 00:00:00 2001
From: peterc-s <pjcsmail@gmail.com>
Date: Sat, 28 Dec 2024 14:00:19 +0000
Subject: [PATCH 3/4] update raylib video example to use header file and fix
 segfault

Author:    peterc-s <pjcsmail@gmail.com>
---
 examples/introducing-clay-video-demo/main.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/examples/introducing-clay-video-demo/main.c b/examples/introducing-clay-video-demo/main.c
index e36f53a..c8c3924 100644
--- a/examples/introducing-clay-video-demo/main.c
+++ b/examples/introducing-clay-video-demo/main.c
@@ -1,6 +1,7 @@
 #define CLAY_IMPLEMENTATION
 #include "../../clay.h"
-#include "../../renderers/raylib/clay_renderer_raylib.c"
+#define CLAY_RAYLIB_IMPLEMENTATION // This is different to the video, the raylib renderer is now in a header file
+#include "../../renderers/raylib/clay_renderer_raylib.h"
 
 const int FONT_ID_BODY_16 = 0;
 Clay_Color COLOR_WHITE = { 255, 255, 255, 255};
@@ -79,10 +80,7 @@ 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();
-    Clay_Arena clayMemory = (Clay_Arena) {
-        .memory = malloc((size_t)1024 * 1024 * 1024 * 1024),
-        .capacity = clayRequiredMemory
-    };
+    Clay_Arena clayMemory = Clay_CreateArenaWithCapacityAndMemory(clayRequiredMemory, malloc(clayRequiredMemory));
     Clay_Initialize(clayMemory, (Clay_Dimensions) {
        .width = GetScreenWidth(),
        .height = GetScreenHeight()
@@ -302,4 +300,4 @@ int main(void) {
         Clay_Raylib_Render(renderCommands);
         EndDrawing();
     }
-}
\ No newline at end of file
+}

From 23863edde0742811e7c4bd4db003d401ea756677 Mon Sep 17 00:00:00 2001
From: peterc-s <pjcsmail@gmail.com>
Date: Sat, 28 Dec 2024 14:10:36 +0000
Subject: [PATCH 4/4] add undef

Author:    peterc-s <pjcsmail@gmail.com>
---
 renderers/raylib/clay_renderer_raylib.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/renderers/raylib/clay_renderer_raylib.h b/renderers/raylib/clay_renderer_raylib.h
index fb01e73..e3058f0 100644
--- a/renderers/raylib/clay_renderer_raylib.h
+++ b/renderers/raylib/clay_renderer_raylib.h
@@ -40,6 +40,8 @@ typedef struct
 } CustomLayoutElement;
 
 #ifdef CLAY_RAYLIB_IMPLEMENTATION
+#undef CLAY_RAYLIB_IMPLEMENTATION
+
 // Global state
 Raylib_Font Raylib_fonts[10];
 Camera Raylib_camera;