Merge branch 'main' into main

This commit is contained in:
Nic Barker 2024-09-01 10:59:05 +12:00 committed by GitHub
commit 99775ace5e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 40 additions and 28 deletions

View File

@ -1,7 +1,13 @@
cp ../../clay.h clay.c;
# Intel Mac
clang -c -o clay.o -static -target x86_64-apple-darwin clay.c -fPIC && ar r clay-odin/macos/clay.a clay.o;
# ARM Mac
clang -c -o clay.o -static clay.c -fPIC && ar r clay-odin/macos-arm64/clay.a clay.o;
# x64 Windows
clang -c -o clay-odin/windows/clay.lib -target x86_64-pc-windows-msvc -fuse-ld=llvm-lib -static clay.c;
# Linux
clang -c -o clay.o -static -target x86_64-unknown-linux-gnu clay.c -fPIC && ar r clay-odin/linux/clay.a clay.o;
# WASM
clang -c -o clay-odin/wasm/clay.o -target wasm32 -nostdlib -static clay.c;
rm clay.o;
rm clay.c;

View File

@ -6,7 +6,7 @@ import "core:strings"
when ODIN_OS == .Windows {
foreign import Clay "windows/clay.lib"
} else when ODIN_OS == .Linux {
foreign import Clay "linux/libclay.a"
foreign import Clay "linux/clay.a"
} else when ODIN_OS == .Darwin {
when ODIN_ARCH == .arm64 {
foreign import Clay "macos-arm64/clay.a"
@ -14,7 +14,7 @@ when ODIN_OS == .Windows {
foreign import Clay "macos/clay.a"
}
} else when ODIN_ARCH == .wasm32 || ODIN_ARCH == .wasm64p32 {
foreign import Clay "wasm/clay.o"
foreign import Clay "wasm/clay.o"
}
String :: struct {
@ -57,7 +57,13 @@ BorderData :: struct {
color: Color,
}
RenderCommandType :: enum u8 {
when ODIN_OS == .Windows {
EnumBackingType :: u32
} else {
EnumBackingType :: u8
}
RenderCommandType :: enum EnumBackingType {
None,
Rectangle,
Border,
@ -104,7 +110,7 @@ ScrollElementConfig :: struct {
vertical: bool,
}
FloatingAttachPointType :: enum u8 {
FloatingAttachPointType :: enum EnumBackingType {
LEFT_TOP,
LEFT_CENTER,
LEFT_BOTTOM,
@ -156,7 +162,7 @@ ScrollContainerData :: struct {
found: bool,
}
SizingType :: enum u8 {
SizingType :: enum EnumBackingType {
FIT,
GROW,
PERCENT,
@ -188,18 +194,18 @@ Padding :: struct {
y: u16,
}
LayoutDirection :: enum u8 {
LayoutDirection :: enum EnumBackingType {
LEFT_TO_RIGHT,
TOP_TO_BOTTOM,
}
LayoutAlignmentX :: enum u8 {
LayoutAlignmentX :: enum EnumBackingType {
LEFT,
RIGHT,
CENTER,
}
LayoutAlignmentY :: enum u8 {
LayoutAlignmentY :: enum EnumBackingType {
TOP,
BOTTOM,
CENTER,
@ -240,7 +246,7 @@ foreign Clay {
}
@(private, link_prefix = "Clay_", default_calling_convention = "c")
foreign {
foreign _ {
_layoutConfigs: ClayArray(LayoutConfig)
_rectangleElementConfigs: ClayArray(RectangleElementConfig)
_textElementConfigs: ClayArray(TextElementConfig)

Binary file not shown.

Binary file not shown.

View File

@ -229,14 +229,14 @@ DeclarativeSyntaxPageDesktop :: proc() {
clay.Layout({sizing = {clay.SizingGrow({}), clay.SizingGrow({})}, childAlignment = {y = .CENTER}, padding = {32, 32}, childGap = 32}),
clay.BorderConfig({left = {2, COLOR_RED}, right = {2, COLOR_RED}}),
) {
DeclarativeSyntaxPage({fontSize = 48, fontId = FONT_ID_TITLE_48, textColor = COLOR_LIGHT}, clay.SizingGrow({}))
DeclarativeSyntaxPage({fontSize = 52, fontId = FONT_ID_TITLE_52, textColor = COLOR_RED}, clay.SizingPercent(0.5))
}
}
}
DeclarativeSyntaxPageMobile :: proc() {
if clay.Container(
clay.ID("SyntaxPageDesktop"),
clay.ID("SyntaxPageMobile"),
clay.Layout(
{
layoutDirection = .TOP_TO_BOTTOM,
@ -247,7 +247,7 @@ DeclarativeSyntaxPageMobile :: proc() {
},
),
) {
DeclarativeSyntaxPage({fontSize = 52, fontId = FONT_ID_TITLE_52, textColor = COLOR_LIGHT}, clay.SizingGrow({}))
DeclarativeSyntaxPage({fontSize = 48, fontId = FONT_ID_TITLE_48, textColor = COLOR_RED}, clay.SizingGrow({}))
}
}
@ -534,6 +534,8 @@ main :: proc() {
checkImage5 = raylib.LoadTextureFromImage(raylib.LoadImage("resources/check_5.png"))
for !raylib.WindowShouldClose() {
defer free_all(context.temp_allocator)
animationLerpValue += raylib.GetFrameTime()
if animationLerpValue > 1 {
animationLerpValue = animationLerpValue - 2

View File

@ -2,6 +2,7 @@ package main
import clay "../../clay-odin"
import "core:math"
import "core:strings"
import "vendor:raylib"
RaylibFont :: struct {
@ -47,7 +48,7 @@ measureText :: proc "c" (text: ^clay.String, config: ^clay.TextElementConfig) ->
return textSize
}
clayRaylibRender :: proc(renderCommands: ^clay.ClayArray(clay.RenderCommand)) {
clayRaylibRender :: proc(renderCommands: ^clay.ClayArray(clay.RenderCommand), allocator := context.temp_allocator) {
for i in 0..<int(renderCommands.length) {
renderCommand := clay.RenderCommandArray_Get(renderCommands, cast(i32)i)
boundingBox := renderCommand.boundingBox
@ -55,21 +56,18 @@ clayRaylibRender :: proc(renderCommands: ^clay.ClayArray(clay.RenderCommand)) {
case clay.RenderCommandType.None:
{}
case clay.RenderCommandType.Text:
// Raylib uses standard C strings so isn't compatible with cheap slices, we need to clone the string to append null terminator
text := renderCommand.text
cloned := make([]u8, text.length + 1, context.temp_allocator)
copy(cloned[:text.length], text.chars[:text.length])
cloned[text.length] = 0
fontToUse: raylib.Font = raylibFonts[renderCommand.config.textElementConfig.fontId].font
raylib.DrawTextEx(
fontToUse,
cstring(raw_data(cloned)),
raylib.Vector2{boundingBox.x, boundingBox.y},
cast(f32)renderCommand.config.textElementConfig.fontSize,
cast(f32)renderCommand.config.textElementConfig.letterSpacing,
clayColorToRaylibColor(renderCommand.config.textElementConfig.textColor),
)
// Raylib uses standard C strings so isn't compatible with cheap slices, we need to clone the string to append null terminator
text := string(renderCommand.text.chars[:renderCommand.text.length])
cloned := strings.clone_to_cstring(text, allocator)
fontToUse: raylib.Font = raylibFonts[renderCommand.config.textElementConfig.fontId].font
raylib.DrawTextEx(
fontToUse,
cloned,
raylib.Vector2{boundingBox.x, boundingBox.y},
cast(f32)renderCommand.config.textElementConfig.fontSize,
cast(f32)renderCommand.config.textElementConfig.letterSpacing,
clayColorToRaylibColor(renderCommand.config.textElementConfig.textColor),
)
case clay.RenderCommandType.Image:
// TODO image handling
imageTexture := cast(^raylib.Texture2D)renderCommand.config.imageElementConfig.imageData