mirror of
https://github.com/nicbarker/clay.git
synced 2025-04-23 22:58:06 +00:00
Compare commits
10 Commits
9f4756bdcb
...
c7a381ebc5
Author | SHA1 | Date | |
---|---|---|---|
|
c7a381ebc5 | ||
|
982ade4cf9 | ||
|
d5af2c3dc0 | ||
|
2677bec854 | ||
|
05ac2810d8 | ||
|
1f8cab8d72 | ||
|
6186596b41 | ||
|
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;
|
||||
}
|
9
clay.h
9
clay.h
@ -102,6 +102,10 @@
|
||||
|
||||
static uint8_t CLAY__ELEMENT_DEFINITION_LATCH;
|
||||
|
||||
// GCC marks the above CLAY__ELEMENT_DEFINITION_LATCH as an unused variable for files that include clay.h but don't declare any layout
|
||||
// This is to suppress that warning
|
||||
static inline void Clay__SuppressUnusedLatchDefinitionVariableWarning(void) { (void) CLAY__ELEMENT_DEFINITION_LATCH; }
|
||||
|
||||
// Publicly visible layout element macros -----------------------------------------------------
|
||||
|
||||
/* This macro looks scary on the surface, but is actually quite simple.
|
||||
@ -1654,6 +1658,8 @@ void Clay__CloseElement(void) {
|
||||
elementHasScrollVertical = config->config.scrollElementConfig->vertical;
|
||||
context->openClipElementStack.length--;
|
||||
break;
|
||||
} else if (config->type == CLAY__ELEMENT_CONFIG_TYPE_FLOATING) {
|
||||
context->openClipElementStack.length--;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1933,6 +1939,9 @@ void Clay__ConfigureOpenElementPtr(const Clay_ElementDeclaration *declaration) {
|
||||
if (!openLayoutElementId.id) {
|
||||
openLayoutElementId = Clay__HashString(CLAY_STRING("Clay__FloatingContainer"), context->layoutElementTreeRoots.length, 0);
|
||||
}
|
||||
int32_t currentElementIndex = Clay__int32_tArray_GetValue(&context->openLayoutElementStack, context->openLayoutElementStack.length - 1);
|
||||
Clay__int32_tArray_Set(&context->layoutElementClipElementIds, currentElementIndex, clipElementId);
|
||||
Clay__int32_tArray_Add(&context->openClipElementStack, clipElementId);
|
||||
Clay__LayoutElementTreeRootArray_Add(&context->layoutElementTreeRoots, CLAY__INIT(Clay__LayoutElementTreeRoot) {
|
||||
.layoutElementIndex = Clay__int32_tArray_GetValue(&context->openLayoutElementStack, context->openLayoutElementStack.length - 1),
|
||||
.parentId = floatingConfig.parentId,
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include <SDL_ttf.h>
|
||||
#include <SDL_image.h>
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159
|
||||
|
Loading…
Reference in New Issue
Block a user