mirror of
https://github.com/nicbarker/clay.git
synced 2025-05-15 14:58:03 +00:00
Compare commits
6 Commits
0d4597e8f6
...
73debc01f2
Author | SHA1 | Date | |
---|---|---|---|
|
73debc01f2 | ||
|
766325c395 | ||
|
5afdf3f8c9 | ||
|
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;
|
||||||
|
}
|
4
clay.h
4
clay.h
@ -1443,7 +1443,7 @@ Clay__MeasureTextCacheItem *Clay__MeasureTextCached(Clay_String *text, Clay_Text
|
|||||||
measured = Clay__MeasureTextCacheItemArray_Get(&context->measureTextHashMapInternal, newItemIndex);
|
measured = Clay__MeasureTextCacheItemArray_Get(&context->measureTextHashMapInternal, newItemIndex);
|
||||||
} else {
|
} else {
|
||||||
if (context->measureTextHashMapInternal.length == context->measureTextHashMapInternal.capacity - 1) {
|
if (context->measureTextHashMapInternal.length == context->measureTextHashMapInternal.capacity - 1) {
|
||||||
if (context->booleanWarnings.maxTextMeasureCacheExceeded) {
|
if (!context->booleanWarnings.maxTextMeasureCacheExceeded) {
|
||||||
context->errorHandler.errorHandlerFunction(CLAY__INIT(Clay_ErrorData) {
|
context->errorHandler.errorHandlerFunction(CLAY__INIT(Clay_ErrorData) {
|
||||||
.errorType = CLAY_ERROR_TYPE_ELEMENTS_CAPACITY_EXCEEDED,
|
.errorType = CLAY_ERROR_TYPE_ELEMENTS_CAPACITY_EXCEEDED,
|
||||||
.errorText = CLAY_STRING("Clay ran out of capacity while attempting to measure text elements. Try using Clay_SetMaxElementCount() with a higher value."),
|
.errorText = CLAY_STRING("Clay ran out of capacity while attempting to measure text elements. Try using Clay_SetMaxElementCount() with a higher value."),
|
||||||
@ -3589,7 +3589,7 @@ uint32_t Clay_MinMemorySize(void) {
|
|||||||
Clay_Context* currentContext = Clay_GetCurrentContext();
|
Clay_Context* currentContext = Clay_GetCurrentContext();
|
||||||
if (currentContext) {
|
if (currentContext) {
|
||||||
fakeContext.maxElementCount = currentContext->maxElementCount;
|
fakeContext.maxElementCount = currentContext->maxElementCount;
|
||||||
fakeContext.maxMeasureTextCacheWordCount = currentContext->maxElementCount;
|
fakeContext.maxMeasureTextCacheWordCount = currentContext->maxMeasureTextCacheWordCount;
|
||||||
}
|
}
|
||||||
// Reserve space in the arena for the context, important for calculating min memory size correctly
|
// Reserve space in the arena for the context, important for calculating min memory size correctly
|
||||||
Clay__Context_Allocate_Arena(&fakeContext.internalArena);
|
Clay__Context_Allocate_Arena(&fakeContext.internalArena);
|
||||||
|
Loading…
Reference in New Issue
Block a user