mirror of
https://github.com/nicbarker/clay.git
synced 2025-04-20 05:08:04 +00:00
Merge branch 'main' into main
This commit is contained in:
commit
99775ace5e
@ -1,7 +1,13 @@
|
|||||||
cp ../../clay.h clay.c;
|
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;
|
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;
|
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;
|
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;
|
clang -c -o clay-odin/wasm/clay.o -target wasm32 -nostdlib -static clay.c;
|
||||||
rm clay.o;
|
rm clay.o;
|
||||||
rm clay.c;
|
rm clay.c;
|
||||||
|
@ -6,7 +6,7 @@ import "core:strings"
|
|||||||
when ODIN_OS == .Windows {
|
when ODIN_OS == .Windows {
|
||||||
foreign import Clay "windows/clay.lib"
|
foreign import Clay "windows/clay.lib"
|
||||||
} else when ODIN_OS == .Linux {
|
} else when ODIN_OS == .Linux {
|
||||||
foreign import Clay "linux/libclay.a"
|
foreign import Clay "linux/clay.a"
|
||||||
} else when ODIN_OS == .Darwin {
|
} else when ODIN_OS == .Darwin {
|
||||||
when ODIN_ARCH == .arm64 {
|
when ODIN_ARCH == .arm64 {
|
||||||
foreign import Clay "macos-arm64/clay.a"
|
foreign import Clay "macos-arm64/clay.a"
|
||||||
@ -57,7 +57,13 @@ BorderData :: struct {
|
|||||||
color: Color,
|
color: Color,
|
||||||
}
|
}
|
||||||
|
|
||||||
RenderCommandType :: enum u8 {
|
when ODIN_OS == .Windows {
|
||||||
|
EnumBackingType :: u32
|
||||||
|
} else {
|
||||||
|
EnumBackingType :: u8
|
||||||
|
}
|
||||||
|
|
||||||
|
RenderCommandType :: enum EnumBackingType {
|
||||||
None,
|
None,
|
||||||
Rectangle,
|
Rectangle,
|
||||||
Border,
|
Border,
|
||||||
@ -104,7 +110,7 @@ ScrollElementConfig :: struct {
|
|||||||
vertical: bool,
|
vertical: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
FloatingAttachPointType :: enum u8 {
|
FloatingAttachPointType :: enum EnumBackingType {
|
||||||
LEFT_TOP,
|
LEFT_TOP,
|
||||||
LEFT_CENTER,
|
LEFT_CENTER,
|
||||||
LEFT_BOTTOM,
|
LEFT_BOTTOM,
|
||||||
@ -156,7 +162,7 @@ ScrollContainerData :: struct {
|
|||||||
found: bool,
|
found: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
SizingType :: enum u8 {
|
SizingType :: enum EnumBackingType {
|
||||||
FIT,
|
FIT,
|
||||||
GROW,
|
GROW,
|
||||||
PERCENT,
|
PERCENT,
|
||||||
@ -188,18 +194,18 @@ Padding :: struct {
|
|||||||
y: u16,
|
y: u16,
|
||||||
}
|
}
|
||||||
|
|
||||||
LayoutDirection :: enum u8 {
|
LayoutDirection :: enum EnumBackingType {
|
||||||
LEFT_TO_RIGHT,
|
LEFT_TO_RIGHT,
|
||||||
TOP_TO_BOTTOM,
|
TOP_TO_BOTTOM,
|
||||||
}
|
}
|
||||||
|
|
||||||
LayoutAlignmentX :: enum u8 {
|
LayoutAlignmentX :: enum EnumBackingType {
|
||||||
LEFT,
|
LEFT,
|
||||||
RIGHT,
|
RIGHT,
|
||||||
CENTER,
|
CENTER,
|
||||||
}
|
}
|
||||||
|
|
||||||
LayoutAlignmentY :: enum u8 {
|
LayoutAlignmentY :: enum EnumBackingType {
|
||||||
TOP,
|
TOP,
|
||||||
BOTTOM,
|
BOTTOM,
|
||||||
CENTER,
|
CENTER,
|
||||||
@ -240,7 +246,7 @@ foreign Clay {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@(private, link_prefix = "Clay_", default_calling_convention = "c")
|
@(private, link_prefix = "Clay_", default_calling_convention = "c")
|
||||||
foreign {
|
foreign _ {
|
||||||
_layoutConfigs: ClayArray(LayoutConfig)
|
_layoutConfigs: ClayArray(LayoutConfig)
|
||||||
_rectangleElementConfigs: ClayArray(RectangleElementConfig)
|
_rectangleElementConfigs: ClayArray(RectangleElementConfig)
|
||||||
_textElementConfigs: ClayArray(TextElementConfig)
|
_textElementConfigs: ClayArray(TextElementConfig)
|
||||||
|
BIN
bindings/odin/clay-odin/linux/clay.a
Normal file
BIN
bindings/odin/clay-odin/linux/clay.a
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -229,14 +229,14 @@ DeclarativeSyntaxPageDesktop :: proc() {
|
|||||||
clay.Layout({sizing = {clay.SizingGrow({}), clay.SizingGrow({})}, childAlignment = {y = .CENTER}, padding = {32, 32}, childGap = 32}),
|
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}}),
|
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() {
|
DeclarativeSyntaxPageMobile :: proc() {
|
||||||
if clay.Container(
|
if clay.Container(
|
||||||
clay.ID("SyntaxPageDesktop"),
|
clay.ID("SyntaxPageMobile"),
|
||||||
clay.Layout(
|
clay.Layout(
|
||||||
{
|
{
|
||||||
layoutDirection = .TOP_TO_BOTTOM,
|
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"))
|
checkImage5 = raylib.LoadTextureFromImage(raylib.LoadImage("resources/check_5.png"))
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !raylib.WindowShouldClose() {
|
||||||
|
defer free_all(context.temp_allocator)
|
||||||
|
|
||||||
animationLerpValue += raylib.GetFrameTime()
|
animationLerpValue += raylib.GetFrameTime()
|
||||||
if animationLerpValue > 1 {
|
if animationLerpValue > 1 {
|
||||||
animationLerpValue = animationLerpValue - 2
|
animationLerpValue = animationLerpValue - 2
|
||||||
|
@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import clay "../../clay-odin"
|
import clay "../../clay-odin"
|
||||||
import "core:math"
|
import "core:math"
|
||||||
|
import "core:strings"
|
||||||
import "vendor:raylib"
|
import "vendor:raylib"
|
||||||
|
|
||||||
RaylibFont :: struct {
|
RaylibFont :: struct {
|
||||||
@ -47,7 +48,7 @@ measureText :: proc "c" (text: ^clay.String, config: ^clay.TextElementConfig) ->
|
|||||||
return textSize
|
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) {
|
for i in 0..<int(renderCommands.length) {
|
||||||
renderCommand := clay.RenderCommandArray_Get(renderCommands, cast(i32)i)
|
renderCommand := clay.RenderCommandArray_Get(renderCommands, cast(i32)i)
|
||||||
boundingBox := renderCommand.boundingBox
|
boundingBox := renderCommand.boundingBox
|
||||||
@ -56,15 +57,12 @@ clayRaylibRender :: proc(renderCommands: ^clay.ClayArray(clay.RenderCommand)) {
|
|||||||
{}
|
{}
|
||||||
case clay.RenderCommandType.Text:
|
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
|
// 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
|
text := string(renderCommand.text.chars[:renderCommand.text.length])
|
||||||
cloned := make([]u8, text.length + 1, context.temp_allocator)
|
cloned := strings.clone_to_cstring(text, allocator)
|
||||||
copy(cloned[:text.length], text.chars[:text.length])
|
|
||||||
cloned[text.length] = 0
|
|
||||||
|
|
||||||
fontToUse: raylib.Font = raylibFonts[renderCommand.config.textElementConfig.fontId].font
|
fontToUse: raylib.Font = raylibFonts[renderCommand.config.textElementConfig.fontId].font
|
||||||
raylib.DrawTextEx(
|
raylib.DrawTextEx(
|
||||||
fontToUse,
|
fontToUse,
|
||||||
cstring(raw_data(cloned)),
|
cloned,
|
||||||
raylib.Vector2{boundingBox.x, boundingBox.y},
|
raylib.Vector2{boundingBox.x, boundingBox.y},
|
||||||
cast(f32)renderCommand.config.textElementConfig.fontSize,
|
cast(f32)renderCommand.config.textElementConfig.fontSize,
|
||||||
cast(f32)renderCommand.config.textElementConfig.letterSpacing,
|
cast(f32)renderCommand.config.textElementConfig.letterSpacing,
|
||||||
|
Loading…
Reference in New Issue
Block a user