mirror of
https://github.com/nicbarker/clay.git
synced 2025-05-02 16:38:06 +00:00
Compare commits
7 Commits
2c53e5cfee
...
62e8084549
Author | SHA1 | Date | |
---|---|---|---|
|
62e8084549 | ||
|
3f01ee4a4e | ||
|
a431254de4 | ||
|
7cc719e61f | ||
|
ea3e29be5c | ||
|
134beca09c | ||
|
b3cdf90d39 |
@ -8,7 +8,7 @@ add_subdirectory("examples/cpp-project-example")
|
||||
# Don't try to compile C99 projects using MSVC
|
||||
if(NOT MSVC)
|
||||
add_subdirectory("examples/raylib-sidebar-scrolling-container")
|
||||
add_subdirectory("examples/cairo-pdf-rendering")
|
||||
# add_subdirectory("examples/cairo-pdf-rendering") Some issue with github actions populating cairo, disable for now
|
||||
add_subdirectory("examples/clay-official-website")
|
||||
add_subdirectory("examples/introducing-clay-video-demo")
|
||||
add_subdirectory("examples/SDL2-video-demo")
|
||||
|
@ -100,7 +100,7 @@ Clay_RenderCommandArray CreateLayout() {
|
||||
CLAY_RECTANGLE({ .color = COLOR_LIGHT })
|
||||
) {
|
||||
CLAY(CLAY_ID("ProfilePictureOuter"), CLAY_LAYOUT({ .sizing = { .width = CLAY_SIZING_GROW() }, .padding = {16, 16}, .childGap = 16, .childAlignment = { .y = CLAY_ALIGN_Y_CENTER }), CLAY_RECTANGLE({ .color = COLOR_RED })) {
|
||||
CLAY(CLAY_ID("ProfilePicture"), CLAY_LAYOUT({ .sizing = { .width = CLAY_SIZING_FIXED(60), .height = CLAY_SIZING_FIXED(60) }}), CLAY_IMAGE({ .imageData = &profilePicture, .height = 60, .width = 60 })) {}
|
||||
CLAY(CLAY_ID("ProfilePicture"), CLAY_LAYOUT({ .sizing = { .width = CLAY_SIZING_FIXED(60), .height = CLAY_SIZING_FIXED(60) }}), CLAY_IMAGE({ .imageData = &profilePicture, .sourceDimensions = {60, 60} })) {}
|
||||
CLAY_TEXT(CLAY_STRING("Clay - UI Library"), CLAY_TEXT_CONFIG({ .fontSize = 24, .textColor = {255, 255, 255, 255} }));
|
||||
}
|
||||
|
||||
@ -1059,11 +1059,11 @@ CLAY(CLAY_IMAGE({ .image = { .format = IMAGE_FORMAT_RGBA, .internalData = &image
|
||||
// Load an image somewhere in your code
|
||||
Image profilePicture = LoadImage("profilePicture.png");
|
||||
// Declare a reusable image config
|
||||
Clay_ImageElementConfig imageConfig = (Clay_ImageElementConfig) { .imageData = &profilePicture, .height = 60, .width = 60 };
|
||||
Clay_ImageElementConfig imageConfig = (Clay_ImageElementConfig) { .imageData = &profilePicture, .sourceDimensions = {60, 60} };
|
||||
// Declare an image element using a reusable config
|
||||
CLAY(CLAY_IMAGE(imageConfig)) {}
|
||||
// Declare an image element using an inline config
|
||||
CLAY(CLAY_IMAGE({ .imageData = &profilePicture, .height = 60, .width = 60 })) {}
|
||||
CLAY(CLAY_IMAGE({ .imageData = &profilePicture, .sourceDimensions = {60, 60} })) {}
|
||||
// Rendering example
|
||||
Image *imageToRender = renderCommand->elementConfig.imageElementConfig->imageData;
|
||||
```
|
||||
|
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;
|
||||
}
|
8
clay.h
8
clay.h
@ -21,6 +21,14 @@
|
||||
#ifndef CLAY_HEADER
|
||||
#define CLAY_HEADER
|
||||
|
||||
#if !( \
|
||||
(defined(__cplusplus) && __cplusplus >= 202002L) || \
|
||||
(defined(__STDC__) && __STDC__ == 1 && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
|
||||
defined(_MSC_VER) \
|
||||
)
|
||||
#error "Clay requires C99, C++20, or MSVC"
|
||||
#endif
|
||||
|
||||
#ifdef CLAY_WASM
|
||||
#define CLAY_WASM_EXPORT(name) __attribute__((export_name(name)))
|
||||
#else
|
||||
|
Loading…
Reference in New Issue
Block a user