From a6cf58c74c80fff41f86151f73e2dfb8ec084599 Mon Sep 17 00:00:00 2001 From: Matt Breckon Date: Sun, 24 Aug 2025 09:33:36 +0100 Subject: [PATCH 1/5] Add utf-8 codepoint support to example odin raylib renderer --- .../clay_renderer_raylib.odin | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/bindings/odin/examples/clay-official-website/clay_renderer_raylib.odin b/bindings/odin/examples/clay-official-website/clay_renderer_raylib.odin index ff624aa..e6877c4 100644 --- a/bindings/odin/examples/clay-official-website/clay_renderer_raylib.odin +++ b/bindings/odin/examples/clay-official-website/clay_renderer_raylib.odin @@ -21,9 +21,17 @@ measure_text :: proc "c" (text: clay.StringSlice, config: ^clay.TextElementConfi font := raylib_fonts[config.fontId].font - for i in 0 ..< text.length { - glyph_index := text.chars[i] - 32 + byte_index := 0 + for byte_index < int(text.length) { + // handle utf-8 codepoints + codepoint_bytes: i32 = 0 + codepoint := raylib.GetCodepoint( + transmute(cstring)&text.chars[byte_index], + &codepoint_bytes, + ) + byte_index += int(codepoint_bytes) + glyph_index := raylib.GetGlyphIndex(fontToUse, codepoint) glyph := font.glyphs[glyph_index] if glyph.advanceX != 0 { @@ -198,4 +206,4 @@ draw_rect :: proc(x, y, w, h: f32, color: clay.Color) { @(private = "file") draw_rect_rounded :: proc(x,y,w,h: f32, radius: f32, color: clay.Color){ rl.DrawRectangleRounded({x,y,w,h},radius,8,clay_color_to_rl_color(color)) -} \ No newline at end of file +} From 55453f8e45e450de0d2591d5bc618bc206a3459f Mon Sep 17 00:00:00 2001 From: Matt Breckon Date: Sun, 24 Aug 2025 12:11:29 +0100 Subject: [PATCH 2/5] Fix typos and remove code that came from another example renderer --- .../examples/clay-official-website/clay_renderer_raylib.odin | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bindings/odin/examples/clay-official-website/clay_renderer_raylib.odin b/bindings/odin/examples/clay-official-website/clay_renderer_raylib.odin index e6877c4..c3b4550 100644 --- a/bindings/odin/examples/clay-official-website/clay_renderer_raylib.odin +++ b/bindings/odin/examples/clay-official-website/clay_renderer_raylib.odin @@ -25,13 +25,13 @@ measure_text :: proc "c" (text: clay.StringSlice, config: ^clay.TextElementConfi for byte_index < int(text.length) { // handle utf-8 codepoints codepoint_bytes: i32 = 0 - codepoint := raylib.GetCodepoint( + codepoint := rl.GetCodepoint( transmute(cstring)&text.chars[byte_index], &codepoint_bytes, ) byte_index += int(codepoint_bytes) - glyph_index := raylib.GetGlyphIndex(fontToUse, codepoint) + glyph_index := rl.GetGlyphIndex(font, codepoint) glyph := font.glyphs[glyph_index] if glyph.advanceX != 0 { From 80e28e70888ff28060cfe21671bd7b18b68736df Mon Sep 17 00:00:00 2001 From: Matt Breckon Date: Sun, 24 Aug 2025 12:16:30 +0100 Subject: [PATCH 3/5] Last formatting fix --- .../examples/clay-official-website/clay_renderer_raylib.odin | 1 + 1 file changed, 1 insertion(+) diff --git a/bindings/odin/examples/clay-official-website/clay_renderer_raylib.odin b/bindings/odin/examples/clay-official-website/clay_renderer_raylib.odin index c3b4550..9216014 100644 --- a/bindings/odin/examples/clay-official-website/clay_renderer_raylib.odin +++ b/bindings/odin/examples/clay-official-website/clay_renderer_raylib.odin @@ -207,3 +207,4 @@ draw_rect :: proc(x, y, w, h: f32, color: clay.Color) { draw_rect_rounded :: proc(x,y,w,h: f32, radius: f32, color: clay.Color){ rl.DrawRectangleRounded({x,y,w,h},radius,8,clay_color_to_rl_color(color)) } + From b284305e120b4536b1dded554be1050c7a7e56fd Mon Sep 17 00:00:00 2001 From: Matt Breckon Date: Sun, 24 Aug 2025 12:17:47 +0100 Subject: [PATCH 4/5] Another attempt at a formatting fix --- .../examples/clay-official-website/clay_renderer_raylib.odin | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bindings/odin/examples/clay-official-website/clay_renderer_raylib.odin b/bindings/odin/examples/clay-official-website/clay_renderer_raylib.odin index 9216014..8d49fdb 100644 --- a/bindings/odin/examples/clay-official-website/clay_renderer_raylib.odin +++ b/bindings/odin/examples/clay-official-website/clay_renderer_raylib.odin @@ -206,5 +206,4 @@ draw_rect :: proc(x, y, w, h: f32, color: clay.Color) { @(private = "file") draw_rect_rounded :: proc(x,y,w,h: f32, radius: f32, color: clay.Color){ rl.DrawRectangleRounded({x,y,w,h},radius,8,clay_color_to_rl_color(color)) -} - +} From 2388d067260159a5ead77635badbee4cb8831d63 Mon Sep 17 00:00:00 2001 From: Matt Breckon Date: Sun, 24 Aug 2025 12:19:13 +0100 Subject: [PATCH 5/5] Definitely the last formatting fix :-( --- .../examples/clay-official-website/clay_renderer_raylib.odin | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/odin/examples/clay-official-website/clay_renderer_raylib.odin b/bindings/odin/examples/clay-official-website/clay_renderer_raylib.odin index 8d49fdb..c3b4550 100644 --- a/bindings/odin/examples/clay-official-website/clay_renderer_raylib.odin +++ b/bindings/odin/examples/clay-official-website/clay_renderer_raylib.odin @@ -206,4 +206,4 @@ draw_rect :: proc(x, y, w, h: f32, color: clay.Color) { @(private = "file") draw_rect_rounded :: proc(x,y,w,h: f32, radius: f32, color: clay.Color){ rl.DrawRectangleRounded({x,y,w,h},radius,8,clay_color_to_rl_color(color)) -} +}