mirror of
https://github.com/nicbarker/clay.git
synced 2025-05-17 07:48:02 +00:00
Compare commits
8 Commits
a6dd21d4b1
...
2eed8a9e7d
Author | SHA1 | Date | |
---|---|---|---|
|
2eed8a9e7d | ||
|
5009146c65 | ||
|
865b06d386 | ||
|
12319fc240 | ||
|
2d7d5bc082 | ||
|
ea3e29be5c | ||
|
134beca09c | ||
|
b3cdf90d39 |
@ -89,7 +89,7 @@ int main() {
|
|||||||
CLAY({
|
CLAY({
|
||||||
.id = CLAY_ID("SideBar"),
|
.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 },
|
.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("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} } }) {}
|
CLAY({ .id = CLAY_ID("ProfilePicture"), .layout = { .sizing = { .width = CLAY_SIZING_FIXED(60), .height = CLAY_SIZING_FIXED(60) }}, .image = { .imageData = &profilePicture, .sourceDimensions = {60, 60} } }) {}
|
||||||
|
5
bindings/D/README.md
Normal file
5
bindings/D/README.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
### D Language Example
|
||||||
|
|
||||||
|
```
|
||||||
|
dmd main.d clay.c
|
||||||
|
```
|
2
bindings/D/clay.c
Normal file
2
bindings/D/clay.c
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
#define CLAY_IMPLEMENTATION
|
||||||
|
#include "../../clay.h"
|
88
bindings/D/main.d
Normal file
88
bindings/D/main.d
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
import clay;
|
||||||
|
|
||||||
|
import core.stdc.stdlib;
|
||||||
|
|
||||||
|
__gshared:
|
||||||
|
|
||||||
|
Clay_LayoutConfig layoutElement = { padding: {5} };
|
||||||
|
|
||||||
|
extern(C) void main()
|
||||||
|
{
|
||||||
|
ulong totalMemorySize = Clay_MinMemorySize();
|
||||||
|
Clay_Arena clayMemory = {
|
||||||
|
label: str("Clay Memory Arena"),
|
||||||
|
capacity: totalMemorySize,
|
||||||
|
memory: cast(char*)malloc(totalMemorySize)
|
||||||
|
};
|
||||||
|
|
||||||
|
Clay_Initialize(clayMemory, Clay_Dimensions(1024,768));
|
||||||
|
Clay_BeginLayout();
|
||||||
|
if (ClayBegin( Rectangle(color: Clay_Color(255,255,255,0)), Layout(layoutElement)))
|
||||||
|
{ }
|
||||||
|
ClayEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// helper functions
|
||||||
|
Clay_String str(string it)
|
||||||
|
{
|
||||||
|
return Clay_String(cast(int)it.length, it.ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ClayBegin(A...)(A configs)
|
||||||
|
{
|
||||||
|
Clay__OpenElement();
|
||||||
|
foreach(config; configs)
|
||||||
|
{
|
||||||
|
alias T = typeof(config);
|
||||||
|
static if (is(T == Clay_ElementId))
|
||||||
|
{
|
||||||
|
Clay__AttachId(config);
|
||||||
|
}
|
||||||
|
else static if(is(T == Clay_LayoutConfig*))
|
||||||
|
{
|
||||||
|
Clay__AttachLayoutConfig(config);
|
||||||
|
}
|
||||||
|
else static if(is(T == Clay_ElementConfig))
|
||||||
|
{
|
||||||
|
Clay__AttachElementConfig(config.config, config.type);
|
||||||
|
}
|
||||||
|
else static assert(0, "unsupported " ~ typeof(config).stringof);
|
||||||
|
}
|
||||||
|
|
||||||
|
Clay__ElementPostConfiguration();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ClayEnd()
|
||||||
|
{
|
||||||
|
Clay__CloseElement();
|
||||||
|
}
|
||||||
|
|
||||||
|
Clay_ElementId Id(string label)
|
||||||
|
{
|
||||||
|
return Clay__HashString(str(label), 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
Clay_LayoutConfig* Layout(lazy Clay_Sizing sizing = Clay_Sizing.init)
|
||||||
|
{
|
||||||
|
Clay_LayoutConfig config;
|
||||||
|
config.sizing = sizing;
|
||||||
|
return Clay__StoreLayoutConfig(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
Clay_LayoutConfig* Layout(Clay_LayoutConfig config)
|
||||||
|
{
|
||||||
|
return Clay__StoreLayoutConfig(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
Clay_ElementConfig Rectangle(lazy Clay_Color color = Clay_Color.init)
|
||||||
|
{
|
||||||
|
Clay_RectangleElementConfig config;
|
||||||
|
config.color = color;
|
||||||
|
|
||||||
|
Clay_ElementConfig ret;
|
||||||
|
ret.type = Clay__ElementConfigType.CLAY__ELEMENT_CONFIG_TYPE_RECTANGLE;
|
||||||
|
ret.config.rectangleElementConfig = Clay__StoreRectangleElementConfig(config);
|
||||||
|
return ret;
|
||||||
|
}
|
@ -1,13 +1,13 @@
|
|||||||
cp ../../clay.h clay.c;
|
cp ../../clay.h clay.c;
|
||||||
# Intel Mac
|
# 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
|
# 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
|
# 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
|
# 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
|
# 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.o;
|
||||||
rm clay.c;
|
rm clay.c;
|
||||||
|
@ -36,7 +36,7 @@ Dimensions :: struct {
|
|||||||
|
|
||||||
Arena :: struct {
|
Arena :: struct {
|
||||||
nextAllocation: uintptr,
|
nextAllocation: uintptr,
|
||||||
capacity: uintptr,
|
capacity: c.size_t,
|
||||||
memory: [^]c.char,
|
memory: [^]c.char,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -367,7 +367,7 @@ Context :: struct {} // opaque structure, only use as a pointer
|
|||||||
@(link_prefix = "Clay_", default_calling_convention = "c")
|
@(link_prefix = "Clay_", default_calling_convention = "c")
|
||||||
foreign Clay {
|
foreign Clay {
|
||||||
MinMemorySize :: proc() -> u32 ---
|
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) ---
|
SetPointerState :: proc(position: Vector2, pointerDown: bool) ---
|
||||||
Initialize :: proc(arena: Arena, layoutDimensions: Dimensions, errorHandler: ErrorHandler) -> ^Context ---
|
Initialize :: proc(arena: Arena, layoutDimensions: Dimensions, errorHandler: ErrorHandler) -> ^Context ---
|
||||||
GetCurrentContext :: proc() -> ^Context ---
|
GetCurrentContext :: proc() -> ^Context ---
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -91,8 +91,11 @@ static inline Clay_Dimensions Raylib_MeasureText(Clay_StringSlice text, Clay_Tex
|
|||||||
float textHeight = config->fontSize;
|
float textHeight = config->fontSize;
|
||||||
Font* fonts = (Font*)userData;
|
Font* fonts = (Font*)userData;
|
||||||
Font fontToUse = fonts[config->fontId];
|
Font fontToUse = fonts[config->fontId];
|
||||||
// Font failed to load, likely the fonts are in the wrong place relative to the execution dir
|
// Font failed to load, likely the fonts are in the wrong place relative to the execution dir.
|
||||||
if (!fontToUse.glyphs) return textSize;
|
// 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;
|
float scaleFactor = config->fontSize/(float)fontToUse.baseSize;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user