mirror of
https://github.com/nicbarker/clay.git
synced 2025-05-17 15:58:05 +00:00
Compare commits
8 Commits
2eed8a9e7d
...
a4f0a5f51a
Author | SHA1 | Date | |
---|---|---|---|
|
a4f0a5f51a | ||
|
19a27b39f2 | ||
|
22e8cc318c | ||
|
8e6640f7a2 | ||
|
4f8957d5d2 | ||
|
ea3e29be5c | ||
|
134beca09c | ||
|
b3cdf90d39 |
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;
|
||||
}
|
@ -102,6 +102,7 @@ TextAlignment :: enum EnumBackingType {
|
||||
}
|
||||
|
||||
TextElementConfig :: struct {
|
||||
userData: rawptr,
|
||||
textColor: Color,
|
||||
fontId: u16,
|
||||
fontSize: u16,
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -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 })
|
||||
|
8
clay.h
8
clay.h
@ -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,
|
||||
|
@ -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' },
|
||||
|
Binary file not shown.
@ -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' },
|
||||
|
Loading…
Reference in New Issue
Block a user