diff --git a/README.md b/README.md index fa8c303..8a6a55e 100644 --- a/README.md +++ b/README.md @@ -89,7 +89,7 @@ int main() { CLAY({ .id = CLAY_ID("SideBar"), .layout = { .layoutDirection = CLAY_TOP_TO_BOTTOM, .sizing = { .width = CLAY_SIZING_FIXED(300), .height = CLAY_SIZING_GROW(0) }, .padding = CLAY_PADDING_ALL(16), .childGap = 16 }, - .backgroundColor = COLOR_LIGHT } + .backgroundColor = COLOR_LIGHT }) { CLAY({ .id = CLAY_ID("ProfilePictureOuter"), .layout = { .sizing = { .width = CLAY_SIZING_GROW(0) }, .padding = CLAY_PADDING_ALL(16), .childGap = 16, .childAlignment = { .y = CLAY_ALIGN_Y_CENTER } }, .backgroundColor = COLOR_RED }) { CLAY({ .id = CLAY_ID("ProfilePicture"), .layout = { .sizing = { .width = CLAY_SIZING_FIXED(60), .height = CLAY_SIZING_FIXED(60) }}, .image = { .imageData = &profilePicture, .sourceDimensions = {60, 60} } }) {} diff --git a/bindings/odin/build-clay-lib.sh b/bindings/odin/build-clay-lib.sh index d05badf..2a7ee48 100755 --- a/bindings/odin/build-clay-lib.sh +++ b/bindings/odin/build-clay-lib.sh @@ -1,13 +1,13 @@ cp ../../clay.h clay.c; # Intel Mac -clang -c -DCLAY_IMPLEMENTATION -o clay.o -ffreestanding -static -target x86_64-apple-darwin clay.c -fPIC && ar r clay-odin/macos/clay.a clay.o; +clang -c -DCLAY_IMPLEMENTATION -o clay.o -ffreestanding -static -target x86_64-apple-darwin clay.c -fPIC -O3 && ar r clay-odin/macos/clay.a clay.o; # ARM Mac -clang -c -DCLAY_IMPLEMENTATION -g -o clay.o -static clay.c -fPIC && ar r clay-odin/macos-arm64/clay.a clay.o; +clang -c -DCLAY_IMPLEMENTATION -g -o clay.o -static clay.c -fPIC -O3 && ar r clay-odin/macos-arm64/clay.a clay.o; # x64 Windows -clang -c -DCLAY_IMPLEMENTATION -o clay-odin/windows/clay.lib -ffreestanding -target x86_64-pc-windows-msvc -fuse-ld=llvm-lib -static clay.c; +clang -c -DCLAY_IMPLEMENTATION -o clay-odin/windows/clay.lib -ffreestanding -target x86_64-pc-windows-msvc -fuse-ld=llvm-lib -static -O3 clay.c; # Linux -clang -c -DCLAY_IMPLEMENTATION -o clay.o -ffreestanding -static -target x86_64-unknown-linux-gnu clay.c -fPIC && ar r clay-odin/linux/clay.a clay.o; +clang -c -DCLAY_IMPLEMENTATION -o clay.o -ffreestanding -static -target x86_64-unknown-linux-gnu clay.c -fPIC -O3 && ar r clay-odin/linux/clay.a clay.o; # WASM -clang -c -DCLAY_IMPLEMENTATION -o clay-odin/wasm/clay.o -target wasm32 -nostdlib -static clay.c; +clang -c -DCLAY_IMPLEMENTATION -o clay-odin/wasm/clay.o -target wasm32 -nostdlib -static -O3 clay.c; rm clay.o; rm clay.c; diff --git a/bindings/odin/clay-odin/clay.odin b/bindings/odin/clay-odin/clay.odin index 8195a18..78496b1 100644 --- a/bindings/odin/clay-odin/clay.odin +++ b/bindings/odin/clay-odin/clay.odin @@ -36,7 +36,7 @@ Dimensions :: struct { Arena :: struct { nextAllocation: uintptr, - capacity: uintptr, + capacity: c.size_t, memory: [^]c.char, } @@ -102,6 +102,7 @@ TextAlignment :: enum EnumBackingType { } TextElementConfig :: struct { + userData: rawptr, textColor: Color, fontId: u16, fontSize: u16, @@ -367,7 +368,7 @@ Context :: struct {} // opaque structure, only use as a pointer @(link_prefix = "Clay_", default_calling_convention = "c") foreign Clay { MinMemorySize :: proc() -> u32 --- - CreateArenaWithCapacityAndMemory :: proc(capacity: u32, offset: [^]u8) -> Arena --- + CreateArenaWithCapacityAndMemory :: proc(capacity: c.size_t, offset: [^]u8) -> Arena --- SetPointerState :: proc(position: Vector2, pointerDown: bool) --- Initialize :: proc(arena: Arena, layoutDimensions: Dimensions, errorHandler: ErrorHandler) -> ^Context --- GetCurrentContext :: proc() -> ^Context --- diff --git a/bindings/odin/clay-odin/linux/clay.a b/bindings/odin/clay-odin/linux/clay.a index 981b310..4c3abd3 100644 Binary files a/bindings/odin/clay-odin/linux/clay.a and b/bindings/odin/clay-odin/linux/clay.a differ diff --git a/bindings/odin/clay-odin/macos-arm64/clay.a b/bindings/odin/clay-odin/macos-arm64/clay.a index e3ea9e9..e144c3f 100644 Binary files a/bindings/odin/clay-odin/macos-arm64/clay.a and b/bindings/odin/clay-odin/macos-arm64/clay.a differ diff --git a/bindings/odin/clay-odin/macos/clay.a b/bindings/odin/clay-odin/macos/clay.a index 0279e9c..8719dd4 100644 Binary files a/bindings/odin/clay-odin/macos/clay.a and b/bindings/odin/clay-odin/macos/clay.a differ diff --git a/bindings/odin/clay-odin/wasm/clay.o b/bindings/odin/clay-odin/wasm/clay.o index efc0772..002d759 100644 Binary files a/bindings/odin/clay-odin/wasm/clay.o and b/bindings/odin/clay-odin/wasm/clay.o differ diff --git a/bindings/odin/clay-odin/windows/clay.lib b/bindings/odin/clay-odin/windows/clay.lib index d55d923..7659f80 100644 Binary files a/bindings/odin/clay-odin/windows/clay.lib and b/bindings/odin/clay-odin/windows/clay.lib differ 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 d96b01b..d97e321 100644 --- a/bindings/odin/examples/clay-official-website/clay-official-website.odin +++ b/bindings/odin/examples/clay-official-website/clay-official-website.odin @@ -489,7 +489,7 @@ errorHandler :: proc "c" (errorData: clay.ErrorData) { } main :: proc() { - minMemorySize: u32 = clay.MinMemorySize() + minMemorySize: c.size_t = cast(c.size_t)clay.MinMemorySize() memory := make([^]u8, minMemorySize) arena: clay.Arena = clay.CreateArenaWithCapacityAndMemory(minMemorySize, memory) clay.Initialize(arena, {cast(f32)raylib.GetScreenWidth(), cast(f32)raylib.GetScreenHeight()}, { handler = errorHandler }) diff --git a/clay.h b/clay.h index 0fd4fe5..829b70b 100644 --- a/clay.h +++ b/clay.h @@ -1,4 +1,4 @@ -// VERSION: 0.12 +// VERSION: 0.13 /* NOTE: In order to use this library you must define @@ -266,7 +266,7 @@ typedef CLAY_PACKED_ENUM { CLAY_ALIGN_Y_TOP, // Aligns child elements to the bottom of this element, offset by padding.width.bottom CLAY_ALIGN_Y_BOTTOM, - // Aligns child elements vertiically to the center of this element + // Aligns child elements vertically to the center of this element CLAY_ALIGN_Y_CENTER, } Clay_LayoutAlignmentY; @@ -357,6 +357,8 @@ typedef CLAY_PACKED_ENUM { // Controls various functionality related to text elements. typedef struct { + // A pointer that will be transparently passed through to the resulting render command. + void *userData; // The RGBA color of the font to render, conventionally specified as 0-255. Clay_Color textColor; // An integer transparently passed to Clay_MeasureText to identify the font to use. @@ -1769,7 +1771,7 @@ bool Clay__MemCmp(const char *s1, const char *s2, int32_t length); uint8x16_t v2 = vld1q_u8((const uint8_t *)s2); // Compare vectors - if (vminvq_u32(vceqq_u8(v1, v2)) != 0xFFFFFFFF) { // If there's a difference + if (vminvq_u32(vreinterpretq_u32_u8(vceqq_u8(v1, v2))) != 0xFFFFFFFF) { // If there's a difference return false; } @@ -2692,7 +2694,7 @@ void Clay__CalculateFinalLayout(void) { .letterSpacing = textElementConfig->letterSpacing, .lineHeight = textElementConfig->lineHeight, }}, - .userData = sharedConfig->userData, + .userData = textElementConfig->userData, .id = Clay__HashNumber(lineIndex, currentElement->id).id, .zIndex = root->zIndex, .commandType = CLAY_RENDER_COMMAND_TYPE_TEXT, diff --git a/examples/clay-official-website/build/clay/index.html b/examples/clay-official-website/build/clay/index.html index 1e07d31..e626e4b 100644 --- a/examples/clay-official-website/build/clay/index.html +++ b/examples/clay-official-website/build/clay/index.html @@ -119,6 +119,7 @@ {name: 'bottomRight', type: 'float'}, ]}; let textConfigDefinition = { name: 'text', type: 'struct', members: [ + { name: 'userData', type: 'uint32_t' }, { name: 'textColor', ...colorDefinition }, { name: 'fontId', type: 'uint16_t' }, { name: 'fontSize', type: 'uint16_t' }, diff --git a/examples/clay-official-website/build/clay/index.wasm b/examples/clay-official-website/build/clay/index.wasm index 5e94900..e57e631 100755 Binary files a/examples/clay-official-website/build/clay/index.wasm and b/examples/clay-official-website/build/clay/index.wasm differ diff --git a/examples/clay-official-website/index.html b/examples/clay-official-website/index.html index 1e07d31..e626e4b 100644 --- a/examples/clay-official-website/index.html +++ b/examples/clay-official-website/index.html @@ -119,6 +119,7 @@ {name: 'bottomRight', type: 'float'}, ]}; let textConfigDefinition = { name: 'text', type: 'struct', members: [ + { name: 'userData', type: 'uint32_t' }, { name: 'textColor', ...colorDefinition }, { name: 'fontId', type: 'uint16_t' }, { name: 'fontSize', type: 'uint16_t' }, diff --git a/renderers/raylib/clay_renderer_raylib.c b/renderers/raylib/clay_renderer_raylib.c index 35a4f15..de7857c 100644 --- a/renderers/raylib/clay_renderer_raylib.c +++ b/renderers/raylib/clay_renderer_raylib.c @@ -91,8 +91,11 @@ static inline Clay_Dimensions Raylib_MeasureText(Clay_StringSlice text, Clay_Tex float textHeight = config->fontSize; Font* fonts = (Font*)userData; Font fontToUse = fonts[config->fontId]; - // Font failed to load, likely the fonts are in the wrong place relative to the execution dir - if (!fontToUse.glyphs) return textSize; + // Font failed to load, likely the fonts are in the wrong place relative to the execution dir. + // RayLib ships with a default font, so we can continue with that built in one. + if (!fontToUse.glyphs) { + fontToUse = GetFontDefault(); + } float scaleFactor = config->fontSize/(float)fontToUse.baseSize;