From 610f49588c422f3a257f70867452a71c63abf124 Mon Sep 17 00:00:00 2001 From: Nic Barker Date: Mon, 24 Mar 2025 10:31:18 +1300 Subject: [PATCH] Update odin bindings and introduce TextDynamic proc --- bindings/odin/clay-odin/clay.odin | 9 ++++++++- .../clay-official-website/clay-official-website.odin | 9 +++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/bindings/odin/clay-odin/clay.odin b/bindings/odin/clay-odin/clay.odin index 692ab10..0deea79 100644 --- a/bindings/odin/clay-odin/clay.odin +++ b/bindings/odin/clay-odin/clay.odin @@ -1,6 +1,7 @@ package clay import "core:c" +import "base:intrinsics" when ODIN_OS == .Windows { foreign import Clay "windows/clay.lib" @@ -420,7 +421,13 @@ UI :: proc() -> proc (config: ElementDeclaration) -> bool { return ConfigureOpenElement } -Text :: proc(text: string, config: ^TextElementConfig) { +Text :: proc($text: string, config: ^TextElementConfig) { + wrapped := MakeString(text) + wrapped.isStaticallyAllocated = true + _OpenTextElement(wrapped, config) +} + +TextDynamic :: proc(text: string, config: ^TextElementConfig) { _OpenTextElement(MakeString(text), config) } diff --git a/bindings/odin/examples/clay-official-website/clay-official-website.odin b/bindings/odin/examples/clay-official-website/clay-official-website.odin index d97e321..9969269 100644 --- a/bindings/odin/examples/clay-official-website/clay-official-website.odin +++ b/bindings/odin/examples/clay-official-website/clay-official-website.odin @@ -4,6 +4,7 @@ import clay "../../clay-odin" import "core:c" import "core:fmt" import "vendor:raylib" +import "core:mem" windowWidth: i32 = 1024 windowHeight: i32 = 768 @@ -62,7 +63,7 @@ border2pxRed := clay.BorderElementConfig { color = COLOR_RED } -LandingPageBlob :: proc(index: u32, fontSize: u16, fontId: u16, color: clay.Color, text: string, image: ^raylib.Texture2D) { +LandingPageBlob :: proc(index: u32, fontSize: u16, fontId: u16, color: clay.Color, $text: string, image: ^raylib.Texture2D) { if clay.UI()({ id = clay.ID("HeroBlob", index), layout = { sizing = { width = clay.SizingGrow({ max = 480 }) }, padding = clay.PaddingAll(16), childGap = 16, childAlignment = clay.ChildAlignment{ y = .Center } }, @@ -252,7 +253,7 @@ ColorLerp :: proc(a: clay.Color, b: clay.Color, amount: f32) -> clay.Color { return clay.Color{a.r + (b.r - a.r) * amount, a.g + (b.g - a.g) * amount, a.b + (b.b - a.b) * amount, a.a + (b.a - a.a) * amount} } -LOREM_IPSUM_TEXT := "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua." +LOREM_IPSUM_TEXT :: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua." HighPerformancePage :: proc(lerpValue: f32, titleTextConfig: clay.TextElementConfig, widthSizing: clay.SizingAxis) { if clay.UI()({ id = clay.ID("PerformanceLeftText"), layout = { sizing = { width = widthSizing }, layoutDirection = .TopToBottom, childGap = 8 } }) { @@ -321,7 +322,7 @@ HighPerformancePageMobile :: proc(lerpValue: f32) { } } -RendererButtonActive :: proc(index: i32, text: string) { +RendererButtonActive :: proc(index: i32, $text: string) { if clay.UI()({ layout = { sizing = { width = clay.SizingFixed(300) }, padding = clay.PaddingAll(16) }, backgroundColor = COLOR_RED, @@ -331,7 +332,7 @@ RendererButtonActive :: proc(index: i32, text: string) { } } -RendererButtonInactive :: proc(index: u32, text: string) { +RendererButtonInactive :: proc(index: u32, $text: string) { if clay.UI()({ border = border2pxRed }) { if clay.UI()({ id = clay.ID("RendererButtonInactiveInner", index),