Compare commits

...

6 Commits

Author SHA1 Message Date
bangbangsheshotmedown
6ac96be2dc
Merge ea3e29be5c into a9e94e3be0 2025-04-05 00:56:07 +02:00
Nic Barker
a9e94e3be0 [Core] Fix onHover reference not being reset for identical IDs between frames
Some checks failed
CMake on multiple platforms / build (Release, cl, cl, windows-latest) (push) Has been cancelled
CMake on multiple platforms / build (Release, clang, clang++, ubuntu-latest) (push) Has been cancelled
CMake on multiple platforms / build (Release, gcc, g++, ubuntu-latest) (push) Has been cancelled
2025-04-04 13:05:31 +13:00
Nic Barker
cbb50267da [CMake] Revert change to CMakeLists because of OSX problems 2025-04-04 12:59:57 +13:00
bangbangsheshotmedown
ea3e29be5c
Create README.md 2024-10-29 19:53:11 +00:00
bangbangsheshotmedown
134beca09c
Add C file 2024-10-29 19:50:51 +00:00
bangbangsheshotmedown
b3cdf90d39
Add D example 2024-10-29 19:50:13 +00:00
10 changed files with 99 additions and 2 deletions

View File

@ -39,5 +39,5 @@ endif()
# add_subdirectory("examples/cairo-pdf-rendering") Some issue with github actions populating cairo, disable for now
add_library(${PROJECT_NAME} INTERFACE)
target_include_directories(${PROJECT_NAME} INTERFACE .)
#add_library(${PROJECT_NAME} INTERFACE)
#target_include_directories(${PROJECT_NAME} INTERFACE .)

5
bindings/D/README.md Normal file
View File

@ -0,0 +1,5 @@
### D Language Example
```
dmd main.d clay.c
```

2
bindings/D/clay.c Normal file
View File

@ -0,0 +1,2 @@
#define CLAY_IMPLEMENTATION
#include "../../clay.h"

88
bindings/D/main.d Normal file
View 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;
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

2
clay.h
View File

@ -1670,6 +1670,8 @@ Clay_LayoutElementHashMapItem* Clay__AddHashMapItem(Clay_ElementId elementId, Cl
hashItem->generation = context->generation + 1;
hashItem->layoutElement = layoutElement;
hashItem->debugData->collision = false;
hashItem->onHoverFunction = NULL;
hashItem->hoverFunctionUserData = 0;
} else { // Multiple collisions this frame - two elements have the same ID
context->errorHandler.errorHandlerFunction(CLAY__INIT(Clay_ErrorData) {
.errorType = CLAY_ERROR_TYPE_DUPLICATE_ID,