Compare commits

...

4 Commits

Author SHA1 Message Date
Harrison Lambeth
ae846b0a87
Merge c68a3ee136 into efad3deef8 2025-01-29 14:21:22 -07:00
Harrison Lambeth
efad3deef8
Copy elementId in Clay__AddHashMapItem() in case underlying stringId has changed (#239)
Some checks are pending
CMake on multiple platforms / build (Release, cl, cl, windows-latest) (push) Waiting to run
CMake on multiple platforms / build (Release, clang, clang++, ubuntu-latest) (push) Waiting to run
CMake on multiple platforms / build (Release, gcc, g++, ubuntu-latest) (push) Waiting to run
2025-01-30 10:20:14 +13:00
Nic Barker
a1e692b72a
[Core] Add option to hash text contents to text config (#238) 2025-01-30 09:59:42 +13:00
Harrison Lambeth
c68a3ee136
Define CLAY_IMPLEMENTATION in Jetbrains IDE
[__JETBRAINS_IDE__](https://blog.jetbrains.com/clion/2017/02/clion-2017-1-eap-debugger-fixes-ide-macros-and-new-cmake/) is defined within Jetbrains editors like CLion and Rider. This is only defined inside the IDE, and does not affect builds, so we can use it to enable CLAY_IMPLEMENTATION to improve debugging & intellisense in this environment. I'm not sure if other IDEs have similar macros, but I figured we could start with this one
2025-01-28 21:45:35 -07:00
8 changed files with 26 additions and 9 deletions

View File

@ -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.

22
clay.h
View File

@ -14,6 +14,11 @@
#include <stdbool.h>
#include <stddef.h>
#ifdef __JETBRAINS_IDE__
// Help jetbrains IDEs like CLion and Rider with intellisense & debugging
#define CLAY_IMPLEMENTATION
#endif
// -----------------------------------------
// HEADER DECLARATIONS ---------------------
// -----------------------------------------
@ -324,6 +329,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 +993,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 (int 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 +1204,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;