Compare commits

...

9 Commits

Author SHA1 Message Date
TotallyGamerJet
0b0140753e
Merge 63d3af6372 into b33ba4ff62 2025-04-16 23:19:03 +02:00
Nic Barker
b33ba4ff62
[Core] Fix a string hash bug with single characters (#384)
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-16 20:16:05 +12:00
Jackson Novak
f88f0517f7
[Documentation] Fix Clay_String definition in README.md file. (#374) 2025-04-16 20:07:16 +12:00
Tim Lügger
5391a259f3
[Renderers/Raylib] Fix raylib renderer border bottom left corner radius (#378)
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-14 14:26:12 +12:00
Lily Nikitin
fe2d44a888
[Renderers/Raylib] Add explicit type cast for malloc (#379) 2025-04-14 14:23:13 +12:00
TotallyGamerJet
63d3af6372
remove unnecessary cast 2025-03-20 21:54:25 -04:00
TotallyGamerJet
6935abbbfb
fix other files too 2025-03-20 21:47:09 -04:00
TotallyGamerJet
80caa0f4e7
update signature of debug view close button handler 2025-03-20 21:28:28 -04:00
TotallyGamerJet
f298e34bdc
clay.h: update Clay_OnHover to take void* 2025-03-20 10:45:44 -04:00
6 changed files with 27 additions and 17 deletions

View File

@ -313,7 +313,7 @@ CLAY({ .backgroundColor = Clay_Hovered() ? COLOR_BLUE : COLOR_ORANGE }) {
The function `void Clay_OnHover()` allows you to attach a function pointer to the currently open element, which will be called if the mouse / pointer is over the element. The function `void Clay_OnHover()` allows you to attach a function pointer to the currently open element, which will be called if the mouse / pointer is over the element.
```C ```C
void HandleButtonInteraction(Clay_ElementId elementId, Clay_PointerData pointerInfo, intptr_t userData) { void HandleButtonInteraction(Clay_ElementId elementId, Clay_PointerData pointerInfo, void *userData) {
ButtonData *buttonData = (ButtonData *)userData; ButtonData *buttonData = (ButtonData *)userData;
// Pointer state allows you to detect mouse down / hold / release // Pointer state allows you to detect mouse down / hold / release
if (pointerInfo.state == CLAY_POINTER_DATA_PRESSED_THIS_FRAME) { if (pointerInfo.state == CLAY_POINTER_DATA_PRESSED_THIS_FRAME) {
@ -684,12 +684,12 @@ Called **during** layout declaration, and returns `true` if the pointer position
### Clay_OnHover ### Clay_OnHover
`void Clay_OnHover(void (*onHoverFunction)(Clay_ElementId elementId, Clay_PointerData pointerData, intptr_t userData), intptr_t userData)` `void Clay_OnHover(void (*onHoverFunction)(Clay_ElementId elementId, Clay_PointerData pointerData, void *userData), void *userData)`
Called **during** layout declaration, this function allows you to attach a function pointer to the currently open element that will be called once per layout if the pointer position previously set with `Clay_SetPointerState` is inside the bounding box of the currently open element. See [Clay_PointerData](#clay_pointerdata) for more information on the `pointerData` argument. Called **during** layout declaration, this function allows you to attach a function pointer to the currently open element that will be called once per layout if the pointer position previously set with `Clay_SetPointerState` is inside the bounding box of the currently open element. See [Clay_PointerData](#clay_pointerdata) for more information on the `pointerData` argument.
```C ```C
void HandleButtonInteraction(Clay_ElementId elementId, Clay_PointerData pointerData, intptr_t userData) { void HandleButtonInteraction(Clay_ElementId elementId, Clay_PointerData pointerData, void *userData) {
ButtonData *buttonData = (ButtonData *)userData; ButtonData *buttonData = (ButtonData *)userData;
// Pointer state allows you to detect mouse down / hold / release // Pointer state allows you to detect mouse down / hold / release
if (pointerData.state == CLAY_POINTER_DATA_PRESSED_THIS_FRAME) { if (pointerData.state == CLAY_POINTER_DATA_PRESSED_THIS_FRAME) {
@ -1787,7 +1787,8 @@ Note: when using the debug tools, their internal colors are represented as 0-255
```C ```C
typedef struct { typedef struct {
int length; bool isStaticallyAllocated;
int32_t length;
const char *chars; const char *chars;
} Clay_String; } Clay_String;
``` ```
@ -1796,7 +1797,14 @@ typedef struct {
**Fields** **Fields**
**`.length`** - `int` **`.isStaticallyAllocated`** - `bool`
Whether or not the string is statically allocated, or in other words, whether
or not it lives for the entire lifetime of the program.
---
**`.length`** - `int32_t`
The number of characters in the string, _not including an optional null terminator._ The number of characters in the string, _not including an optional null terminator._

12
clay.h
View File

@ -840,7 +840,7 @@ CLAY_DLL_EXPORT bool Clay_Hovered(void);
// Bind a callback that will be called when the pointer position provided by Clay_SetPointerState is within the current element's bounding box. // Bind a callback that will be called when the pointer position provided by Clay_SetPointerState is within the current element's bounding box.
// - onHoverFunction is a function pointer to a user defined function. // - onHoverFunction is a function pointer to a user defined function.
// - userData is a pointer that will be transparently passed through when the onHoverFunction is called. // - userData is a pointer that will be transparently passed through when the onHoverFunction is called.
CLAY_DLL_EXPORT void Clay_OnHover(void (*onHoverFunction)(Clay_ElementId elementId, Clay_PointerData pointerData, intptr_t userData), intptr_t userData); CLAY_DLL_EXPORT void Clay_OnHover(void (*onHoverFunction)(Clay_ElementId elementId, Clay_PointerData pointerData, void *userData), void *userData);
// An imperative function that returns true if the pointer position provided by Clay_SetPointerState is within the element with the provided ID's bounding box. // An imperative function that returns true if the pointer position provided by Clay_SetPointerState is within the element with the provided ID's bounding box.
// This ID can be calculated either with CLAY_ID() for string literal IDs, or Clay_GetElementId for dynamic strings. // This ID can be calculated either with CLAY_ID() for string literal IDs, or Clay_GetElementId for dynamic strings.
CLAY_DLL_EXPORT bool Clay_PointerOver(Clay_ElementId elementId); CLAY_DLL_EXPORT bool Clay_PointerOver(Clay_ElementId elementId);
@ -1132,8 +1132,8 @@ typedef struct { // todo get this struct into a single cache line
Clay_BoundingBox boundingBox; Clay_BoundingBox boundingBox;
Clay_ElementId elementId; Clay_ElementId elementId;
Clay_LayoutElement* layoutElement; Clay_LayoutElement* layoutElement;
void (*onHoverFunction)(Clay_ElementId elementId, Clay_PointerData pointerInfo, intptr_t userData); void (*onHoverFunction)(Clay_ElementId elementId, Clay_PointerData pointerInfo, void *userData);
intptr_t hoverFunctionUserData; void *hoverFunctionUserData;
int32_t nextIndex; int32_t nextIndex;
uint32_t generation; uint32_t generation;
uint32_t idAlias; uint32_t idAlias;
@ -1392,6 +1392,7 @@ uint64_t Clay__HashData(const uint8_t* data, size_t length) {
Clay__SIMDARXMix(&v2, &v3); Clay__SIMDARXMix(&v2, &v3);
v0 = _mm_add_epi64(v0, v2); v0 = _mm_add_epi64(v0, v2);
v1 = _mm_add_epi64(v1, v3); v1 = _mm_add_epi64(v1, v3);
v0 = _mm_add_epi64(v0, v1);
uint64_t result[2]; uint64_t result[2];
_mm_storeu_si128((__m128i*)result, v0); _mm_storeu_si128((__m128i*)result, v0);
@ -1445,6 +1446,7 @@ uint64_t Clay__HashData(const uint8_t* data, size_t length) {
Clay__SIMDARXMix(&v2, &v3); Clay__SIMDARXMix(&v2, &v3);
v0 = vaddq_u64(v0, v2); v0 = vaddq_u64(v0, v2);
v1 = vaddq_u64(v1, v3); v1 = vaddq_u64(v1, v3);
v0 = vaddq_u64(v0, v1);
uint64_t result[2]; uint64_t result[2];
vst1q_u64(result, v0); vst1q_u64(result, v0);
@ -3316,7 +3318,7 @@ void Clay__RenderDebugViewCornerRadius(Clay_CornerRadius cornerRadius, Clay_Text
} }
} }
void HandleDebugViewCloseButtonInteraction(Clay_ElementId elementId, Clay_PointerData pointerInfo, intptr_t userData) { void HandleDebugViewCloseButtonInteraction(Clay_ElementId elementId, Clay_PointerData pointerInfo, void *userData) {
Clay_Context* context = Clay_GetCurrentContext(); Clay_Context* context = Clay_GetCurrentContext();
(void) elementId; (void) pointerInfo; (void) userData; (void) elementId; (void) pointerInfo; (void) userData;
if (pointerInfo.state == CLAY_POINTER_DATA_PRESSED_THIS_FRAME) { if (pointerInfo.state == CLAY_POINTER_DATA_PRESSED_THIS_FRAME) {
@ -4087,7 +4089,7 @@ bool Clay_Hovered(void) {
return false; return false;
} }
void Clay_OnHover(void (*onHoverFunction)(Clay_ElementId elementId, Clay_PointerData pointerInfo, intptr_t userData), intptr_t userData) { void Clay_OnHover(void (*onHoverFunction)(Clay_ElementId elementId, Clay_PointerData pointerInfo, void *userData), void *userData) {
Clay_Context* context = Clay_GetCurrentContext(); Clay_Context* context = Clay_GetCurrentContext();
if (context->booleanWarnings.maxElementsExceeded) { if (context->booleanWarnings.maxElementsExceeded) {
return; return;

View File

@ -232,7 +232,7 @@ void HighPerformancePageMobile(float lerpValue) {
} }
} }
void HandleRendererButtonInteraction(Clay_ElementId elementId, Clay_PointerData pointerInfo, intptr_t userData) { void HandleRendererButtonInteraction(Clay_ElementId elementId, Clay_PointerData pointerInfo, void *userData) {
if (pointerInfo.state == CLAY_POINTER_DATA_PRESSED_THIS_FRAME) { if (pointerInfo.state == CLAY_POINTER_DATA_PRESSED_THIS_FRAME) {
ACTIVE_RENDERER_INDEX = (uint32_t)userData; ACTIVE_RENDERER_INDEX = (uint32_t)userData;
Clay_SetCullingEnabled(ACTIVE_RENDERER_INDEX == 1); Clay_SetCullingEnabled(ACTIVE_RENDERER_INDEX == 1);
@ -259,7 +259,7 @@ void RendererButtonInactive(Clay_String text, size_t rendererIndex) {
.cornerRadius = CLAY_CORNER_RADIUS(10), .cornerRadius = CLAY_CORNER_RADIUS(10),
.userData = FrameAllocateCustomData((CustomHTMLData) { .disablePointerEvents = true, .cursorPointer = true }) .userData = FrameAllocateCustomData((CustomHTMLData) { .disablePointerEvents = true, .cursorPointer = true })
}) { }) {
Clay_OnHover(HandleRendererButtonInteraction, rendererIndex); Clay_OnHover(HandleRendererButtonInteraction, (void *)rendererIndex);
CLAY_TEXT(text, CLAY_TEXT_CONFIG({ .fontSize = 28, .fontId = FONT_ID_BODY_36, .textColor = COLOR_RED })); CLAY_TEXT(text, CLAY_TEXT_CONFIG({ .fontSize = 28, .fontId = FONT_ID_BODY_36, .textColor = COLOR_RED }));
} }
} }

View File

@ -64,7 +64,7 @@ typedef struct {
void HandleSidebarInteraction( void HandleSidebarInteraction(
Clay_ElementId elementId, Clay_ElementId elementId,
Clay_PointerData pointerData, Clay_PointerData pointerData,
intptr_t userData void *userData
) { ) {
SidebarClickData *clickData = (SidebarClickData*)userData; SidebarClickData *clickData = (SidebarClickData*)userData;
// If this button was clicked // If this button was clicked
@ -222,7 +222,7 @@ Clay_RenderCommandArray ClayVideoDemo_CreateLayout(ClayVideoDemo_Data *data) {
*clickData = (SidebarClickData) { .requestedDocumentIndex = i, .selectedDocumentIndex = &data->selectedDocumentIndex }; *clickData = (SidebarClickData) { .requestedDocumentIndex = i, .selectedDocumentIndex = &data->selectedDocumentIndex };
data->frameArena.offset += sizeof(SidebarClickData); data->frameArena.offset += sizeof(SidebarClickData);
CLAY({ .layout = sidebarButtonLayout, .backgroundColor = (Clay_Color) { 120, 120, 120, Clay_Hovered() ? 120 : 0 }, .cornerRadius = CLAY_CORNER_RADIUS(8) }) { CLAY({ .layout = sidebarButtonLayout, .backgroundColor = (Clay_Color) { 120, 120, 120, Clay_Hovered() ? 120 : 0 }, .cornerRadius = CLAY_CORNER_RADIUS(8) }) {
Clay_OnHover(HandleSidebarInteraction, (intptr_t)clickData); Clay_OnHover(HandleSidebarInteraction, clickData);
CLAY_TEXT(document.title, CLAY_TEXT_CONFIG({ CLAY_TEXT(document.title, CLAY_TEXT_CONFIG({
.fontId = FONT_ID_BODY_16, .fontId = FONT_ID_BODY_16,
.fontSize = 20, .fontSize = 20,

View File

@ -22,7 +22,7 @@ FetchContent_MakeAvailable(fontstash)
FetchContent_Declare( FetchContent_Declare(
sokol sokol
GIT_REPOSITORY "https://github.com/floooh/sokol.git" GIT_REPOSITORY "https://github.com/floooh/sokol.git"
GIT_TAG "da9de496f938b7575eff7f01ab774d77469bd390" GIT_TAG "master"
GIT_PROGRESS TRUE GIT_PROGRESS TRUE
GIT_SHALLOW TRUE GIT_SHALLOW TRUE
) )

View File

@ -157,7 +157,7 @@ void Clay_Raylib_Render(Clay_RenderCommandArray renderCommands, Font* fonts)
if(strlen > temp_render_buffer_len) { if(strlen > temp_render_buffer_len) {
// Grow the temp buffer if we need a larger string // Grow the temp buffer if we need a larger string
if(temp_render_buffer) free(temp_render_buffer); if(temp_render_buffer) free(temp_render_buffer);
temp_render_buffer = malloc(strlen); temp_render_buffer = (char *) malloc(strlen);
temp_render_buffer_len = strlen; temp_render_buffer_len = strlen;
} }
@ -225,7 +225,7 @@ void Clay_Raylib_Render(Clay_RenderCommandArray renderCommands, Font* fonts)
DrawRing((Vector2) { roundf(boundingBox.x + boundingBox.width - config->cornerRadius.topRight), roundf(boundingBox.y + config->cornerRadius.topRight) }, roundf(config->cornerRadius.topRight - config->width.top), config->cornerRadius.topRight, 270, 360, 10, CLAY_COLOR_TO_RAYLIB_COLOR(config->color)); DrawRing((Vector2) { roundf(boundingBox.x + boundingBox.width - config->cornerRadius.topRight), roundf(boundingBox.y + config->cornerRadius.topRight) }, roundf(config->cornerRadius.topRight - config->width.top), config->cornerRadius.topRight, 270, 360, 10, CLAY_COLOR_TO_RAYLIB_COLOR(config->color));
} }
if (config->cornerRadius.bottomLeft > 0) { if (config->cornerRadius.bottomLeft > 0) {
DrawRing((Vector2) { roundf(boundingBox.x + config->cornerRadius.bottomLeft), roundf(boundingBox.y + boundingBox.height - config->cornerRadius.bottomLeft) }, roundf(config->cornerRadius.bottomLeft - config->width.top), config->cornerRadius.bottomLeft, 90, 180, 10, CLAY_COLOR_TO_RAYLIB_COLOR(config->color)); DrawRing((Vector2) { roundf(boundingBox.x + config->cornerRadius.bottomLeft), roundf(boundingBox.y + boundingBox.height - config->cornerRadius.bottomLeft) }, roundf(config->cornerRadius.bottomLeft - config->width.bottom), config->cornerRadius.bottomLeft, 90, 180, 10, CLAY_COLOR_TO_RAYLIB_COLOR(config->color));
} }
if (config->cornerRadius.bottomRight > 0) { if (config->cornerRadius.bottomRight > 0) {
DrawRing((Vector2) { roundf(boundingBox.x + boundingBox.width - config->cornerRadius.bottomRight), roundf(boundingBox.y + boundingBox.height - config->cornerRadius.bottomRight) }, roundf(config->cornerRadius.bottomRight - config->width.bottom), config->cornerRadius.bottomRight, 0.1, 90, 10, CLAY_COLOR_TO_RAYLIB_COLOR(config->color)); DrawRing((Vector2) { roundf(boundingBox.x + boundingBox.width - config->cornerRadius.bottomRight), roundf(boundingBox.y + boundingBox.height - config->cornerRadius.bottomRight) }, roundf(config->cornerRadius.bottomRight - config->width.bottom), config->cornerRadius.bottomRight, 0.1, 90, 10, CLAY_COLOR_TO_RAYLIB_COLOR(config->color));