mirror of
https://github.com/nicbarker/clay.git
synced 2025-05-12 21:38:06 +00:00
Compare commits
4 Commits
b5ffbeb277
...
ae846b0a87
Author | SHA1 | Date | |
---|---|---|---|
|
ae846b0a87 | ||
|
efad3deef8 | ||
|
a1e692b72a | ||
|
c68a3ee136 |
@ -111,12 +111,13 @@ TextWrapMode :: enum EnumBackingType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TextElementConfig :: struct {
|
TextElementConfig :: struct {
|
||||||
textColor: Color,
|
textColor: Color,
|
||||||
fontId: u16,
|
fontId: u16,
|
||||||
fontSize: u16,
|
fontSize: u16,
|
||||||
letterSpacing: u16,
|
letterSpacing: u16,
|
||||||
lineHeight: u16,
|
lineHeight: u16,
|
||||||
wrapMode: TextWrapMode,
|
wrapMode: TextWrapMode,
|
||||||
|
hashStringContents: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
ImageElementConfig :: struct {
|
ImageElementConfig :: struct {
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
22
clay.h
22
clay.h
@ -14,6 +14,11 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#ifdef __JETBRAINS_IDE__
|
||||||
|
// Help jetbrains IDEs like CLion and Rider with intellisense & debugging
|
||||||
|
#define CLAY_IMPLEMENTATION
|
||||||
|
#endif
|
||||||
|
|
||||||
// -----------------------------------------
|
// -----------------------------------------
|
||||||
// HEADER DECLARATIONS ---------------------
|
// HEADER DECLARATIONS ---------------------
|
||||||
// -----------------------------------------
|
// -----------------------------------------
|
||||||
@ -324,6 +329,7 @@ typedef struct {
|
|||||||
uint16_t letterSpacing;
|
uint16_t letterSpacing;
|
||||||
uint16_t lineHeight;
|
uint16_t lineHeight;
|
||||||
Clay_TextElementConfigWrapMode wrapMode;
|
Clay_TextElementConfigWrapMode wrapMode;
|
||||||
|
bool hashStringContents;
|
||||||
#ifdef CLAY_EXTEND_CONFIG_TEXT
|
#ifdef CLAY_EXTEND_CONFIG_TEXT
|
||||||
CLAY_EXTEND_CONFIG_TEXT
|
CLAY_EXTEND_CONFIG_TEXT
|
||||||
#endif
|
#endif
|
||||||
@ -987,9 +993,18 @@ uint32_t Clay__HashTextWithConfig(Clay_String *text, Clay_TextElementConfig *con
|
|||||||
uint32_t hash = 0;
|
uint32_t hash = 0;
|
||||||
uintptr_t pointerAsNumber = (uintptr_t)text->chars;
|
uintptr_t pointerAsNumber = (uintptr_t)text->chars;
|
||||||
|
|
||||||
hash += pointerAsNumber;
|
if (config->hashStringContents) {
|
||||||
hash += (hash << 10);
|
uint32_t maxLengthToHash = CLAY__MIN(text->length, 256);
|
||||||
hash ^= (hash >> 6);
|
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 += text->length;
|
||||||
hash += (hash << 10);
|
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
|
if (hashItem->elementId.id == elementId.id) { // Collision - resolve based on generation
|
||||||
item.nextIndex = hashItem->nextIndex;
|
item.nextIndex = hashItem->nextIndex;
|
||||||
if (hashItem->generation <= context->generation) { // First collision - assume this is the "same" element
|
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->generation = context->generation + 1;
|
||||||
hashItem->layoutElement = layoutElement;
|
hashItem->layoutElement = layoutElement;
|
||||||
hashItem->debugData->collision = false;
|
hashItem->debugData->collision = false;
|
||||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user