mirror of
https://github.com/nicbarker/clay.git
synced 2025-05-07 02:48:04 +00:00
Compare commits
5 Commits
211333b21b
...
7cf30aa6ba
Author | SHA1 | Date | |
---|---|---|---|
|
7cf30aa6ba | ||
|
208c7cb3a0 | ||
|
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;
|
||||||
|
}
|
7
clay.h
7
clay.h
@ -2804,7 +2804,8 @@ void Clay__CalculateFinalLayout() {
|
|||||||
Clay__AddRenderCommand(renderCommand);
|
Clay__AddRenderCommand(renderCommand);
|
||||||
if (borderConfig->betweenChildren.width > 0 && borderConfig->betweenChildren.color.a > 0) {
|
if (borderConfig->betweenChildren.width > 0 && borderConfig->betweenChildren.color.a > 0) {
|
||||||
Clay_RectangleElementConfig *rectangleConfig = Clay__StoreRectangleElementConfig(CLAY__INIT(Clay_RectangleElementConfig) {.color = borderConfig->betweenChildren.color});
|
Clay_RectangleElementConfig *rectangleConfig = Clay__StoreRectangleElementConfig(CLAY__INIT(Clay_RectangleElementConfig) {.color = borderConfig->betweenChildren.color});
|
||||||
Clay_Vector2 borderOffset = { (float)layoutConfig->padding.x, (float)layoutConfig->padding.y };
|
float halfGap = layoutConfig->childGap / 2;
|
||||||
|
Clay_Vector2 borderOffset = { (float)layoutConfig->padding.x - halfGap, (float)layoutConfig->padding.y - halfGap };
|
||||||
if (layoutConfig->layoutDirection == CLAY_LEFT_TO_RIGHT) {
|
if (layoutConfig->layoutDirection == CLAY_LEFT_TO_RIGHT) {
|
||||||
for (int32_t i = 0; i < currentElement->childrenOrTextContent.children.length; ++i) {
|
for (int32_t i = 0; i < currentElement->childrenOrTextContent.children.length; ++i) {
|
||||||
Clay_LayoutElement *childElement = Clay_LayoutElementArray_Get(&context->layoutElements, currentElement->childrenOrTextContent.children.elements[i]);
|
Clay_LayoutElement *childElement = Clay_LayoutElementArray_Get(&context->layoutElements, currentElement->childrenOrTextContent.children.elements[i]);
|
||||||
@ -2816,7 +2817,7 @@ void Clay__CalculateFinalLayout() {
|
|||||||
.commandType = CLAY_RENDER_COMMAND_TYPE_RECTANGLE,
|
.commandType = CLAY_RENDER_COMMAND_TYPE_RECTANGLE,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
borderOffset.x += (childElement->dimensions.width + (float)layoutConfig->childGap / 2);
|
borderOffset.x += (childElement->dimensions.width + (float)layoutConfig->childGap);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (int32_t i = 0; i < currentElement->childrenOrTextContent.children.length; ++i) {
|
for (int32_t i = 0; i < currentElement->childrenOrTextContent.children.length; ++i) {
|
||||||
@ -2829,7 +2830,7 @@ void Clay__CalculateFinalLayout() {
|
|||||||
.commandType = CLAY_RENDER_COMMAND_TYPE_RECTANGLE,
|
.commandType = CLAY_RENDER_COMMAND_TYPE_RECTANGLE,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
borderOffset.y += (childElement->dimensions.height + (float)layoutConfig->childGap / 2);
|
borderOffset.y += (childElement->dimensions.height + (float)layoutConfig->childGap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user