mirror of
https://github.com/nicbarker/clay.git
synced 2025-05-12 21:38:06 +00:00
Compare commits
6 Commits
9665efda42
...
a6c082ec9c
Author | SHA1 | Date | |
---|---|---|---|
|
a6c082ec9c | ||
|
40ae6d8894 | ||
|
efad3deef8 | ||
|
a1e692b72a | ||
|
63a74a92a8 | ||
|
8d3cadc52e |
@ -111,12 +111,13 @@ TextWrapMode :: enum EnumBackingType {
|
||||
}
|
||||
|
||||
TextElementConfig :: struct {
|
||||
textColor: Color,
|
||||
fontId: u16,
|
||||
fontSize: u16,
|
||||
letterSpacing: u16,
|
||||
lineHeight: u16,
|
||||
wrapMode: TextWrapMode,
|
||||
textColor: Color,
|
||||
fontId: u16,
|
||||
fontSize: u16,
|
||||
letterSpacing: u16,
|
||||
lineHeight: u16,
|
||||
wrapMode: TextWrapMode,
|
||||
hashStringContents: bool,
|
||||
}
|
||||
|
||||
ImageElementConfig :: struct {
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
17
clay.h
17
clay.h
@ -324,6 +324,7 @@ typedef struct {
|
||||
uint16_t letterSpacing;
|
||||
uint16_t lineHeight;
|
||||
Clay_TextElementConfigWrapMode wrapMode;
|
||||
bool hashStringContents;
|
||||
#ifdef CLAY_EXTEND_CONFIG_TEXT
|
||||
CLAY_EXTEND_CONFIG_TEXT
|
||||
#endif
|
||||
@ -987,9 +988,18 @@ uint32_t Clay__HashTextWithConfig(Clay_String *text, Clay_TextElementConfig *con
|
||||
uint32_t hash = 0;
|
||||
uintptr_t pointerAsNumber = (uintptr_t)text->chars;
|
||||
|
||||
hash += pointerAsNumber;
|
||||
hash += (hash << 10);
|
||||
hash ^= (hash >> 6);
|
||||
if (config->hashStringContents) {
|
||||
uint32_t maxLengthToHash = CLAY__MIN(text->length, 256);
|
||||
for (uint32_t i = 0; i < maxLengthToHash; i++) {
|
||||
hash += text->chars[i];
|
||||
hash += (hash << 10);
|
||||
hash ^= (hash >> 6);
|
||||
}
|
||||
} else {
|
||||
hash += pointerAsNumber;
|
||||
hash += (hash << 10);
|
||||
hash ^= (hash >> 6);
|
||||
}
|
||||
|
||||
hash += text->length;
|
||||
hash += (hash << 10);
|
||||
@ -1189,6 +1199,7 @@ Clay_LayoutElementHashMapItem* Clay__AddHashMapItem(Clay_ElementId elementId, Cl
|
||||
if (hashItem->elementId.id == elementId.id) { // Collision - resolve based on generation
|
||||
item.nextIndex = hashItem->nextIndex;
|
||||
if (hashItem->generation <= context->generation) { // First collision - assume this is the "same" element
|
||||
hashItem->elementId = elementId; // Make sure to copy this across. If the stringId reference has changed, we should update the hash item to use the new one.
|
||||
hashItem->generation = context->generation + 1;
|
||||
hashItem->layoutElement = layoutElement;
|
||||
hashItem->debugData->collision = false;
|
||||
|
Binary file not shown.
24
fuzz/fuzzing_target.c
Normal file
24
fuzz/fuzzing_target.c
Normal file
@ -0,0 +1,24 @@
|
||||
#include "clay.h"
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||
if (size < sizeof(Clay_String)) return 0;
|
||||
|
||||
Clay_String testString = { .length = size, .chars = (const char *)data };
|
||||
|
||||
Clay_Dimensions dimensions = MeasureText(&testString, NULL);
|
||||
|
||||
// Call other critical functions
|
||||
Clay_Arena arena = Clay_CreateArenaWithCapacityAndMemory(1024, (void*)data);
|
||||
Clay_Initialize(arena, (Clay_Dimensions){1024, 768});
|
||||
Clay_SetPointerState((Clay_Vector2){0, 0}, false);
|
||||
Clay_BeginLayout();
|
||||
Clay_EndLayout();
|
||||
|
||||
// Handle pointer state changes
|
||||
Clay_SetPointerState((Clay_Vector2){1, 1}, true);
|
||||
Clay_SetPointerState((Clay_Vector2){2, 2}, false);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user