From c405a2acc05389f8b2003f09d5e0d237435115ce Mon Sep 17 00:00:00 2001 From: Yousef Khadadeh Date: Tue, 2 Dec 2025 16:09:30 +0300 Subject: [PATCH] Use local IDs instead of global unique IDs in clay --- include/clay.h | 365 ++++++++++++--------- src/DrawingProgram/DrawingProgram.cpp | 4 +- src/GUIStuff/Elements/CheckBox.cpp | 2 +- src/GUIStuff/Elements/ColorPicker.hpp | 2 +- src/GUIStuff/Elements/FontPicker.cpp | 10 +- src/GUIStuff/Elements/MovableTabList.cpp | 12 +- src/GUIStuff/Elements/NumberSlider.hpp | 2 +- src/GUIStuff/Elements/PaintCircleMenu.cpp | 2 +- src/GUIStuff/Elements/RadioButton.cpp | 2 +- src/GUIStuff/Elements/RotateWheel.cpp | 2 +- src/GUIStuff/Elements/SVGIcon.cpp | 2 +- src/GUIStuff/Elements/SelectableButton.cpp | 4 +- src/GUIStuff/Elements/TextBox.hpp | 2 +- src/GUIStuff/Elements/TextParagraph.cpp | 2 +- src/GUIStuff/GUIManager.cpp | 160 +++++---- src/GUIStuff/GUIManager.hpp | 15 +- src/Toolbar.cpp | 104 +++--- 17 files changed, 366 insertions(+), 326 deletions(-) diff --git a/include/clay.h b/include/clay.h index 5e0938a..c6e331c 100644 --- a/include/clay.h +++ b/include/clay.h @@ -31,7 +31,8 @@ #if !( \ (defined(__cplusplus) && __cplusplus >= 202002L) || \ (defined(__STDC__) && __STDC__ == 1 && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \ - defined(_MSC_VER) \ + defined(_MSC_VER) || \ + defined(__OBJC__) \ ) #error "Clay requires C99, C++20, or MSVC" #endif @@ -72,24 +73,24 @@ #define CLAY_SIZING_PERCENT(percentOfParent) (CLAY__INIT(Clay_SizingAxis) { .size = { .percent = (percentOfParent) }, .type = CLAY__SIZING_TYPE_PERCENT }) // Note: If a compile error led you here, you might be trying to use CLAY_ID with something other than a string literal. To construct an ID with a dynamic string, use CLAY_SID instead. -#define CLAY_ID(label) CLAY_IDI(label, 0) +#define CLAY_ID(label) CLAY_SID(CLAY_STRING(label)) -#define CLAY_SID(label) CLAY_SIDI(label, 0) +#define CLAY_SID(label) Clay__HashString(label, 0) // Note: If a compile error led you here, you might be trying to use CLAY_IDI with something other than a string literal. To construct an ID with a dynamic string, use CLAY_SIDI instead. #define CLAY_IDI(label, index) CLAY_SIDI(CLAY_STRING(label), index) -#define CLAY_SIDI(label, index) Clay__HashString(label, index, 0) +#define CLAY_SIDI(label, index) Clay__HashStringWithOffset(label, index, 0) // Note: If a compile error led you here, you might be trying to use CLAY_ID_LOCAL with something other than a string literal. To construct an ID with a dynamic string, use CLAY_SID_LOCAL instead. -#define CLAY_ID_LOCAL(label) CLAY_IDI_LOCAL(label, 0) +#define CLAY_ID_LOCAL(label) CLAY_SID_LOCAL(CLAY_STRING(label)) -#define CLAY_SID_LOCAL(label) CLAY_SIDI_LOCAL(label, 0) +#define CLAY_SID_LOCAL(label) Clay__HashString(label, Clay__GetParentElementId()) // Note: If a compile error led you here, you might be trying to use CLAY_IDI_LOCAL with something other than a string literal. To construct an ID with a dynamic string, use CLAY_SIDI_LOCAL instead. #define CLAY_IDI_LOCAL(label, index) CLAY_SIDI_LOCAL(CLAY_STRING(label), index) -#define CLAY_SIDI_LOCAL(label, index) Clay__HashString(label, index, Clay__GetParentElementId()) +#define CLAY_SIDI_LOCAL(label, index) Clay__HashStringWithOffset(label, index, Clay__GetParentElementId()) #define CLAY__STRING_LENGTH(s) ((sizeof(s) / sizeof((s)[0])) - sizeof((s)[0])) @@ -120,25 +121,32 @@ static inline void Clay__SuppressUnusedLatchDefinitionVariableWarning(void) { (v Into calls like this: - Clay_OpenElement(); - Clay_ConfigureOpenElement((Clay_ElementDeclaration) { + Clay__OpenElement(); + Clay__ConfigureOpenElement((Clay_ElementDeclaration) { .id = CLAY_ID("Container"), .backgroundColor = { 255, 200, 200, 255 } }); ...children declared here - Clay_CloseElement(); + Clay__CloseElement(); The for loop will only ever run a single iteration, putting Clay__CloseElement() in the increment of the loop means that it will run after the body - where the children are declared. It just exists to make sure you don't forget to call Clay_CloseElement(). */ -#define CLAY(...) \ +#define CLAY_AUTO_ID(...) \ for ( \ CLAY__ELEMENT_DEFINITION_LATCH = (Clay__OpenElement(), Clay__ConfigureOpenElement(CLAY__CONFIG_WRAPPER(Clay_ElementDeclaration, __VA_ARGS__)), 0); \ CLAY__ELEMENT_DEFINITION_LATCH < 1; \ CLAY__ELEMENT_DEFINITION_LATCH=1, Clay__CloseElement() \ ) +#define CLAY(id, ...) \ + for ( \ + CLAY__ELEMENT_DEFINITION_LATCH = (Clay__OpenElementWithId(id), Clay__ConfigureOpenElement(CLAY__CONFIG_WRAPPER(Clay_ElementDeclaration, __VA_ARGS__)), 0); \ + CLAY__ELEMENT_DEFINITION_LATCH < 1; \ + CLAY__ELEMENT_DEFINITION_LATCH=1, Clay__CloseElement() \ + ) + // These macros exist to allow the CLAY() macro to be called both with an inline struct definition, such as // CLAY({ .id = something... }); // As well as by passing a predefined declaration struct @@ -739,9 +747,6 @@ typedef struct Clay_PointerData { } Clay_PointerData; typedef struct Clay_ElementDeclaration { - // Primarily created via the CLAY_ID(), CLAY_IDI(), CLAY_ID_LOCAL() and CLAY_IDI_LOCAL() macros. - // Represents a hashed string ID used for identifying and finding specific clay UI elements, required by functions such as Clay_PointerOver() and Clay_GetElementData(). - Clay_ElementId id; // Controls various settings that affect the size and position of an element, as well as the sizes and positions of any child elements. Clay_LayoutConfig layout; // Controls the background color of the resulting element. @@ -788,6 +793,8 @@ typedef CLAY_PACKED_ENUM { CLAY_ERROR_TYPE_PERCENTAGE_OVER_1, // Clay encountered an internal error. It would be wonderful if you could report this so we can fix it! CLAY_ERROR_TYPE_INTERNAL_ERROR, + // Clay__OpenElement was called more times than Clay__CloseElement, so there were still remaining open elements when the layout ended. + CLAY_ERROR_TYPE_UNBALANCED_OPEN_CLOSE, } Clay_ErrorType; // Data to identify the error that clay has encountered. @@ -872,7 +879,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. // - 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. -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. // 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); @@ -915,10 +922,12 @@ CLAY_DLL_EXPORT void Clay_ResetMeasureTextCache(void); // Internal API functions required by macros ---------------------- CLAY_DLL_EXPORT void Clay__OpenElement(void); +CLAY_DLL_EXPORT void Clay__OpenElementWithId(Clay_ElementId elementId); CLAY_DLL_EXPORT void Clay__ConfigureOpenElement(const Clay_ElementDeclaration config); CLAY_DLL_EXPORT void Clay__ConfigureOpenElementPtr(const Clay_ElementDeclaration *config); CLAY_DLL_EXPORT void Clay__CloseElement(void); -CLAY_DLL_EXPORT Clay_ElementId Clay__HashString(Clay_String key, uint32_t offset, uint32_t seed); +CLAY_DLL_EXPORT Clay_ElementId Clay__HashString(Clay_String key, uint32_t seed); +CLAY_DLL_EXPORT Clay_ElementId Clay__HashStringWithOffset(Clay_String key, uint32_t offset, uint32_t seed); CLAY_DLL_EXPORT void Clay__OpenTextElement(Clay_String text, Clay_TextElementConfig *textConfig); CLAY_DLL_EXPORT Clay_TextElementConfig *Clay__StoreTextElementConfig(Clay_TextElementConfig config); CLAY_DLL_EXPORT uint32_t Clay__GetParentElementId(void); @@ -1137,6 +1146,7 @@ typedef struct { Clay_LayoutConfig *layoutConfig; Clay__ElementConfigArraySlice elementConfigs; uint32_t id; + uint16_t floatingChildrenCount; } Clay_LayoutElement; CLAY__ARRAY_DEFINE(Clay_LayoutElement, Clay_LayoutElementArray) @@ -1169,11 +1179,10 @@ typedef struct { // todo get this struct into a single cache line Clay_BoundingBox boundingBox; Clay_ElementId elementId; Clay_LayoutElement* layoutElement; - void (*onHoverFunction)(Clay_ElementId elementId, Clay_PointerData pointerInfo, intptr_t userData); - intptr_t hoverFunctionUserData; + void (*onHoverFunction)(Clay_ElementId elementId, Clay_PointerData pointerInfo, void *userData); + void *hoverFunctionUserData; int32_t nextIndex; uint32_t generation; - uint32_t idAlias; Clay__DebugElementData *debugData; } Clay_LayoutElementHashMapItem; @@ -1283,15 +1292,12 @@ struct Clay_Context { Clay_Context* Clay__Context_Allocate_Arena(Clay_Arena *arena) { size_t totalSizeBytes = sizeof(Clay_Context); - uintptr_t memoryAddress = (uintptr_t)arena->memory; - // Make sure the memory address passed in for clay to use is cache line aligned - uintptr_t nextAllocOffset = (memoryAddress % 64); - if (nextAllocOffset + totalSizeBytes > arena->capacity) + if (totalSizeBytes > arena->capacity) { return NULL; } - arena->nextAllocation = nextAllocOffset + totalSizeBytes; - return (Clay_Context*)(memoryAddress + nextAllocOffset); + arena->nextAllocation += totalSizeBytes; + return (Clay_Context*)(arena->memory); } Clay_String Clay__WriteStringToCharBuffer(Clay__charArray *buffer, Clay_String string) { @@ -1362,7 +1368,22 @@ Clay_ElementId Clay__HashNumber(const uint32_t offset, const uint32_t seed) { return CLAY__INIT(Clay_ElementId) { .id = hash + 1, .offset = offset, .baseId = seed, .stringId = CLAY__STRING_DEFAULT }; // Reserve the hash result of zero as "null id" } -Clay_ElementId Clay__HashString(Clay_String key, const uint32_t offset, const uint32_t seed) { +Clay_ElementId Clay__HashString(Clay_String key, const uint32_t seed) { + uint32_t hash = seed; + + for (int32_t i = 0; i < key.length; i++) { + hash += key.chars[i]; + hash += (hash << 10); + hash ^= (hash >> 6); + } + + hash += (hash << 3); + hash ^= (hash >> 11); + hash += (hash << 15); + return CLAY__INIT(Clay_ElementId) { .id = hash + 1, .offset = 0, .baseId = hash + 1, .stringId = key }; // Reserve the hash result of zero as "null id" +} + +Clay_ElementId Clay__HashStringWithOffset(Clay_String key, const uint32_t offset, const uint32_t seed) { uint32_t hash = 0; uint32_t base = seed; @@ -1645,7 +1666,10 @@ Clay__MeasureTextCacheItem *Clay__MeasureTextCached(Clay_String *text, Clay_Text char current = text->chars[end]; if (current == ' ' || current == '\n') { int32_t length = end - start; - Clay_Dimensions dimensions = Clay__MeasureText(CLAY__INIT(Clay_StringSlice) { .length = length, .chars = &text->chars[start], .baseChars = text->chars }, config, context->measureTextUserData); + Clay_Dimensions dimensions = CLAY__DEFAULT_STRUCT; + if (length > 0) { + dimensions = Clay__MeasureText(CLAY__INIT(Clay_StringSlice) {.length = length, .chars = &text->chars[start], .baseChars = text->chars}, config, context->measureTextUserData); + } measured->minWidth = CLAY__MAX(dimensions.width, measured->minWidth); measuredHeight = CLAY__MAX(measuredHeight, dimensions.height); if (current == ' ') { @@ -1692,12 +1716,12 @@ bool Clay__PointIsInsideRect(Clay_Vector2 point, Clay_BoundingBox rect) { return point.x >= rect.x && point.x <= rect.x + rect.width && point.y >= rect.y && point.y <= rect.y + rect.height; } -Clay_LayoutElementHashMapItem* Clay__AddHashMapItem(Clay_ElementId elementId, Clay_LayoutElement* layoutElement, uint32_t idAlias) { +Clay_LayoutElementHashMapItem* Clay__AddHashMapItem(Clay_ElementId elementId, Clay_LayoutElement* layoutElement) { Clay_Context* context = Clay_GetCurrentContext(); if (context->layoutElementsHashMapInternal.length == context->layoutElementsHashMapInternal.capacity - 1) { return NULL; } - Clay_LayoutElementHashMapItem item = { .elementId = elementId, .layoutElement = layoutElement, .nextIndex = -1, .generation = context->generation + 1, .idAlias = idAlias }; + Clay_LayoutElementHashMapItem item = { .elementId = elementId, .layoutElement = layoutElement, .nextIndex = -1, .generation = context->generation + 1 }; uint32_t hashBucket = elementId.id % context->layoutElementsHashMap.capacity; int32_t hashItemPrevious = -1; int32_t hashItemIndex = context->layoutElementsHashMap.internalArray[hashBucket]; @@ -1707,7 +1731,6 @@ Clay_LayoutElementHashMapItem* Clay__AddHashMapItem(Clay_ElementId elementId, Cl 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->idAlias = idAlias; hashItem->generation = context->generation + 1; hashItem->layoutElement = layoutElement; hashItem->debugData->collision = false; @@ -1754,9 +1777,10 @@ Clay_LayoutElementHashMapItem *Clay__GetHashMapItem(uint32_t id) { Clay_ElementId Clay__GenerateIdForAnonymousElement(Clay_LayoutElement *openLayoutElement) { Clay_Context* context = Clay_GetCurrentContext(); Clay_LayoutElement *parentElement = Clay_LayoutElementArray_Get(&context->layoutElements, Clay__int32_tArray_GetValue(&context->openLayoutElementStack, context->openLayoutElementStack.length - 2)); - Clay_ElementId elementId = Clay__HashNumber(parentElement->childrenOrTextContent.children.length, parentElement->id); + uint32_t offset = parentElement->childrenOrTextContent.children.length + parentElement->floatingChildrenCount; + Clay_ElementId elementId = Clay__HashNumber(offset, parentElement->id); openLayoutElement->id = elementId.id; - Clay__AddHashMapItem(elementId, openLayoutElement, 0); + Clay__AddHashMapItem(elementId, openLayoutElement); Clay__StringArray_Add(&context->layoutElementIdStrings, elementId.stringId); return elementId; } @@ -1795,6 +1819,10 @@ void Clay__CloseElement(void) { } Clay_LayoutElement *openLayoutElement = Clay__GetOpenLayoutElement(); Clay_LayoutConfig *layoutConfig = openLayoutElement->layoutConfig; + if (!layoutConfig) { + openLayoutElement->layoutConfig = &Clay_LayoutConfig_DEFAULT; + layoutConfig = &Clay_LayoutConfig_DEFAULT; + } bool elementHasClipHorizontal = false; bool elementHasClipVertical = false; for (int32_t i = 0; i < openLayoutElement->elementConfigs.length; i++) { @@ -1891,9 +1919,15 @@ void Clay__CloseElement(void) { // Close the currently open element int32_t closingElementIndex = Clay__int32_tArray_RemoveSwapback(&context->openLayoutElementStack, (int)context->openLayoutElementStack.length - 1); + + // Get the currently open parent openLayoutElement = Clay__GetOpenLayoutElement(); - if (!elementIsFloating && context->openLayoutElementStack.length > 1) { + if (context->openLayoutElementStack.length > 1) { + if(elementIsFloating) { + openLayoutElement->floatingChildrenCount++; + return; + } openLayoutElement->childrenOrTextContent.children.length++; Clay__int32_tArray_Add(&context->layoutElementChildrenBuffer, closingElementIndex); } @@ -1971,8 +2005,28 @@ void Clay__OpenElement(void) { return; } Clay_LayoutElement layoutElement = CLAY__DEFAULT_STRUCT; - Clay_LayoutElementArray_Add(&context->layoutElements, layoutElement); + Clay_LayoutElement* openLayoutElement = Clay_LayoutElementArray_Add(&context->layoutElements, layoutElement); Clay__int32_tArray_Add(&context->openLayoutElementStack, context->layoutElements.length - 1); + Clay__GenerateIdForAnonymousElement(openLayoutElement); + if (context->openClipElementStack.length > 0) { + Clay__int32_tArray_Set(&context->layoutElementClipElementIds, context->layoutElements.length - 1, Clay__int32_tArray_GetValue(&context->openClipElementStack, (int)context->openClipElementStack.length - 1)); + } else { + Clay__int32_tArray_Set(&context->layoutElementClipElementIds, context->layoutElements.length - 1, 0); + } +} + +void Clay__OpenElementWithId(Clay_ElementId elementId) { + Clay_Context* context = Clay_GetCurrentContext(); + if (context->layoutElements.length == context->layoutElements.capacity - 1 || context->booleanWarnings.maxElementsExceeded) { + context->booleanWarnings.maxElementsExceeded = true; + return; + } + Clay_LayoutElement layoutElement = CLAY__DEFAULT_STRUCT; + layoutElement.id = elementId.id; + Clay_LayoutElement * openLayoutElement = Clay_LayoutElementArray_Add(&context->layoutElements, layoutElement); + Clay__int32_tArray_Add(&context->openLayoutElementStack, context->layoutElements.length - 1); + Clay__AddHashMapItem(elementId, openLayoutElement); + Clay__StringArray_Add(&context->layoutElementIdStrings, elementId.stringId); if (context->openClipElementStack.length > 0) { Clay__int32_tArray_Set(&context->layoutElementClipElementIds, context->layoutElements.length - 1, Clay__int32_tArray_GetValue(&context->openClipElementStack, (int)context->openClipElementStack.length - 1)); } else { @@ -2000,7 +2054,7 @@ void Clay__OpenTextElement(Clay_String text, Clay_TextElementConfig *textConfig) Clay__MeasureTextCacheItem *textMeasured = Clay__MeasureTextCached(&text, textConfig); Clay_ElementId elementId = Clay__HashNumber(parentElement->childrenOrTextContent.children.length, parentElement->id); textElement->id = elementId.id; - Clay__AddHashMapItem(elementId, textElement, 0); + Clay__AddHashMapItem(elementId, textElement); Clay__StringArray_Add(&context->layoutElementIdStrings, elementId.stringId); Clay_Dimensions textDimensions = { .width = textMeasured->unwrappedDimensions.width, .height = textConfig->lineHeight > 0 ? (float)textConfig->lineHeight : textMeasured->unwrappedDimensions.height }; textElement->dimensions = textDimensions; @@ -2014,19 +2068,6 @@ void Clay__OpenTextElement(Clay_String text, Clay_TextElementConfig *textConfig) parentElement->childrenOrTextContent.children.length++; } -Clay_ElementId Clay__AttachId(Clay_ElementId elementId) { - Clay_Context* context = Clay_GetCurrentContext(); - if (context->booleanWarnings.maxElementsExceeded) { - return Clay_ElementId_DEFAULT; - } - Clay_LayoutElement *openLayoutElement = Clay__GetOpenLayoutElement(); - uint32_t idAlias = openLayoutElement->id; - openLayoutElement->id = elementId.id; - Clay__AddHashMapItem(elementId, openLayoutElement, idAlias); - Clay__StringArray_Set(&context->layoutElementIdStrings, context->layoutElements.length - 1, elementId.stringId); - return elementId; -} - void Clay__ConfigureOpenElementPtr(const Clay_ElementDeclaration *declaration) { Clay_Context* context = Clay_GetCurrentContext(); Clay_LayoutElement *openLayoutElement = Clay__GetOpenLayoutElement(); @@ -2038,8 +2079,6 @@ void Clay__ConfigureOpenElementPtr(const Clay_ElementDeclaration *declaration) { .userData = context->errorHandler.userData }); } - Clay_ElementId openLayoutElementId = declaration->id; - openLayoutElement->elementConfigs.internalArray = &context->elementConfigs.internalArray[context->elementConfigs.length]; Clay_SharedElementConfig *sharedConfig = NULL; if (declaration->backgroundColor.a > 0) { @@ -2092,10 +2131,7 @@ void Clay__ConfigureOpenElementPtr(const Clay_ElementDeclaration *declaration) { clipElementId = Clay__int32_tArray_GetValue(&context->layoutElementClipElementIds, (int32_t)(parentItem->layoutElement - context->layoutElements.internalArray)); } } else if (declaration->floating.attachTo == CLAY_ATTACH_TO_ROOT) { - floatingConfig.parentId = Clay__HashString(CLAY_STRING("Clay__RootContainer"), 0, 0).id; - } - if (!openLayoutElementId.id) { - openLayoutElementId = Clay__HashString(CLAY_STRING("Clay__FloatingContainer"), context->layoutElementTreeRoots.length, 0); + floatingConfig.parentId = Clay__HashString(CLAY_STRING("Clay__RootContainer"), 0).id; } if (declaration->floating.clipTo == CLAY_CLIP_TO_NONE) { clipElementId = 0; @@ -2116,12 +2152,6 @@ void Clay__ConfigureOpenElementPtr(const Clay_ElementDeclaration *declaration) { Clay__AttachElementConfig(CLAY__INIT(Clay_ElementConfigUnion) { .customElementConfig = Clay__StoreCustomElementConfig(declaration->custom) }, CLAY__ELEMENT_CONFIG_TYPE_CUSTOM); } - if (openLayoutElementId.id != 0) { - Clay__AttachId(openLayoutElementId); - } else if (openLayoutElement->id == 0) { - openLayoutElementId = Clay__GenerateIdForAnonymousElement(openLayoutElement); - } - if (declaration->clip.horizontal | declaration->clip.vertical) { Clay__AttachElementConfig(CLAY__INIT(Clay_ElementConfigUnion) { .clipElementConfig = Clay__StoreClipElementConfig(declaration->clip) }, CLAY__ELEMENT_CONFIG_TYPE_CLIP); Clay__int32_tArray_Add(&context->openClipElementStack, (int)openLayoutElement->id); @@ -2195,7 +2225,7 @@ void Clay__InitializePersistentMemory(Clay_Context* context) { int32_t maxMeasureTextCacheWordCount = context->maxMeasureTextCacheWordCount; Clay_Arena *arena = &context->internalArena; - context->scrollContainerDatas = Clay__ScrollContainerDataInternalArray_Allocate_Arena(10, arena); + context->scrollContainerDatas = Clay__ScrollContainerDataInternalArray_Allocate_Arena(100, arena); context->layoutElementsHashMapInternal = Clay__LayoutElementHashMapItemArray_Allocate_Arena(maxElementCount, arena); context->layoutElementsHashMap = Clay__int32_tArray_Allocate_Arena(maxElementCount, arena); context->measureTextHashMapInternal = Clay__MeasureTextCacheItemArray_Allocate_Arena(maxElementCount, arena); @@ -2231,17 +2261,37 @@ void Clay__SizeContainersAlongAxis(bool xAxis) { Clay_LayoutElementHashMapItem *parentItem = Clay__GetHashMapItem(floatingElementConfig->parentId); if (parentItem && parentItem != &Clay_LayoutElementHashMapItem_DEFAULT) { Clay_LayoutElement *parentLayoutElement = parentItem->layoutElement; - if (rootElement->layoutConfig->sizing.width.type == CLAY__SIZING_TYPE_GROW) { - rootElement->dimensions.width = parentLayoutElement->dimensions.width; + switch (rootElement->layoutConfig->sizing.width.type) { + case CLAY__SIZING_TYPE_GROW: { + rootElement->dimensions.width = parentLayoutElement->dimensions.width; + break; + } + case CLAY__SIZING_TYPE_PERCENT: { + rootElement->dimensions.width = parentLayoutElement->dimensions.width * rootElement->layoutConfig->sizing.width.size.percent; + break; + } + default: break; } - if (rootElement->layoutConfig->sizing.height.type == CLAY__SIZING_TYPE_GROW) { - rootElement->dimensions.height = parentLayoutElement->dimensions.height; + switch (rootElement->layoutConfig->sizing.height.type) { + case CLAY__SIZING_TYPE_GROW: { + rootElement->dimensions.height = parentLayoutElement->dimensions.height; + break; + } + case CLAY__SIZING_TYPE_PERCENT: { + rootElement->dimensions.height = parentLayoutElement->dimensions.height * rootElement->layoutConfig->sizing.height.size.percent; + break; + } + default: break; } } } - rootElement->dimensions.width = CLAY__MIN(CLAY__MAX(rootElement->dimensions.width, rootElement->layoutConfig->sizing.width.size.minMax.min), rootElement->layoutConfig->sizing.width.size.minMax.max); - rootElement->dimensions.height = CLAY__MIN(CLAY__MAX(rootElement->dimensions.height, rootElement->layoutConfig->sizing.height.size.minMax.min), rootElement->layoutConfig->sizing.height.size.minMax.max); + if (rootElement->layoutConfig->sizing.width.type != CLAY__SIZING_TYPE_PERCENT) { + rootElement->dimensions.width = CLAY__MIN(CLAY__MAX(rootElement->dimensions.width, rootElement->layoutConfig->sizing.width.size.minMax.min), rootElement->layoutConfig->sizing.width.size.minMax.max); + } + if (rootElement->layoutConfig->sizing.height.type != CLAY__SIZING_TYPE_PERCENT) { + rootElement->dimensions.height = CLAY__MIN(CLAY__MAX(rootElement->dimensions.height, rootElement->layoutConfig->sizing.height.size.minMax.min), rootElement->layoutConfig->sizing.height.size.minMax.max); + } for (int32_t i = 0; i < bfsBuffer.length; ++i) { int32_t parentIndex = Clay__int32_tArray_GetValue(&bfsBuffer, i); @@ -2694,7 +2744,6 @@ void Clay__CalculateFinalLayout(void) { if (clipConfig->vertical) { rootPosition.y += clipConfig->childOffset.y; } - break; } Clay__AddRenderCommand(CLAY__INIT(Clay_RenderCommand) { .boundingBox = clipHashMapItem->boundingBox, @@ -2751,12 +2800,6 @@ void Clay__CalculateFinalLayout(void) { Clay_LayoutElementHashMapItem *hashMapItem = Clay__GetHashMapItem(currentElement->id); if (hashMapItem) { hashMapItem->boundingBox = currentElementBoundingBox; - if (hashMapItem->idAlias) { - Clay_LayoutElementHashMapItem *hashMapItemAlias = Clay__GetHashMapItem(hashMapItem->idAlias); - if (hashMapItemAlias) { - hashMapItemAlias->boundingBox = currentElementBoundingBox; - } - } } int32_t sortedConfigIndexes[20]; @@ -2931,6 +2974,7 @@ void Clay__CalculateFinalLayout(void) { default: break; } currentElementTreeNode->nextChildOffset.x += extraSpace; + extraSpace = CLAY__MAX(0, extraSpace); } else { for (int32_t i = 0; i < currentElement->childrenOrTextContent.children.length; ++i) { Clay_LayoutElement *childElement = Clay_LayoutElementArray_Get(&context->layoutElements, currentElement->childrenOrTextContent.children.elements[i]); @@ -2944,6 +2988,7 @@ void Clay__CalculateFinalLayout(void) { case CLAY_ALIGN_Y_CENTER: extraSpace /= 2; break; default: break; } + extraSpace = CLAY__MAX(0, extraSpace); currentElementTreeNode->nextChildOffset.y += extraSpace; } @@ -3152,8 +3197,8 @@ Clay__RenderDebugLayoutData Clay__RenderDebugLayoutElementsList(int32_t initialR Clay__int32_tArray_Add(&dfsBuffer, (int32_t)root->layoutElementIndex); context->treeNodeVisited.internalArray[0] = false; if (rootIndex > 0) { - CLAY({ .id = CLAY_IDI("Clay__DebugView_EmptyRowOuter", rootIndex), .layout = { .sizing = {.width = CLAY_SIZING_GROW(0)}, .padding = {CLAY__DEBUGVIEW_INDENT_WIDTH / 2, 0, 0, 0} } }) { - CLAY({ .id = CLAY_IDI("Clay__DebugView_EmptyRow", rootIndex), .layout = { .sizing = { .width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIXED((float)CLAY__DEBUGVIEW_ROW_HEIGHT) }}, .border = { .color = CLAY__DEBUGVIEW_COLOR_3, .width = { .top = 1 } } }) {} + CLAY(CLAY_IDI("Clay__DebugView_EmptyRowOuter", rootIndex), { .layout = { .sizing = {.width = CLAY_SIZING_GROW(0)}, .padding = {CLAY__DEBUGVIEW_INDENT_WIDTH / 2, 0, 0, 0} } }) { + CLAY(CLAY_IDI("Clay__DebugView_EmptyRow", rootIndex), { .layout = { .sizing = { .width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIXED((float)CLAY__DEBUGVIEW_ROW_HEIGHT) }}, .border = { .color = CLAY__DEBUGVIEW_COLOR_3, .width = { .top = 1 } } }) {} } layoutData.rowCount++; } @@ -3183,11 +3228,10 @@ Clay__RenderDebugLayoutData Clay__RenderDebugLayoutElementsList(int32_t initialR if (context->debugSelectedElementId == currentElement->id) { layoutData.selectedElementRowIndex = layoutData.rowCount; } - CLAY({ .id = CLAY_IDI("Clay__DebugView_ElementOuter", currentElement->id), .layout = Clay__DebugView_ScrollViewItemLayoutConfig }) { + CLAY(CLAY_IDI("Clay__DebugView_ElementOuter", currentElement->id), { .layout = Clay__DebugView_ScrollViewItemLayoutConfig }) { // Collapse icon / button if (!(Clay__ElementHasConfig(currentElement, CLAY__ELEMENT_CONFIG_TYPE_TEXT) || currentElement->childrenOrTextContent.children.length == 0)) { - CLAY({ - .id = CLAY_IDI("Clay__DebugView_CollapseElement", currentElement->id), + CLAY(CLAY_IDI("Clay__DebugView_CollapseElement", currentElement->id), { .layout = { .sizing = {CLAY_SIZING_FIXED(16), CLAY_SIZING_FIXED(16)}, .childAlignment = { CLAY_ALIGN_X_CENTER, CLAY_ALIGN_Y_CENTER} }, .cornerRadius = CLAY_CORNER_RADIUS(4), .border = { .color = CLAY__DEBUGVIEW_COLOR_3, .width = {1, 1, 1, 1, 0} }, @@ -3195,19 +3239,19 @@ Clay__RenderDebugLayoutData Clay__RenderDebugLayoutElementsList(int32_t initialR CLAY_TEXT((currentElementData && currentElementData->debugData->collapsed) ? CLAY_STRING("+") : CLAY_STRING("-"), CLAY_TEXT_CONFIG({ .textColor = CLAY__DEBUGVIEW_COLOR_4, .fontSize = 16 })); } } else { // Square dot for empty containers - CLAY({ .layout = { .sizing = {CLAY_SIZING_FIXED(16), CLAY_SIZING_FIXED(16)}, .childAlignment = { CLAY_ALIGN_X_CENTER, CLAY_ALIGN_Y_CENTER } } }) { - CLAY({ .layout = { .sizing = {CLAY_SIZING_FIXED(8), CLAY_SIZING_FIXED(8)} }, .backgroundColor = CLAY__DEBUGVIEW_COLOR_3, .cornerRadius = CLAY_CORNER_RADIUS(2) }) {} + CLAY_AUTO_ID({ .layout = { .sizing = {CLAY_SIZING_FIXED(16), CLAY_SIZING_FIXED(16)}, .childAlignment = { CLAY_ALIGN_X_CENTER, CLAY_ALIGN_Y_CENTER } } }) { + CLAY_AUTO_ID({ .layout = { .sizing = {CLAY_SIZING_FIXED(8), CLAY_SIZING_FIXED(8)} }, .backgroundColor = CLAY__DEBUGVIEW_COLOR_3, .cornerRadius = CLAY_CORNER_RADIUS(2) }) {} } } // Collisions and offscreen info if (currentElementData) { if (currentElementData->debugData->collision) { - CLAY({ .layout = { .padding = { 8, 8, 2, 2 }}, .border = { .color = {177, 147, 8, 255}, .width = {1, 1, 1, 1, 0} } }) { + CLAY_AUTO_ID({ .layout = { .padding = { 8, 8, 2, 2 }}, .border = { .color = {177, 147, 8, 255}, .width = {1, 1, 1, 1, 0} } }) { CLAY_TEXT(CLAY_STRING("Duplicate ID"), CLAY_TEXT_CONFIG({ .textColor = CLAY__DEBUGVIEW_COLOR_3, .fontSize = 16 })); } } if (offscreen) { - CLAY({ .layout = { .padding = { 8, 8, 2, 2 } }, .border = { .color = CLAY__DEBUGVIEW_COLOR_3, .width = { 1, 1, 1, 1, 0} } }) { + CLAY_AUTO_ID({ .layout = { .padding = { 8, 8, 2, 2 } }, .border = { .color = CLAY__DEBUGVIEW_COLOR_3, .width = { 1, 1, 1, 1, 0} } }) { CLAY_TEXT(CLAY_STRING("Offscreen"), CLAY_TEXT_CONFIG({ .textColor = CLAY__DEBUGVIEW_COLOR_3, .fontSize = 16 })); } } @@ -3224,12 +3268,12 @@ Clay__RenderDebugLayoutData Clay__RenderDebugLayoutElementsList(int32_t initialR Clay_Color backgroundColor = elementConfig->config.sharedElementConfig->backgroundColor; Clay_CornerRadius radius = elementConfig->config.sharedElementConfig->cornerRadius; if (backgroundColor.a > 0) { - CLAY({ .layout = { .padding = { 8, 8, 2, 2 } }, .backgroundColor = labelColor, .cornerRadius = CLAY_CORNER_RADIUS(4), .border = { .color = labelColor, .width = { 1, 1, 1, 1, 0} } }) { + CLAY_AUTO_ID({ .layout = { .padding = { 8, 8, 2, 2 } }, .backgroundColor = labelColor, .cornerRadius = CLAY_CORNER_RADIUS(4), .border = { .color = labelColor, .width = { 1, 1, 1, 1, 0} } }) { CLAY_TEXT(CLAY_STRING("Color"), CLAY_TEXT_CONFIG({ .textColor = offscreen ? CLAY__DEBUGVIEW_COLOR_3 : CLAY__DEBUGVIEW_COLOR_4, .fontSize = 16 })); } } if (radius.bottomLeft > 0) { - CLAY({ .layout = { .padding = { 8, 8, 2, 2 } }, .backgroundColor = labelColor, .cornerRadius = CLAY_CORNER_RADIUS(4), .border = { .color = labelColor, .width = { 1, 1, 1, 1, 0 } } }) { + CLAY_AUTO_ID({ .layout = { .padding = { 8, 8, 2, 2 } }, .backgroundColor = labelColor, .cornerRadius = CLAY_CORNER_RADIUS(4), .border = { .color = labelColor, .width = { 1, 1, 1, 1, 0 } } }) { CLAY_TEXT(CLAY_STRING("Radius"), CLAY_TEXT_CONFIG({ .textColor = offscreen ? CLAY__DEBUGVIEW_COLOR_3 : CLAY__DEBUGVIEW_COLOR_4, .fontSize = 16 })); } } @@ -3238,7 +3282,7 @@ Clay__RenderDebugLayoutData Clay__RenderDebugLayoutElementsList(int32_t initialR Clay__DebugElementConfigTypeLabelConfig config = Clay__DebugGetElementConfigTypeLabel(elementConfig->type); Clay_Color backgroundColor = config.color; backgroundColor.a = 90; - CLAY({ .layout = { .padding = { 8, 8, 2, 2 } }, .backgroundColor = backgroundColor, .cornerRadius = CLAY_CORNER_RADIUS(4), .border = { .color = config.color, .width = { 1, 1, 1, 1, 0 } } }) { + CLAY_AUTO_ID({ .layout = { .padding = { 8, 8, 2, 2 } }, .backgroundColor = backgroundColor, .cornerRadius = CLAY_CORNER_RADIUS(4), .border = { .color = config.color, .width = { 1, 1, 1, 1, 0 } } }) { CLAY_TEXT(config.label, CLAY_TEXT_CONFIG({ .textColor = offscreen ? CLAY__DEBUGVIEW_COLOR_3 : CLAY__DEBUGVIEW_COLOR_4, .fontSize = 16 })); } } @@ -3249,8 +3293,8 @@ Clay__RenderDebugLayoutData Clay__RenderDebugLayoutElementsList(int32_t initialR layoutData.rowCount++; Clay__TextElementData *textElementData = currentElement->childrenOrTextContent.textElementData; Clay_TextElementConfig *rawTextConfig = offscreen ? CLAY_TEXT_CONFIG({ .textColor = CLAY__DEBUGVIEW_COLOR_3, .fontSize = 16 }) : &Clay__DebugView_TextNameConfig; - CLAY({ .layout = { .sizing = { .height = CLAY_SIZING_FIXED(CLAY__DEBUGVIEW_ROW_HEIGHT)}, .childAlignment = { .y = CLAY_ALIGN_Y_CENTER } } }) { - CLAY({ .layout = { .sizing = {.width = CLAY_SIZING_FIXED(CLAY__DEBUGVIEW_INDENT_WIDTH + 16) } } }) {} + CLAY_AUTO_ID({ .layout = { .sizing = { .height = CLAY_SIZING_FIXED(CLAY__DEBUGVIEW_ROW_HEIGHT)}, .childAlignment = { .y = CLAY_ALIGN_Y_CENTER } } }) { + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_FIXED(CLAY__DEBUGVIEW_INDENT_WIDTH + 16) } } }) {} CLAY_TEXT(CLAY_STRING("\""), rawTextConfig); CLAY_TEXT(textElementData->text.length > 40 ? (CLAY__INIT(Clay_String) { .length = 40, .chars = textElementData->text.chars }) : textElementData->text, rawTextConfig); if (textElementData->text.length > 40) { @@ -3278,7 +3322,7 @@ Clay__RenderDebugLayoutData Clay__RenderDebugLayoutElementsList(int32_t initialR } if (context->pointerInfo.state == CLAY_POINTER_DATA_PRESSED_THIS_FRAME) { - Clay_ElementId collapseButtonId = Clay__HashString(CLAY_STRING("Clay__DebugView_CollapseElement"), 0, 0); + Clay_ElementId collapseButtonId = Clay__HashString(CLAY_STRING("Clay__DebugView_CollapseElement"), 0); for (int32_t i = (int)context->pointerOverIds.length - 1; i >= 0; i--) { Clay_ElementId *elementId = Clay_ElementIdArray_Get(&context->pointerOverIds, i); if (elementId->baseId == collapseButtonId.baseId) { @@ -3290,8 +3334,8 @@ Clay__RenderDebugLayoutData Clay__RenderDebugLayoutElementsList(int32_t initialR } if (highlightedElementId) { - CLAY({ .id = CLAY_ID("Clay__DebugView_ElementHighlight"), .layout = { .sizing = {CLAY_SIZING_GROW(0), CLAY_SIZING_GROW(0)} }, .floating = { .parentId = highlightedElementId, .zIndex = 32767, .pointerCaptureMode = CLAY_POINTER_CAPTURE_MODE_PASSTHROUGH, .attachTo = CLAY_ATTACH_TO_ELEMENT_WITH_ID } }) { - CLAY({ .id = CLAY_ID("Clay__DebugView_ElementHighlightRectangle"), .layout = { .sizing = {CLAY_SIZING_GROW(0), CLAY_SIZING_GROW(0)} }, .backgroundColor = Clay__debugViewHighlightColor }) {} + CLAY(CLAY_ID("Clay__DebugView_ElementHighlight"), { .layout = { .sizing = {CLAY_SIZING_GROW(0), CLAY_SIZING_GROW(0)} }, .floating = { .parentId = highlightedElementId, .zIndex = 32767, .pointerCaptureMode = CLAY_POINTER_CAPTURE_MODE_PASSTHROUGH, .attachTo = CLAY_ATTACH_TO_ELEMENT_WITH_ID } }) { + CLAY(CLAY_ID("Clay__DebugView_ElementHighlightRectangle"), { .layout = { .sizing = {CLAY_SIZING_GROW(0), CLAY_SIZING_GROW(0)} }, .backgroundColor = Clay__debugViewHighlightColor }) {} } } return layoutData; @@ -3332,17 +3376,17 @@ void Clay__RenderDebugViewElementConfigHeader(Clay_String elementId, Clay__Eleme Clay__DebugElementConfigTypeLabelConfig config = Clay__DebugGetElementConfigTypeLabel(type); Clay_Color backgroundColor = config.color; backgroundColor.a = 90; - CLAY({ .layout = { .sizing = { .width = CLAY_SIZING_GROW(0) }, .padding = CLAY_PADDING_ALL(CLAY__DEBUGVIEW_OUTER_PADDING), .childAlignment = { .y = CLAY_ALIGN_Y_CENTER } } }) { - CLAY({ .layout = { .padding = { 8, 8, 2, 2 } }, .backgroundColor = backgroundColor, .cornerRadius = CLAY_CORNER_RADIUS(4), .border = { .color = config.color, .width = { 1, 1, 1, 1, 0 } } }) { + CLAY_AUTO_ID({ .layout = { .sizing = { .width = CLAY_SIZING_GROW(0) }, .padding = CLAY_PADDING_ALL(CLAY__DEBUGVIEW_OUTER_PADDING), .childAlignment = { .y = CLAY_ALIGN_Y_CENTER } } }) { + CLAY_AUTO_ID({ .layout = { .padding = { 8, 8, 2, 2 } }, .backgroundColor = backgroundColor, .cornerRadius = CLAY_CORNER_RADIUS(4), .border = { .color = config.color, .width = { 1, 1, 1, 1, 0 } } }) { CLAY_TEXT(config.label, CLAY_TEXT_CONFIG({ .textColor = CLAY__DEBUGVIEW_COLOR_4, .fontSize = 16 })); } - CLAY({ .layout = { .sizing = { .width = CLAY_SIZING_GROW(0) } } }) {} + CLAY_AUTO_ID({ .layout = { .sizing = { .width = CLAY_SIZING_GROW(0) } } }) {} CLAY_TEXT(elementId, CLAY_TEXT_CONFIG({ .textColor = CLAY__DEBUGVIEW_COLOR_3, .fontSize = 16, .wrapMode = CLAY_TEXT_WRAP_NONE })); } } void Clay__RenderDebugViewColor(Clay_Color color, Clay_TextElementConfig *textConfig) { - CLAY({ .layout = { .childAlignment = {.y = CLAY_ALIGN_Y_CENTER} } }) { + CLAY_AUTO_ID({ .layout = { .childAlignment = {.y = CLAY_ALIGN_Y_CENTER} } }) { CLAY_TEXT(CLAY_STRING("{ r: "), textConfig); CLAY_TEXT(Clay__IntToString(color.r), textConfig); CLAY_TEXT(CLAY_STRING(", g: "), textConfig); @@ -3352,13 +3396,13 @@ void Clay__RenderDebugViewColor(Clay_Color color, Clay_TextElementConfig *textCo CLAY_TEXT(CLAY_STRING(", a: "), textConfig); CLAY_TEXT(Clay__IntToString(color.a), textConfig); CLAY_TEXT(CLAY_STRING(" }"), textConfig); - CLAY({ .layout = { .sizing = { .width = CLAY_SIZING_FIXED(10) } } }) {} - CLAY({ .layout = { .sizing = { CLAY_SIZING_FIXED(CLAY__DEBUGVIEW_ROW_HEIGHT - 8), CLAY_SIZING_FIXED(CLAY__DEBUGVIEW_ROW_HEIGHT - 8)} }, .backgroundColor = color, .cornerRadius = CLAY_CORNER_RADIUS(4), .border = { .color = CLAY__DEBUGVIEW_COLOR_4, .width = { 1, 1, 1, 1, 0 } } }) {} + CLAY_AUTO_ID({ .layout = { .sizing = { .width = CLAY_SIZING_FIXED(10) } } }) {} + CLAY_AUTO_ID({ .layout = { .sizing = { CLAY_SIZING_FIXED(CLAY__DEBUGVIEW_ROW_HEIGHT - 8), CLAY_SIZING_FIXED(CLAY__DEBUGVIEW_ROW_HEIGHT - 8)} }, .backgroundColor = color, .cornerRadius = CLAY_CORNER_RADIUS(4), .border = { .color = CLAY__DEBUGVIEW_COLOR_4, .width = { 1, 1, 1, 1, 0 } } }) {} } } void Clay__RenderDebugViewCornerRadius(Clay_CornerRadius cornerRadius, Clay_TextElementConfig *textConfig) { - CLAY({ .layout = { .childAlignment = {.y = CLAY_ALIGN_Y_CENTER} } }) { + CLAY_AUTO_ID({ .layout = { .childAlignment = {.y = CLAY_ALIGN_Y_CENTER} } }) { CLAY_TEXT(CLAY_STRING("{ topLeft: "), textConfig); CLAY_TEXT(Clay__IntToString(cornerRadius.topLeft), textConfig); CLAY_TEXT(CLAY_STRING(", topRight: "), textConfig); @@ -3371,7 +3415,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(); (void) elementId; (void) pointerInfo; (void) userData; if (pointerInfo.state == CLAY_POINTER_DATA_PRESSED_THIS_FRAME) { @@ -3381,7 +3425,7 @@ void HandleDebugViewCloseButtonInteraction(Clay_ElementId elementId, Clay_Pointe void Clay__RenderDebugView(void) { Clay_Context* context = Clay_GetCurrentContext(); - Clay_ElementId closeButtonId = Clay__HashString(CLAY_STRING("Clay__DebugViewTopHeaderCloseButtonOuter"), 0, 0); + Clay_ElementId closeButtonId = Clay__HashString(CLAY_STRING("Clay__DebugViewTopHeaderCloseButtonOuter"), 0); if (context->pointerInfo.state == CLAY_POINTER_DATA_PRESSED_THIS_FRAME) { for (int32_t i = 0; i < context->pointerOverIds.length; ++i) { Clay_ElementId *elementId = Clay_ElementIdArray_Get(&context->pointerOverIds, i); @@ -3396,7 +3440,7 @@ void Clay__RenderDebugView(void) { uint32_t initialElementsLength = context->layoutElements.length; Clay_TextElementConfig *infoTextConfig = CLAY_TEXT_CONFIG({ .textColor = CLAY__DEBUGVIEW_COLOR_4, .fontSize = 16, .wrapMode = CLAY_TEXT_WRAP_NONE }); Clay_TextElementConfig *infoTitleConfig = CLAY_TEXT_CONFIG({ .textColor = CLAY__DEBUGVIEW_COLOR_3, .fontSize = 16, .wrapMode = CLAY_TEXT_WRAP_NONE }); - Clay_ElementId scrollId = Clay__HashString(CLAY_STRING("Clay__DebugViewOuterScrollPane"), 0, 0); + Clay_ElementId scrollId = Clay__HashString(CLAY_STRING("Clay__DebugViewOuterScrollPane"), 0); float scrollYOffset = 0; bool pointerInDebugView = context->pointerInfo.position.y < context->layoutDimensions.height - 300; for (int32_t i = 0; i < context->scrollContainerDatas.length; ++i) { @@ -3417,16 +3461,16 @@ void Clay__RenderDebugView(void) { highlightedRow = -1; } Clay__RenderDebugLayoutData layoutData = CLAY__DEFAULT_STRUCT; - CLAY({ .id = CLAY_ID("Clay__DebugView"), + CLAY(CLAY_ID("Clay__DebugView"), { .layout = { .sizing = { CLAY_SIZING_FIXED((float)Clay__debugViewWidth) , CLAY_SIZING_FIXED(context->layoutDimensions.height) }, .layoutDirection = CLAY_TOP_TO_BOTTOM }, .floating = { .zIndex = 32765, .attachPoints = { .element = CLAY_ATTACH_POINT_LEFT_CENTER, .parent = CLAY_ATTACH_POINT_RIGHT_CENTER }, .attachTo = CLAY_ATTACH_TO_ROOT, .clipTo = CLAY_CLIP_TO_ATTACHED_PARENT }, .border = { .color = CLAY__DEBUGVIEW_COLOR_3, .width = { .bottom = 1 } } }) { - CLAY({ .layout = { .sizing = {CLAY_SIZING_GROW(0), CLAY_SIZING_FIXED(CLAY__DEBUGVIEW_ROW_HEIGHT)}, .padding = {CLAY__DEBUGVIEW_OUTER_PADDING, CLAY__DEBUGVIEW_OUTER_PADDING, 0, 0 }, .childAlignment = {.y = CLAY_ALIGN_Y_CENTER} }, .backgroundColor = CLAY__DEBUGVIEW_COLOR_2 }) { + CLAY_AUTO_ID({ .layout = { .sizing = {CLAY_SIZING_GROW(0), CLAY_SIZING_FIXED(CLAY__DEBUGVIEW_ROW_HEIGHT)}, .padding = {CLAY__DEBUGVIEW_OUTER_PADDING, CLAY__DEBUGVIEW_OUTER_PADDING, 0, 0 }, .childAlignment = {.y = CLAY_ALIGN_Y_CENTER} }, .backgroundColor = CLAY__DEBUGVIEW_COLOR_2 }) { CLAY_TEXT(CLAY_STRING("Clay Debug Tools"), infoTextConfig); - CLAY({ .layout = { .sizing = { .width = CLAY_SIZING_GROW(0) } } }) {} + CLAY_AUTO_ID({ .layout = { .sizing = { .width = CLAY_SIZING_GROW(0) } } }) {} // Close button - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {CLAY_SIZING_FIXED(CLAY__DEBUGVIEW_ROW_HEIGHT - 10), CLAY_SIZING_FIXED(CLAY__DEBUGVIEW_ROW_HEIGHT - 10)}, .childAlignment = {CLAY_ALIGN_X_CENTER, CLAY_ALIGN_Y_CENTER} }, .backgroundColor = {217,91,67,80}, .cornerRadius = CLAY_CORNER_RADIUS(4), @@ -3436,18 +3480,18 @@ void Clay__RenderDebugView(void) { CLAY_TEXT(CLAY_STRING("x"), CLAY_TEXT_CONFIG({ .textColor = CLAY__DEBUGVIEW_COLOR_4, .fontSize = 16 })); } } - CLAY({ .layout = { .sizing = {CLAY_SIZING_GROW(0), CLAY_SIZING_FIXED(1)} }, .backgroundColor = CLAY__DEBUGVIEW_COLOR_3 } ) {} - CLAY({ .id = scrollId, .layout = { .sizing = {CLAY_SIZING_GROW(0), CLAY_SIZING_GROW(0)} }, .clip = { .horizontal = true, .vertical = true, .childOffset = Clay_GetScrollOffset() } }) { - CLAY({ .layout = { .sizing = {CLAY_SIZING_GROW(0), CLAY_SIZING_GROW(0)}, .layoutDirection = CLAY_TOP_TO_BOTTOM }, .backgroundColor = ((initialElementsLength + initialRootsLength) & 1) == 0 ? CLAY__DEBUGVIEW_COLOR_2 : CLAY__DEBUGVIEW_COLOR_1 }) { - Clay_ElementId panelContentsId = Clay__HashString(CLAY_STRING("Clay__DebugViewPaneOuter"), 0, 0); + CLAY_AUTO_ID({ .layout = { .sizing = {CLAY_SIZING_GROW(0), CLAY_SIZING_FIXED(1)} }, .backgroundColor = CLAY__DEBUGVIEW_COLOR_3 } ) {} + CLAY(scrollId, { .layout = { .sizing = {CLAY_SIZING_GROW(0), CLAY_SIZING_GROW(0)} }, .clip = { .horizontal = true, .vertical = true, .childOffset = Clay_GetScrollOffset() } }) { + CLAY_AUTO_ID({ .layout = { .sizing = {CLAY_SIZING_GROW(0), CLAY_SIZING_GROW(0)}, .layoutDirection = CLAY_TOP_TO_BOTTOM }, .backgroundColor = ((initialElementsLength + initialRootsLength) & 1) == 0 ? CLAY__DEBUGVIEW_COLOR_2 : CLAY__DEBUGVIEW_COLOR_1 }) { + Clay_ElementId panelContentsId = Clay__HashString(CLAY_STRING("Clay__DebugViewPaneOuter"), 0); // Element list - CLAY({ .id = panelContentsId, .layout = { .sizing = {CLAY_SIZING_GROW(0), CLAY_SIZING_GROW(0)} }, .floating = { .zIndex = 32766, .pointerCaptureMode = CLAY_POINTER_CAPTURE_MODE_PASSTHROUGH, .attachTo = CLAY_ATTACH_TO_PARENT, .clipTo = CLAY_CLIP_TO_ATTACHED_PARENT } }) { - CLAY({ .layout = { .sizing = {CLAY_SIZING_GROW(0), CLAY_SIZING_GROW(0)}, .padding = { CLAY__DEBUGVIEW_OUTER_PADDING, CLAY__DEBUGVIEW_OUTER_PADDING, 0, 0 }, .layoutDirection = CLAY_TOP_TO_BOTTOM } }) { + CLAY(panelContentsId, { .layout = { .sizing = {CLAY_SIZING_GROW(0), CLAY_SIZING_GROW(0)} }, .floating = { .zIndex = 32766, .pointerCaptureMode = CLAY_POINTER_CAPTURE_MODE_PASSTHROUGH, .attachTo = CLAY_ATTACH_TO_PARENT, .clipTo = CLAY_CLIP_TO_ATTACHED_PARENT } }) { + CLAY_AUTO_ID({ .layout = { .sizing = {CLAY_SIZING_GROW(0), CLAY_SIZING_GROW(0)}, .padding = { CLAY__DEBUGVIEW_OUTER_PADDING, CLAY__DEBUGVIEW_OUTER_PADDING, 0, 0 }, .layoutDirection = CLAY_TOP_TO_BOTTOM } }) { layoutData = Clay__RenderDebugLayoutElementsList((int32_t)initialRootsLength, highlightedRow); } } float contentWidth = Clay__GetHashMapItem(panelContentsId.id)->layoutElement->dimensions.width; - CLAY({ .layout = { .sizing = {.width = CLAY_SIZING_FIXED(contentWidth) }, .layoutDirection = CLAY_TOP_TO_BOTTOM } }) {} + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_FIXED(contentWidth) }, .layoutDirection = CLAY_TOP_TO_BOTTOM } }) {} for (int32_t i = 0; i < layoutData.rowCount; i++) { Clay_Color rowColor = (i & 1) == 0 ? CLAY__DEBUGVIEW_COLOR_2 : CLAY__DEBUGVIEW_COLOR_1; if (i == layoutData.selectedElementRowIndex) { @@ -3458,22 +3502,22 @@ void Clay__RenderDebugView(void) { rowColor.g *= 1.25f; rowColor.b *= 1.25f; } - CLAY({ .layout = { .sizing = {CLAY_SIZING_GROW(0), CLAY_SIZING_FIXED(CLAY__DEBUGVIEW_ROW_HEIGHT)}, .layoutDirection = CLAY_TOP_TO_BOTTOM }, .backgroundColor = rowColor } ) {} + CLAY_AUTO_ID({ .layout = { .sizing = {CLAY_SIZING_GROW(0), CLAY_SIZING_FIXED(CLAY__DEBUGVIEW_ROW_HEIGHT)}, .layoutDirection = CLAY_TOP_TO_BOTTOM }, .backgroundColor = rowColor } ) {} } } } - CLAY({ .layout = { .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIXED(1)} }, .backgroundColor = CLAY__DEBUGVIEW_COLOR_3 }) {} + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIXED(1)} }, .backgroundColor = CLAY__DEBUGVIEW_COLOR_3 }) {} if (context->debugSelectedElementId != 0) { Clay_LayoutElementHashMapItem *selectedItem = Clay__GetHashMapItem(context->debugSelectedElementId); - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {CLAY_SIZING_GROW(0), CLAY_SIZING_FIXED(300)}, .layoutDirection = CLAY_TOP_TO_BOTTOM }, .backgroundColor = CLAY__DEBUGVIEW_COLOR_2 , .clip = { .vertical = true, .childOffset = Clay_GetScrollOffset() }, .border = { .color = CLAY__DEBUGVIEW_COLOR_3, .width = { .betweenChildren = 1 } } }) { - CLAY({ .layout = { .sizing = {CLAY_SIZING_GROW(0), CLAY_SIZING_FIXED(CLAY__DEBUGVIEW_ROW_HEIGHT + 8)}, .padding = {CLAY__DEBUGVIEW_OUTER_PADDING, CLAY__DEBUGVIEW_OUTER_PADDING, 0, 0 }, .childAlignment = {.y = CLAY_ALIGN_Y_CENTER} } }) { + CLAY_AUTO_ID({ .layout = { .sizing = {CLAY_SIZING_GROW(0), CLAY_SIZING_FIXED(CLAY__DEBUGVIEW_ROW_HEIGHT + 8)}, .padding = {CLAY__DEBUGVIEW_OUTER_PADDING, CLAY__DEBUGVIEW_OUTER_PADDING, 0, 0 }, .childAlignment = {.y = CLAY_ALIGN_Y_CENTER} } }) { CLAY_TEXT(CLAY_STRING("Layout Config"), infoTextConfig); - CLAY({ .layout = { .sizing = { .width = CLAY_SIZING_GROW(0) } } }) {} + CLAY_AUTO_ID({ .layout = { .sizing = { .width = CLAY_SIZING_GROW(0) } } }) {} if (selectedItem->elementId.stringId.length != 0) { CLAY_TEXT(selectedItem->elementId.stringId, infoTitleConfig); if (selectedItem->elementId.offset != 0) { @@ -3485,10 +3529,10 @@ void Clay__RenderDebugView(void) { } Clay_Padding attributeConfigPadding = {CLAY__DEBUGVIEW_OUTER_PADDING, CLAY__DEBUGVIEW_OUTER_PADDING, 8, 8}; // Clay_LayoutConfig debug info - CLAY({ .layout = { .padding = attributeConfigPadding, .childGap = 8, .layoutDirection = CLAY_TOP_TO_BOTTOM } }) { + CLAY_AUTO_ID({ .layout = { .padding = attributeConfigPadding, .childGap = 8, .layoutDirection = CLAY_TOP_TO_BOTTOM } }) { // .boundingBox CLAY_TEXT(CLAY_STRING("Bounding Box"), infoTitleConfig); - CLAY({ .layout = { .layoutDirection = CLAY_LEFT_TO_RIGHT } }) { + CLAY_AUTO_ID({ .layout = { .layoutDirection = CLAY_LEFT_TO_RIGHT } }) { CLAY_TEXT(CLAY_STRING("{ x: "), infoTextConfig); CLAY_TEXT(Clay__IntToString(selectedItem->boundingBox.x), infoTextConfig); CLAY_TEXT(CLAY_STRING(", y: "), infoTextConfig); @@ -3505,17 +3549,17 @@ void Clay__RenderDebugView(void) { CLAY_TEXT(layoutConfig->layoutDirection == CLAY_TOP_TO_BOTTOM ? CLAY_STRING("TOP_TO_BOTTOM") : CLAY_STRING("LEFT_TO_RIGHT"), infoTextConfig); // .sizing CLAY_TEXT(CLAY_STRING("Sizing"), infoTitleConfig); - CLAY({ .layout = { .layoutDirection = CLAY_LEFT_TO_RIGHT } }) { + CLAY_AUTO_ID({ .layout = { .layoutDirection = CLAY_LEFT_TO_RIGHT } }) { CLAY_TEXT(CLAY_STRING("width: "), infoTextConfig); Clay__RenderDebugLayoutSizing(layoutConfig->sizing.width, infoTextConfig); } - CLAY({ .layout = { .layoutDirection = CLAY_LEFT_TO_RIGHT } }) { + CLAY_AUTO_ID({ .layout = { .layoutDirection = CLAY_LEFT_TO_RIGHT } }) { CLAY_TEXT(CLAY_STRING("height: "), infoTextConfig); Clay__RenderDebugLayoutSizing(layoutConfig->sizing.height, infoTextConfig); } // .padding CLAY_TEXT(CLAY_STRING("Padding"), infoTitleConfig); - CLAY({ .id = CLAY_ID("Clay__DebugViewElementInfoPadding") }) { + CLAY(CLAY_ID("Clay__DebugViewElementInfoPadding"), { }) { CLAY_TEXT(CLAY_STRING("{ left: "), infoTextConfig); CLAY_TEXT(Clay__IntToString(layoutConfig->padding.left), infoTextConfig); CLAY_TEXT(CLAY_STRING(", right: "), infoTextConfig); @@ -3531,7 +3575,7 @@ void Clay__RenderDebugView(void) { CLAY_TEXT(Clay__IntToString(layoutConfig->childGap), infoTextConfig); // .childAlignment CLAY_TEXT(CLAY_STRING("Child Alignment"), infoTitleConfig); - CLAY({ .layout = { .layoutDirection = CLAY_LEFT_TO_RIGHT } }) { + CLAY_AUTO_ID({ .layout = { .layoutDirection = CLAY_LEFT_TO_RIGHT } }) { CLAY_TEXT(CLAY_STRING("{ x: "), infoTextConfig); Clay_String alignX = CLAY_STRING("LEFT"); if (layoutConfig->childAlignment.x == CLAY_ALIGN_X_CENTER) { @@ -3557,7 +3601,7 @@ void Clay__RenderDebugView(void) { switch (elementConfig->type) { case CLAY__ELEMENT_CONFIG_TYPE_SHARED: { Clay_SharedElementConfig *sharedConfig = elementConfig->config.sharedElementConfig; - CLAY({ .layout = { .padding = attributeConfigPadding, .childGap = 8, .layoutDirection = CLAY_TOP_TO_BOTTOM }}) { + CLAY_AUTO_ID({ .layout = { .padding = attributeConfigPadding, .childGap = 8, .layoutDirection = CLAY_TOP_TO_BOTTOM }}) { // .backgroundColor CLAY_TEXT(CLAY_STRING("Background Color"), infoTitleConfig); Clay__RenderDebugViewColor(sharedConfig->backgroundColor, infoTextConfig); @@ -3569,7 +3613,7 @@ void Clay__RenderDebugView(void) { } case CLAY__ELEMENT_CONFIG_TYPE_TEXT: { Clay_TextElementConfig *textConfig = elementConfig->config.textElementConfig; - CLAY({ .layout = { .padding = attributeConfigPadding, .childGap = 8, .layoutDirection = CLAY_TOP_TO_BOTTOM } }) { + CLAY_AUTO_ID({ .layout = { .padding = attributeConfigPadding, .childGap = 8, .layoutDirection = CLAY_TOP_TO_BOTTOM } }) { // .fontSize CLAY_TEXT(CLAY_STRING("Font Size"), infoTitleConfig); CLAY_TEXT(Clay__IntToString(textConfig->fontSize), infoTextConfig); @@ -3608,10 +3652,19 @@ void Clay__RenderDebugView(void) { } case CLAY__ELEMENT_CONFIG_TYPE_ASPECT: { Clay_AspectRatioElementConfig *aspectRatioConfig = elementConfig->config.aspectRatioElementConfig; - CLAY({ .id = CLAY_ID("Clay__DebugViewElementInfoAspectRatioBody"), .layout = { .padding = attributeConfigPadding, .childGap = 8, .layoutDirection = CLAY_TOP_TO_BOTTOM } }) { + CLAY(CLAY_ID("Clay__DebugViewElementInfoAspectRatioBody"), { .layout = { .padding = attributeConfigPadding, .childGap = 8, .layoutDirection = CLAY_TOP_TO_BOTTOM } }) { CLAY_TEXT(CLAY_STRING("Aspect Ratio"), infoTitleConfig); // Aspect Ratio - CLAY_TEXT(Clay__IntToString(aspectRatioConfig->aspectRatio), infoTextConfig); + CLAY(CLAY_ID("Clay__DebugViewElementInfoAspectRatio"), { }) { + CLAY_TEXT(Clay__IntToString(aspectRatioConfig->aspectRatio), infoTextConfig); + CLAY_TEXT(CLAY_STRING("."), infoTextConfig); + float frac = aspectRatioConfig->aspectRatio - (int)(aspectRatioConfig->aspectRatio); + frac *= 100; + if ((int)frac < 10) { + CLAY_TEXT(CLAY_STRING("0"), infoTextConfig); + } + CLAY_TEXT(Clay__IntToString(frac), infoTextConfig); + } } break; } @@ -3621,16 +3674,16 @@ void Clay__RenderDebugView(void) { if (Clay__ElementHasConfig(selectedItem->layoutElement, CLAY__ELEMENT_CONFIG_TYPE_ASPECT)) { aspectConfig = *Clay__FindElementConfigWithType(selectedItem->layoutElement, CLAY__ELEMENT_CONFIG_TYPE_ASPECT).aspectRatioElementConfig; } - CLAY({ .id = CLAY_ID("Clay__DebugViewElementInfoImageBody"), .layout = { .padding = attributeConfigPadding, .childGap = 8, .layoutDirection = CLAY_TOP_TO_BOTTOM } }) { + CLAY(CLAY_ID("Clay__DebugViewElementInfoImageBody"), { .layout = { .padding = attributeConfigPadding, .childGap = 8, .layoutDirection = CLAY_TOP_TO_BOTTOM } }) { // Image Preview CLAY_TEXT(CLAY_STRING("Preview"), infoTitleConfig); - CLAY({ .layout = { .sizing = { .width = CLAY_SIZING_GROW(64, 128), .height = CLAY_SIZING_GROW(64, 128) }}, .aspectRatio = aspectConfig, .image = *imageConfig }) {} + CLAY_AUTO_ID({ .layout = { .sizing = { .width = CLAY_SIZING_GROW(64, 128), .height = CLAY_SIZING_GROW(64, 128) }}, .aspectRatio = aspectConfig, .image = *imageConfig }) {} } break; } case CLAY__ELEMENT_CONFIG_TYPE_CLIP: { Clay_ClipElementConfig *clipConfig = elementConfig->config.clipElementConfig; - CLAY({ .layout = { .padding = attributeConfigPadding, .childGap = 8, .layoutDirection = CLAY_TOP_TO_BOTTOM } }) { + CLAY_AUTO_ID({ .layout = { .padding = attributeConfigPadding, .childGap = 8, .layoutDirection = CLAY_TOP_TO_BOTTOM } }) { // .vertical CLAY_TEXT(CLAY_STRING("Vertical"), infoTitleConfig); CLAY_TEXT(clipConfig->vertical ? CLAY_STRING("true") : CLAY_STRING("false") , infoTextConfig); @@ -3642,10 +3695,10 @@ void Clay__RenderDebugView(void) { } case CLAY__ELEMENT_CONFIG_TYPE_FLOATING: { Clay_FloatingElementConfig *floatingConfig = elementConfig->config.floatingElementConfig; - CLAY({ .layout = { .padding = attributeConfigPadding, .childGap = 8, .layoutDirection = CLAY_TOP_TO_BOTTOM } }) { + CLAY_AUTO_ID({ .layout = { .padding = attributeConfigPadding, .childGap = 8, .layoutDirection = CLAY_TOP_TO_BOTTOM } }) { // .offset CLAY_TEXT(CLAY_STRING("Offset"), infoTitleConfig); - CLAY({ .layout = { .layoutDirection = CLAY_LEFT_TO_RIGHT } }) { + CLAY_AUTO_ID({ .layout = { .layoutDirection = CLAY_LEFT_TO_RIGHT } }) { CLAY_TEXT(CLAY_STRING("{ x: "), infoTextConfig); CLAY_TEXT(Clay__IntToString(floatingConfig->offset.x), infoTextConfig); CLAY_TEXT(CLAY_STRING(", y: "), infoTextConfig); @@ -3654,7 +3707,7 @@ void Clay__RenderDebugView(void) { } // .expand CLAY_TEXT(CLAY_STRING("Expand"), infoTitleConfig); - CLAY({ .layout = { .layoutDirection = CLAY_LEFT_TO_RIGHT } }) { + CLAY_AUTO_ID({ .layout = { .layoutDirection = CLAY_LEFT_TO_RIGHT } }) { CLAY_TEXT(CLAY_STRING("{ width: "), infoTextConfig); CLAY_TEXT(Clay__IntToString(floatingConfig->expand.width), infoTextConfig); CLAY_TEXT(CLAY_STRING(", height: "), infoTextConfig); @@ -3670,7 +3723,7 @@ void Clay__RenderDebugView(void) { CLAY_TEXT(hashItem->elementId.stringId, infoTextConfig); // .attachPoints CLAY_TEXT(CLAY_STRING("Attach Points"), infoTitleConfig); - CLAY({ .layout = { .layoutDirection = CLAY_LEFT_TO_RIGHT } }) { + CLAY_AUTO_ID({ .layout = { .layoutDirection = CLAY_LEFT_TO_RIGHT } }) { CLAY_TEXT(CLAY_STRING("{ element: "), infoTextConfig); Clay_String attachPointElement = CLAY_STRING("LEFT_TOP"); if (floatingConfig->attachPoints.element == CLAY_ATTACH_POINT_LEFT_CENTER) { @@ -3743,9 +3796,9 @@ void Clay__RenderDebugView(void) { } case CLAY__ELEMENT_CONFIG_TYPE_BORDER: { Clay_BorderElementConfig *borderConfig = elementConfig->config.borderElementConfig; - CLAY({ .id = CLAY_ID("Clay__DebugViewElementInfoBorderBody"), .layout = { .padding = attributeConfigPadding, .childGap = 8, .layoutDirection = CLAY_TOP_TO_BOTTOM } }) { + CLAY(CLAY_ID("Clay__DebugViewElementInfoBorderBody"), { .layout = { .padding = attributeConfigPadding, .childGap = 8, .layoutDirection = CLAY_TOP_TO_BOTTOM } }) { CLAY_TEXT(CLAY_STRING("Border Widths"), infoTitleConfig); - CLAY({ .layout = { .layoutDirection = CLAY_LEFT_TO_RIGHT } }) { + CLAY_AUTO_ID({ .layout = { .layoutDirection = CLAY_LEFT_TO_RIGHT } }) { CLAY_TEXT(CLAY_STRING("{ left: "), infoTextConfig); CLAY_TEXT(Clay__IntToString(borderConfig->width.left), infoTextConfig); CLAY_TEXT(CLAY_STRING(", right: "), infoTextConfig); @@ -3768,16 +3821,16 @@ void Clay__RenderDebugView(void) { } } } else { - CLAY({ .id = CLAY_ID("Clay__DebugViewWarningsScrollPane"), .layout = { .sizing = {CLAY_SIZING_GROW(0), CLAY_SIZING_FIXED(300)}, .childGap = 6, .layoutDirection = CLAY_TOP_TO_BOTTOM }, .backgroundColor = CLAY__DEBUGVIEW_COLOR_2, .clip = { .horizontal = true, .vertical = true, .childOffset = Clay_GetScrollOffset() } }) { + CLAY(CLAY_ID("Clay__DebugViewWarningsScrollPane"), { .layout = { .sizing = {CLAY_SIZING_GROW(0), CLAY_SIZING_FIXED(300)}, .childGap = 6, .layoutDirection = CLAY_TOP_TO_BOTTOM }, .backgroundColor = CLAY__DEBUGVIEW_COLOR_2, .clip = { .horizontal = true, .vertical = true, .childOffset = Clay_GetScrollOffset() } }) { Clay_TextElementConfig *warningConfig = CLAY_TEXT_CONFIG({ .textColor = CLAY__DEBUGVIEW_COLOR_4, .fontSize = 16, .wrapMode = CLAY_TEXT_WRAP_NONE }); - CLAY({ .id = CLAY_ID("Clay__DebugViewWarningItemHeader"), .layout = { .sizing = {.height = CLAY_SIZING_FIXED(CLAY__DEBUGVIEW_ROW_HEIGHT)}, .padding = {CLAY__DEBUGVIEW_OUTER_PADDING, CLAY__DEBUGVIEW_OUTER_PADDING, 0, 0 }, .childGap = 8, .childAlignment = {.y = CLAY_ALIGN_Y_CENTER} } }) { + CLAY(CLAY_ID("Clay__DebugViewWarningItemHeader"), { .layout = { .sizing = {.height = CLAY_SIZING_FIXED(CLAY__DEBUGVIEW_ROW_HEIGHT)}, .padding = {CLAY__DEBUGVIEW_OUTER_PADDING, CLAY__DEBUGVIEW_OUTER_PADDING, 0, 0 }, .childGap = 8, .childAlignment = {.y = CLAY_ALIGN_Y_CENTER} } }) { CLAY_TEXT(CLAY_STRING("Warnings"), warningConfig); } - CLAY({ .id = CLAY_ID("Clay__DebugViewWarningsTopBorder"), .layout = { .sizing = { .width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIXED(1)} }, .backgroundColor = {200, 200, 200, 255} }) {} + CLAY(CLAY_ID("Clay__DebugViewWarningsTopBorder"), { .layout = { .sizing = { .width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIXED(1)} }, .backgroundColor = {200, 200, 200, 255} }) {} int32_t previousWarningsLength = context->warnings.length; for (int32_t i = 0; i < previousWarningsLength; i++) { Clay__Warning warning = context->warnings.internalArray[i]; - CLAY({ .id = CLAY_IDI("Clay__DebugViewWarningItem", i), .layout = { .sizing = {.height = CLAY_SIZING_FIXED(CLAY__DEBUGVIEW_ROW_HEIGHT)}, .padding = {CLAY__DEBUGVIEW_OUTER_PADDING, CLAY__DEBUGVIEW_OUTER_PADDING, 0, 0 }, .childGap = 8, .childAlignment = {.y = CLAY_ALIGN_Y_CENTER} } }) { + CLAY(CLAY_IDI("Clay__DebugViewWarningItem", i), { .layout = { .sizing = {.height = CLAY_SIZING_FIXED(CLAY__DEBUGVIEW_ROW_HEIGHT)}, .padding = {CLAY__DEBUGVIEW_OUTER_PADDING, CLAY__DEBUGVIEW_OUTER_PADDING, 0, 0 }, .childGap = 8, .childAlignment = {.y = CLAY_ALIGN_Y_CENTER} } }) { CLAY_TEXT(warning.baseMessage, warningConfig); if (warning.dynamicMessage.length > 0) { CLAY_TEXT(warning.dynamicMessage, warningConfig); @@ -3822,7 +3875,7 @@ Clay__Warning *Clay__WarningArray_Add(Clay__WarningArray *array, Clay__Warning i void* Clay__Array_Allocate_Arena(int32_t capacity, uint32_t itemSize, Clay_Arena *arena) { size_t totalSizeBytes = capacity * itemSize; - uintptr_t nextAllocOffset = arena->nextAllocation + (64 - (arena->nextAllocation % 64)); + uintptr_t nextAllocOffset = arena->nextAllocation + ((64 - (arena->nextAllocation % 64)) & 63); if (nextAllocOffset + totalSizeBytes <= arena->capacity) { arena->nextAllocation = nextAllocOffset + totalSizeBytes; return (void*)((uintptr_t)arena->memory + (uintptr_t)nextAllocOffset); @@ -3942,16 +3995,12 @@ void Clay_SetPointerState(Clay_Vector2 position, bool isPointerDown) { Clay_BoundingBox elementBox = mapItem->boundingBox; elementBox.x -= root->pointerOffset.x; elementBox.y -= root->pointerOffset.y; - if ((Clay__PointIsInsideRect(position, elementBox)) && (clipElementId == 0 || (Clay__PointIsInsideRect(position, clipItem->boundingBox)))) { + if ((Clay__PointIsInsideRect(position, elementBox)) && (clipElementId == 0 || (Clay__PointIsInsideRect(position, clipItem->boundingBox)) || context->externalScrollHandlingEnabled)) { if (mapItem->onHoverFunction) { mapItem->onHoverFunction(mapItem->elementId, context->pointerInfo, mapItem->hoverFunctionUserData); } Clay_ElementIdArray_Add(&context->pointerOverIds, mapItem->elementId); found = true; - - if (mapItem->idAlias != 0) { - Clay_ElementIdArray_Add(&context->pointerOverIds, CLAY__INIT(Clay_ElementId) { .id = mapItem->idAlias }); - } } if (Clay__ElementHasConfig(currentElement, CLAY__ELEMENT_CONFIG_TYPE_TEXT)) { dfsBuffer.length--; @@ -3990,6 +4039,10 @@ void Clay_SetPointerState(Clay_Vector2 position, bool isPointerDown) { CLAY_WASM_EXPORT("Clay_Initialize") Clay_Context* Clay_Initialize(Clay_Arena arena, Clay_Dimensions layoutDimensions, Clay_ErrorHandler errorHandler) { + // Cacheline align memory passed in + uintptr_t baseOffset = 64 - ((uintptr_t)arena.memory % 64); + baseOffset = baseOffset == 64 ? 0 : baseOffset; + arena.memory += baseOffset; Clay_Context *context = Clay__Context_Allocate_Arena(&arena); if (context == NULL) return NULL; // DEFAULTS @@ -4171,10 +4224,9 @@ void Clay_BeginLayout(void) { rootDimensions.width -= (float)Clay__debugViewWidth; } context->booleanWarnings = CLAY__INIT(Clay_BooleanWarnings) CLAY__DEFAULT_STRUCT; - Clay__OpenElement(); + Clay__OpenElementWithId(CLAY_ID("Clay__RootContainer")); Clay__ConfigureOpenElement(CLAY__INIT(Clay_ElementDeclaration) { - .id = CLAY_ID("Clay__RootContainer"), - .layout = { .sizing = {CLAY_SIZING_FIXED((rootDimensions.width)), CLAY_SIZING_FIXED(rootDimensions.height)} } + .layout = { .sizing = {CLAY_SIZING_FIXED((rootDimensions.width)), CLAY_SIZING_FIXED(rootDimensions.height)} } }); Clay__int32_tArray_Add(&context->openLayoutElementStack, 0); Clay__LayoutElementTreeRootArray_Add(&context->layoutElementTreeRoots, CLAY__INIT(Clay__LayoutElementTreeRoot) { .layoutElementIndex = 0 }); @@ -4202,20 +4254,25 @@ Clay_RenderCommandArray Clay_EndLayout(void) { .renderData = { .text = { .stringContents = CLAY__INIT(Clay_StringSlice) { .length = message.length, .chars = message.chars, .baseChars = message.chars }, .textColor = {255, 0, 0, 255}, .fontSize = 16 } }, .commandType = CLAY_RENDER_COMMAND_TYPE_TEXT }); - } else { - Clay__CalculateFinalLayout(); } + if (context->openLayoutElementStack.length > 1) { + context->errorHandler.errorHandlerFunction(CLAY__INIT(Clay_ErrorData) { + .errorType = CLAY_ERROR_TYPE_UNBALANCED_OPEN_CLOSE, + .errorText = CLAY_STRING("There were still open layout elements when EndLayout was called. This results from an unequal number of calls to Clay__OpenElement and Clay__CloseElement."), + .userData = context->errorHandler.userData }); + } + Clay__CalculateFinalLayout(); return context->renderCommands; } CLAY_WASM_EXPORT("Clay_GetElementId") Clay_ElementId Clay_GetElementId(Clay_String idString) { - return Clay__HashString(idString, 0, 0); + return Clay__HashString(idString, 0); } CLAY_WASM_EXPORT("Clay_GetElementIdWithIndex") Clay_ElementId Clay_GetElementIdWithIndex(Clay_String idString, uint32_t index) { - return Clay__HashString(idString, index, 0); + return Clay__HashStringWithOffset(idString, index, 0); } bool Clay_Hovered(void) { @@ -4236,7 +4293,7 @@ bool Clay_Hovered(void) { 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(); if (context->booleanWarnings.maxElementsExceeded) { return; diff --git a/src/DrawingProgram/DrawingProgram.cpp b/src/DrawingProgram/DrawingProgram.cpp index 8c0d6ed..856e946 100644 --- a/src/DrawingProgram/DrawingProgram.cpp +++ b/src/DrawingProgram/DrawingProgram.cpp @@ -189,7 +189,7 @@ void DrawingProgram::clear_draw_cache() { void DrawingProgram::toolbar_gui() { Toolbar& t = world.main.toolbar; t.gui.push_id("Drawing Program Toolbar GUI"); - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_FIT(0), .height = CLAY_SIZING_FIT(0)}, .padding = CLAY_PADDING_ALL(static_cast(t.io->theme->padding1 / 2)), @@ -267,7 +267,7 @@ bool DrawingProgram::right_click_popup_gui(Vector2f popupPos) { void DrawingProgram::tool_options_gui() { Toolbar& t = world.main.toolbar; float minGUIWidth = drawTool->get_type() == DrawingProgramToolType::SCREENSHOT ? 300 : 200; - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_FIT(minGUIWidth), .height = CLAY_SIZING_FIT(0)}, .padding = CLAY_PADDING_ALL(t.io->theme->padding1), diff --git a/src/GUIStuff/Elements/CheckBox.cpp b/src/GUIStuff/Elements/CheckBox.cpp index 1a256ab..c000bf1 100644 --- a/src/GUIStuff/Elements/CheckBox.cpp +++ b/src/GUIStuff/Elements/CheckBox.cpp @@ -6,7 +6,7 @@ namespace GUIStuff { void CheckBox::update(UpdateInputData& io, bool newIsTicked, const std::function& elemUpdate) { - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_FIXED(15), .height = CLAY_SIZING_FIXED(15)} }, diff --git a/src/GUIStuff/Elements/ColorPicker.hpp b/src/GUIStuff/Elements/ColorPicker.hpp index d906f35..5655c02 100644 --- a/src/GUIStuff/Elements/ColorPicker.hpp +++ b/src/GUIStuff/Elements/ColorPicker.hpp @@ -22,7 +22,7 @@ template class ColorPicker : public Element { force_update_colorpicker(data); - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0) } }, diff --git a/src/GUIStuff/Elements/FontPicker.cpp b/src/GUIStuff/Elements/FontPicker.cpp index b341fae..1156eb2 100644 --- a/src/GUIStuff/Elements/FontPicker.cpp +++ b/src/GUIStuff/Elements/FontPicker.cpp @@ -46,7 +46,7 @@ bool GUIStuff::FontPicker::update(UpdateInputData& io, std::string* fontName, GU const float ENTRY_HEIGHT = 25.0f; - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_FIXED(250), .height = CLAY_SIZING_FIT(0)}, .childGap = 4 @@ -78,7 +78,7 @@ bool GUIStuff::FontPicker::update(UpdateInputData& io, std::string* fontName, GU clickedOut = false; } if(dropdownOpen) { - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_FIXED(250), .height = CLAY_SIZING_FIT(0, 300)}, .layoutDirection = CLAY_TOP_TO_BOTTOM @@ -129,7 +129,7 @@ bool GUIStuff::FontPicker::update(UpdateInputData& io, std::string* fontName, GU auto p = pBuilder.Build(); - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_FIXED(250), .height = CLAY_SIZING_FIXED(25)}, .childGap = 1, @@ -144,7 +144,7 @@ bool GUIStuff::FontPicker::update(UpdateInputData& io, std::string* fontName, GU entryColor = io.theme->backColor2; else entryColor = io.theme->backColor1; - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIXED(25)}, .padding = {.left = 2, .right = 2}, @@ -165,7 +165,7 @@ bool GUIStuff::FontPicker::update(UpdateInputData& io, std::string* fontName, GU scrollAmount = -static_cast(val) * ENTRY_HEIGHT; }); #ifdef __EMSCRIPTEN__ - CLAY({ + CLAY_AUTO_ID({ .layout = { .padding = CLAY_PADDING_ALL(io.theme->padding1) }}) { diff --git a/src/GUIStuff/Elements/MovableTabList.cpp b/src/GUIStuff/Elements/MovableTabList.cpp index 5f41990..75c7080 100644 --- a/src/GUIStuff/Elements/MovableTabList.cpp +++ b/src/GUIStuff/Elements/MovableTabList.cpp @@ -15,7 +15,7 @@ void MovableTabList::update(UpdateInputData& io, const std::vectorstd_str_to_clay_str(tabNames[i].second), CLAY_TEXT_CONFIG({.textColor = convert_vec4(io.theme->frontColor1), .fontSize = io.fontSize })); if(s.clicked) selectedTab = i; - CLAY({.layout = {.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)}}}) {} - CLAY({.layout = { + CLAY_AUTO_ID({.layout = {.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)}}}) {} + CLAY_AUTO_ID({.layout = { .sizing = {.width = CLAY_SIZING_FIXED(GUIStuff::GUIManager::SMALL_BUTTON_SIZE), .height = CLAY_SIZING_FIXED(GUIStuff::GUIManager::SMALL_BUTTON_SIZE)}, .childAlignment = { .x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_CENTER }, .layoutDirection = CLAY_LEFT_TO_RIGHT diff --git a/src/GUIStuff/Elements/NumberSlider.hpp b/src/GUIStuff/Elements/NumberSlider.hpp index 2f45e94..2345005 100644 --- a/src/GUIStuff/Elements/NumberSlider.hpp +++ b/src/GUIStuff/Elements/NumberSlider.hpp @@ -11,7 +11,7 @@ template class NumberSlider : public Element { min = minNew; max = maxNew; - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_GROW(100), .height = CLAY_SIZING_FIXED(10)} }, diff --git a/src/GUIStuff/Elements/PaintCircleMenu.cpp b/src/GUIStuff/Elements/PaintCircleMenu.cpp index 130aa2a..6fde436 100644 --- a/src/GUIStuff/Elements/PaintCircleMenu.cpp +++ b/src/GUIStuff/Elements/PaintCircleMenu.cpp @@ -11,7 +11,7 @@ constexpr double ROTATE_BAR_SNAP_DISTANCE = 0.2; constexpr double ROTATE_BAR_SNAP_DISTRIBUTION = std::numbers::pi * 0.25; void PaintCircleMenu::update(UpdateInputData& io, const Data& data, const std::function& elemUpdate) { - CLAY({.layout = { + CLAY_AUTO_ID({.layout = { .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)} }, .custom = { .customData = this } diff --git a/src/GUIStuff/Elements/RadioButton.cpp b/src/GUIStuff/Elements/RadioButton.cpp index cdd3f10..b1a0262 100644 --- a/src/GUIStuff/Elements/RadioButton.cpp +++ b/src/GUIStuff/Elements/RadioButton.cpp @@ -3,7 +3,7 @@ namespace GUIStuff { void RadioButton::update(UpdateInputData& io, bool newIsTicked, const std::function& elemUpdate) { - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_FIXED(20), .height = CLAY_SIZING_FIXED(20)} }, diff --git a/src/GUIStuff/Elements/RotateWheel.cpp b/src/GUIStuff/Elements/RotateWheel.cpp index d307890..95ea4ed 100644 --- a/src/GUIStuff/Elements/RotateWheel.cpp +++ b/src/GUIStuff/Elements/RotateWheel.cpp @@ -13,7 +13,7 @@ void RotateWheel::update(UpdateInputData& io, double* newRotationAnglePtr, const if(!newRotationAnglePtr) return; - CLAY({.layout = { + CLAY_AUTO_ID({.layout = { .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)} }, .custom = { .customData = this } diff --git a/src/GUIStuff/Elements/SVGIcon.cpp b/src/GUIStuff/Elements/SVGIcon.cpp index 73fb3b0..a395e91 100644 --- a/src/GUIStuff/Elements/SVGIcon.cpp +++ b/src/GUIStuff/Elements/SVGIcon.cpp @@ -15,7 +15,7 @@ void SVGIcon::update(UpdateInputData& io, const std::string& newSvgPath, bool ne highlighted = newIsHighlighted; - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0) } }, diff --git a/src/GUIStuff/Elements/SelectableButton.cpp b/src/GUIStuff/Elements/SelectableButton.cpp index d4f1863..c7f4687 100644 --- a/src/GUIStuff/Elements/SelectableButton.cpp +++ b/src/GUIStuff/Elements/SelectableButton.cpp @@ -29,7 +29,7 @@ void SelectableButton::update(UpdateInputData& io, DrawType drawType, const std: else backgroundColor = io.theme->fillColor2; - CLAY({.layout = { + CLAY_AUTO_ID({.layout = { .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)}, .childGap = 0, .childAlignment = { .x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_CENTER } @@ -41,7 +41,7 @@ void SelectableButton::update(UpdateInputData& io, DrawType drawType, const std: .width = CLAY_BORDER_OUTSIDE(2) } }) { - CLAY({.layout = { + CLAY_AUTO_ID({.layout = { .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)}, .padding = (drawType == DrawType::TRANSPARENT_BORDER) ? CLAY_PADDING_ALL(0) : CLAY_PADDING_ALL(4), .childAlignment = { .x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_CENTER }, diff --git a/src/GUIStuff/Elements/TextBox.hpp b/src/GUIStuff/Elements/TextBox.hpp index c880648..e4d52cc 100644 --- a/src/GUIStuff/Elements/TextBox.hpp +++ b/src/GUIStuff/Elements/TextBox.hpp @@ -23,7 +23,7 @@ template class TextBox : public Element { textbox->set_width(std::numeric_limits::max()); //textbox->set_text_direction_between(0, 0, textbox->get_suggested_direction(0)); - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_GROW(static_cast(io.fontSize * 2)), .height = CLAY_SIZING_FIXED(static_cast(io.fontSize * 1.25f))} }, diff --git a/src/GUIStuff/Elements/TextParagraph.cpp b/src/GUIStuff/Elements/TextParagraph.cpp index a07ec51..7d7a941 100644 --- a/src/GUIStuff/Elements/TextParagraph.cpp +++ b/src/GUIStuff/Elements/TextParagraph.cpp @@ -7,7 +7,7 @@ namespace GUIStuff { void TextParagraph::update(UpdateInputData& io, std::unique_ptr paragraph, float width, const std::function& elemUpdate) { data = std::move(paragraph); data->layout(width); - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_FIXED(width), .height = CLAY_SIZING_FIXED(data->getHeight())} }, diff --git a/src/GUIStuff/GUIManager.cpp b/src/GUIStuff/GUIManager.cpp index 7f8fcea..408e0d3 100644 --- a/src/GUIStuff/GUIManager.cpp +++ b/src/GUIStuff/GUIManager.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -245,7 +246,7 @@ void GUIManager::draw(SkCanvas* canvas) { } void GUIManager::top_to_bottom_window_popup_layout(Clay_SizingAxis x, Clay_SizingAxis y, const std::function& elemUpdate) { - CLAY({.layout = { + CLAY_AUTO_ID({.layout = { .sizing = {.width = x, .height = y }, .padding = CLAY_PADDING_ALL(io->theme->padding1), .childGap = io->theme->childGap1, @@ -263,7 +264,7 @@ void GUIManager::top_to_bottom_window_popup_layout(Clay_SizingAxis x, Clay_Sizin } void GUIManager::left_to_right_layout(Clay_SizingAxis x, Clay_SizingAxis y, const std::function& elemUpdate) { - CLAY({.layout = { + CLAY_AUTO_ID({.layout = { .sizing = {.width = x, .height = y }, .childGap = io->theme->childGap1, .childAlignment = {.x = CLAY_ALIGN_X_LEFT, .y = CLAY_ALIGN_Y_CENTER}, @@ -279,7 +280,7 @@ void GUIManager::left_to_right_line_layout(const std::function& elemUpda } void GUIManager::left_to_right_line_centered_layout(const std::function& elemUpdate) { - CLAY({.layout = { + CLAY_AUTO_ID({.layout = { .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIT(0) }, .childGap = io->theme->childGap1, .childAlignment = {.x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_CENTER}, @@ -307,7 +308,7 @@ void GUIManager::text_label(const std::string& val) { } void GUIManager::text_label_centered(const std::string& val) { - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIT(0) }, .childAlignment = {.x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_CENTER}, @@ -318,7 +319,7 @@ void GUIManager::text_label_centered(const std::string& val) { } void GUIManager::text_label_light_centered(const std::string& val) { - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIT(0) }, .childAlignment = {.x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_CENTER}, @@ -426,7 +427,7 @@ void GUIManager::svg_icon(const std::string& id, const std::string& svgPath, boo bool GUIManager::svg_icon_button(const std::string& id, const std::string& svgPath, bool isSelected, float size, bool hasBorder, const std::function& elemUpdate) { bool toRet = false; push_id(id); - CLAY ({.layout = {.sizing = {.width = CLAY_SIZING_FIXED(size), .height = CLAY_SIZING_FIXED(size) } } }) { + CLAY_AUTO_ID({.layout = {.sizing = {.width = CLAY_SIZING_FIXED(size), .height = CLAY_SIZING_FIXED(size) } } }) { toRet = selectable_button("0", [&](SelectionHelper& s, bool is) { svg_icon("1", svgPath, is || s.held || s.hovered); if(elemUpdate) @@ -440,7 +441,7 @@ bool GUIManager::svg_icon_button(const std::string& id, const std::string& svgPa bool GUIManager::svg_icon_button_transparent(const std::string& id, const std::string& svgPath, bool isSelected, float size, bool hasBorder, const std::function& elemUpdate) { bool toRet = false; push_id(id); - CLAY ({.layout = {.sizing = {.width = CLAY_SIZING_FIXED(size), .height = CLAY_SIZING_FIXED(size) } } }) { + CLAY_AUTO_ID({.layout = {.sizing = {.width = CLAY_SIZING_FIXED(size), .height = CLAY_SIZING_FIXED(size) } } }) { toRet = selectable_button("0", [&](SelectionHelper& s, bool is) { svg_icon("1", svgPath, is || s.held || s.hovered); if(elemUpdate) @@ -453,7 +454,7 @@ bool GUIManager::svg_icon_button_transparent(const std::string& id, const std::s bool GUIManager::text_button_sized(const std::string& id, const std::string& text, Clay_SizingAxis x, Clay_SizingAxis y, bool isSelected, const std::function& elemUpdate) { bool toRet = false; - CLAY ({.layout = {.sizing = {.width = x, .height = y } } }) { + CLAY_AUTO_ID({.layout = {.sizing = {.width = x, .height = y } } }) { toRet = selectable_button(id, [&](SelectionHelper& s, bool iS) { text_label(text); if(elemUpdate) @@ -465,7 +466,7 @@ bool GUIManager::text_button_sized(const std::string& id, const std::string& tex bool GUIManager::text_button(const std::string& id, const std::string& text, bool isSelected, const std::function& elemUpdate) { bool toRet = false; - CLAY ({.layout = {.sizing = {.width = CLAY_SIZING_FIT(0), .height = CLAY_SIZING_FIT(0) } } }) { + CLAY_AUTO_ID({.layout = {.sizing = {.width = CLAY_SIZING_FIT(0), .height = CLAY_SIZING_FIT(0) } } }) { toRet = selectable_button(id, [&](SelectionHelper& s, bool iS) { text_label(text); if(elemUpdate) @@ -477,7 +478,7 @@ bool GUIManager::text_button(const std::string& id, const std::string& text, boo bool GUIManager::text_button_wide(const std::string& id, const std::string& text, bool isSelected, const std::function& elemUpdate) { bool toRet = false; - CLAY ({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIT(0) }, .childAlignment = {.x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_CENTER}, @@ -493,13 +494,13 @@ bool GUIManager::text_button_wide(const std::string& id, const std::string& text bool GUIManager::text_button_left_transparent(const std::string& id, const std::string& text, bool isSelected, const std::function& elemUpdate) { bool toRet = false; - CLAY ({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIT(0) }, .childAlignment = {.x = CLAY_ALIGN_X_LEFT, .y = CLAY_ALIGN_Y_CENTER}, }}) { toRet = selectable_button(id, [&](SelectionHelper& s, bool iS) { - CLAY ({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIT(0) }, .childAlignment = {.x = CLAY_ALIGN_X_LEFT, .y = CLAY_ALIGN_Y_CENTER} @@ -535,11 +536,6 @@ bool GUIManager::input_scalar(const std::string& id, uint8_t* val, uint8_t min, return isUpdating; } -std::string GUIManager::get_clay_unique_id() { - std::string toRet = "CLAY_UNIQUE_ID_" + std::to_string(clayUniqueIDCounter++); - return toRet; -} - void GUIManager::input_path(const std::string& id, std::filesystem::path* val, std::filesystem::file_type fileTypeRestriction, const std::function& elemUpdate) { push_id(id); insert_element>()->update(*io, val, @@ -571,17 +567,12 @@ bool GUIManager::font_picker(const std::string& id, std::string* fontName) { void GUIManager::dropdown_select(const std::string& id, size_t* val, const std::vector& selections, float width, const std::function& hoverboxElemUpdate) { push_id(id); struct DropdownData { - std::string uniqueID; bool isOpen = false; }; - DropdownData& dropdownData = insert_any_with_id_with_function(0, [&]() { - return DropdownData { - .uniqueID = get_clay_unique_id() - }; - }); + DropdownData& dropdownData = insert_any_with_id(0, {}); left_to_right_layout(CLAY_SIZING_FIXED(width), CLAY_SIZING_FIT(0), [&]() { bool click = selectable_button(id, [&](SelectionHelper& s, bool iS) { - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0) }, .padding = {.left = 4, .right = 4}, @@ -591,8 +582,8 @@ void GUIManager::dropdown_select(const std::string& id, size_t* val, const std:: } }) { text_label(selections[*val]); - CLAY({.layout = {.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)}}}) {} - CLAY({ + CLAY_AUTO_ID({.layout = {.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)}}}) {} + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_FIT(SMALL_BUTTON_SIZE), .height = CLAY_SIZING_FIT(SMALL_BUTTON_SIZE)} } @@ -602,13 +593,12 @@ void GUIManager::dropdown_select(const std::string& id, size_t* val, const std:: } }, SelectableButton::DrawType::FILLED, dropdownData.isOpen); if(dropdownData.isOpen) { - Clay_ElementId clayID = Clay_GetElementId(strArena.std_str_to_clay_str(dropdownData.uniqueID)); - Clay_ElementData dropdownElemData = Clay_GetElementData(clayID); + Clay_ElementId localID = CLAY_ID_LOCAL("DROPDOWN"); + Clay_ElementData dropdownElemData = Clay_GetElementData(localID); float calculatedDropdownMaxHeight = 0.0f; if(dropdownElemData.found) calculatedDropdownMaxHeight = std::max(windowSize.y() - dropdownElemData.boundingBox.y - 2.0f, 0.0f); - CLAY({ - .id = clayID, + CLAY(localID, { .layout = { .sizing = {.width = CLAY_SIZING_FIXED(width), .height = CLAY_SIZING_FIT(0, calculatedDropdownMaxHeight)}, .childGap = 0 @@ -634,7 +624,7 @@ void GUIManager::dropdown_select(const std::string& id, size_t* val, const std:: scroll_bar_many_entries_area("dropdown scroll area", 18.0f, selections.size(), true, [&](size_t i, bool) { bool selectedEntry = *val == i; - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_FIXED(250), .height = CLAY_SIZING_FIXED(18)}, .padding = CLAY_PADDING_ALL(0), @@ -650,7 +640,7 @@ void GUIManager::dropdown_select(const std::string& id, size_t* val, const std:: entryColor = io->theme->backColor2; else entryColor = io->theme->backColor1; - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)}, .padding = {.left = 2, .right = 2, .top = 0, .bottom = 0}, @@ -679,7 +669,7 @@ void GUIManager::dropdown_select(const std::string& id, size_t* val, const std:: void GUIManager::scroll_bar_area(const std::string& id, bool clipHorizontal, const std::function& elemUpdate) { push_id(id); - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)}, .childAlignment = {.x = CLAY_ALIGN_X_LEFT, .y = CLAY_ALIGN_Y_TOP}, @@ -695,19 +685,13 @@ void GUIManager::scroll_bar_area(const std::string& id, bool clipHorizontal, con float contentDimensions = 100.0f; float containerDimensions = 100.0f; - std::string uniqueID; }; - ScrollAreaData& sD = insert_any_with_id_with_function(0, [&](){ - return ScrollAreaData{ - .uniqueID = get_clay_unique_id() - }; - }); + ScrollAreaData& sD = insert_any_with_id(0, {}); - Clay_ElementId clayID = Clay_GetElementId(strArena.std_str_to_clay_str(sD.uniqueID)); + Clay_ElementId localID = CLAY_ID_LOCAL("SCROLL_AREA"); - CLAY({ - .id = clayID, + CLAY(localID, { .layout = { .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)}, .childAlignment = {.x = CLAY_ALIGN_X_LEFT, .y = CLAY_ALIGN_Y_TOP}, @@ -721,8 +705,8 @@ void GUIManager::scroll_bar_area(const std::string& id, bool clipHorizontal, con } // Make sure you are accessing this data after the element has been created - Clay_ScrollContainerData scrollData = Clay_GetScrollContainerData(clayID); - Clay_BoundingBox scrollAreaBB = Clay_GetElementData(clayID).boundingBox; + Clay_ScrollContainerData scrollData = Clay_GetScrollContainerData(localID); + Clay_BoundingBox scrollAreaBB = Clay_GetElementData(localID).boundingBox; sD.contentDimensions = scrollData.contentDimensions.height; sD.containerDimensions = scrollData.scrollContainerDimensions.height; @@ -738,7 +722,7 @@ void GUIManager::scroll_bar_area(const std::string& id, bool clipHorizontal, con if(Clay_Hovered()) sD.currentScrollPos += io->mouse.scroll.y() * io->deltaTime * 3000.0f; - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_FIXED(12), .height = CLAY_SIZING_GROW(0)}, .childAlignment = {.x = CLAY_ALIGN_X_LEFT, .y = CLAY_ALIGN_Y_TOP}, @@ -755,12 +739,12 @@ void GUIManager::scroll_bar_area(const std::string& id, bool clipHorizontal, con scrollerColor = io->theme->fillColor2; bool isHoveringOverScroller = false; - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIXED(areaAboveScrollerSize)} } }) {} - CLAY({ + CLAY_AUTO_ID({ .layout = {.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIXED(scrollerSize)}}, .backgroundColor = convert_vec4(scrollerColor), .cornerRadius = CLAY_CORNER_RADIUS(3), @@ -768,7 +752,7 @@ void GUIManager::scroll_bar_area(const std::string& id, bool clipHorizontal, con if(Clay_Hovered()) isHoveringOverScroller = true; } - CLAY({ .layout = {.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)}}}) {} + CLAY_AUTO_ID({ .layout = {.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)}}}) {} if(Clay_Hovered() && io->mouse.leftClick) { sD.isMoving = true; if(isHoveringOverScroller) @@ -809,7 +793,7 @@ void GUIManager::scroll_bar_many_entries_area(const std::string& id, float entry size_t endPoint = std::min(entryCount, startPoint + elementsContainable); if(startPoint != 0) { - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIXED(startPoint * entryHeight)}, } @@ -823,7 +807,7 @@ void GUIManager::scroll_bar_many_entries_area(const std::string& id, float entry } if(endPoint != entryCount) { - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIXED((entryCount - endPoint) * entryHeight)}, } @@ -836,7 +820,7 @@ void GUIManager::scroll_bar_many_entries_area(const std::string& id, float entry bool GUIManager::rotate_wheel(const std::string& id, double* angle, float size, const std::function& elemUpdate) { bool toRet = false; push_id(id); - CLAY ({.layout = {.sizing = {.width = CLAY_SIZING_FIXED(size), .height = CLAY_SIZING_FIXED(size) } } }) { + CLAY_AUTO_ID({.layout = {.sizing = {.width = CLAY_SIZING_FIXED(size), .height = CLAY_SIZING_FIXED(size) } } }) { RotateWheel* e = insert_element(); e->update(*io, angle, elemUpdate); toRet = e->selection.clicked; @@ -855,7 +839,7 @@ void GUIManager::text_paragraph(const std::string& id, std::unique_ptr& elemUpdate) { float size = 300.0f; push_id(id); - CLAY({.layout = { + CLAY_AUTO_ID({.layout = { .sizing = {.width = CLAY_SIZING_FIXED(size), .height = CLAY_SIZING_FIXED(size)} }, .floating = { @@ -871,44 +855,46 @@ void GUIManager::paint_circle_popup_menu(const std::string& id, const Vector2f& } void GUIManager::list_popup_menu(const std::string& id, Vector2f popupPos, const std::function& elemUpdate) { - push_id(id); - - std::string& uniqueID = insert_any_with_id_with_function(0, [&]() { - return get_clay_unique_id(); - }); - - Clay_ElementId clayID = Clay_GetElementId(strArena.std_str_to_clay_str(uniqueID)); - Clay_ElementData actionListElemData = Clay_GetElementData(clayID); - - if(actionListElemData.found) { - if((popupPos.y() + actionListElemData.boundingBox.height) > windowSize.y()) { - popupPos.y() -= actionListElemData.boundingBox.height; - } - } - - CLAY({ - .id = clayID, - .layout = { - .sizing = {.width = CLAY_SIZING_FIT(100), .height = CLAY_SIZING_FIT(0)}, - .padding = CLAY_PADDING_ALL(io->theme->padding1), - .childGap = 1, - .childAlignment = { .x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_TOP}, - .layoutDirection = CLAY_TOP_TO_BOTTOM - }, - .backgroundColor = convert_vec4(io->theme->backColor1), - .cornerRadius = CLAY_CORNER_RADIUS(io->theme->windowCorners1), - .floating = { - .offset = {popupPos.x(), popupPos.y()}, - .zIndex = -1, - .attachTo = CLAY_ATTACH_TO_ROOT + CLAY_AUTO_ID({ + .layout = { + .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)} } }) { - obstructing_window(); - push_id(1); - elemUpdate(); + push_id(id); + + Clay_ElementId localID = CLAY_ID_LOCAL("LIST_POPUP"); + + Clay_ElementData actionListElemData = Clay_GetElementData(localID); + + if(actionListElemData.found) { + if((popupPos.y() + actionListElemData.boundingBox.height) > windowSize.y()) { + popupPos.y() -= actionListElemData.boundingBox.height; + } + } + + CLAY(localID, { + .layout = { + .sizing = {.width = CLAY_SIZING_FIT(100), .height = CLAY_SIZING_FIT(0)}, + .padding = CLAY_PADDING_ALL(io->theme->padding1), + .childGap = 1, + .childAlignment = { .x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_TOP}, + .layoutDirection = CLAY_TOP_TO_BOTTOM + }, + .backgroundColor = convert_vec4(io->theme->backColor1), + .cornerRadius = CLAY_CORNER_RADIUS(io->theme->windowCorners1), + .floating = { + .offset = {popupPos.x(), popupPos.y()}, + .zIndex = -1, + .attachTo = CLAY_ATTACH_TO_ROOT + } + }) { + obstructing_window(); + push_id(1); + elemUpdate(); + pop_id(); + } pop_id(); } - pop_id(); } void GUIManager::obstructing_window() { @@ -917,7 +903,7 @@ void GUIManager::obstructing_window() { } void GUIManager::clay_error_handler(Clay_ErrorData errorData) { - std::cout << "[Clay Error] " << errorData.errorText.chars << std::endl; + Logger::get().log("INFO", "[Clay Error] " + std::string(errorData.errorText.chars)); } void GUIManager::push_id(int64_t id) { diff --git a/src/GUIStuff/GUIManager.hpp b/src/GUIStuff/GUIManager.hpp index 29159f1..703c70c 100644 --- a/src/GUIStuff/GUIManager.hpp +++ b/src/GUIStuff/GUIManager.hpp @@ -265,7 +265,7 @@ class GUIManager { template bool big_color_button(const std::string& id, T* val, bool isSelected = false, const std::function& elemUpdate = nullptr) { bool toRet = false; - CLAY({.layout = {.sizing = {.width = CLAY_SIZING_FIXED(GUIStuff::GUIManager::BIG_BUTTON_SIZE), .height = CLAY_SIZING_FIXED(GUIStuff::GUIManager::BIG_BUTTON_SIZE)}}}) { + CLAY_AUTO_ID({.layout = {.sizing = {.width = CLAY_SIZING_FIXED(GUIStuff::GUIManager::BIG_BUTTON_SIZE), .height = CLAY_SIZING_FIXED(GUIStuff::GUIManager::BIG_BUTTON_SIZE)}}}) { toRet = color_button(id, val, isSelected, elemUpdate); } return toRet; @@ -273,7 +273,7 @@ class GUIManager { template bool color_button(const std::string& id, T* val, bool isSelected = false, const std::function& elemUpdate = nullptr) { return selectable_button(id, [&](SelectionHelper& s, bool iS) { - CLAY({.layout = { + CLAY_AUTO_ID({.layout = { .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)}, }, .backgroundColor = convert_vec4(*val), @@ -286,9 +286,9 @@ class GUIManager { template bool color_button_big(const std::string& id, T* val, bool isSelected = false, const std::function& elemUpdate = nullptr) { bool toRet = false; - CLAY({.layout = {.sizing = {.width = CLAY_SIZING_FIXED(BIG_BUTTON_SIZE), .height = CLAY_SIZING_FIXED(BIG_BUTTON_SIZE)}}}) { + CLAY_AUTO_ID({.layout = {.sizing = {.width = CLAY_SIZING_FIXED(BIG_BUTTON_SIZE), .height = CLAY_SIZING_FIXED(BIG_BUTTON_SIZE)}}}) { toRet = selectable_button(id, [&](SelectionHelper& s, bool iS) { - CLAY({.layout = { + CLAY_AUTO_ID({.layout = { .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)}, }, .backgroundColor = convert_vec4(*val), @@ -306,7 +306,7 @@ class GUIManager { push_id(id); bool& isOpen = insert_any_with_id(0, false); bool clicked; - CLAY ({.layout = {.sizing = {.width = CLAY_SIZING_FIXED(BIG_BUTTON_SIZE), .height = CLAY_SIZING_FIXED(BIG_BUTTON_SIZE) } } }) { + CLAY_AUTO_ID({.layout = {.sizing = {.width = CLAY_SIZING_FIXED(BIG_BUTTON_SIZE), .height = CLAY_SIZING_FIXED(BIG_BUTTON_SIZE) } } }) { clicked = color_button("0", val, isOpen, elemUpdate); } if(clicked) @@ -330,7 +330,7 @@ class GUIManager { if(fixedPickerWidth == 0.0f) isUpdating |= color_picker("c", val, selectAlpha); else { - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_FIXED(fixedPickerWidth), .height = CLAY_SIZING_FIXED(fixedPickerWidth)} } @@ -368,9 +368,6 @@ class GUIManager { } private: - std::string get_clay_unique_id(); - uint64_t clayUniqueIDCounter = 0; - static void clay_error_handler(Clay_ErrorData errorData); static Clay_Dimensions clay_skia_measure_text(Clay_StringSlice str, Clay_TextElementConfig* config, void* userData); diff --git a/src/Toolbar.cpp b/src/Toolbar.cpp index aa17a9e..d4da402 100644 --- a/src/Toolbar.cpp +++ b/src/Toolbar.cpp @@ -360,7 +360,7 @@ void Toolbar::update() { start_gui(); if(main.drawGui) { - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_FIT(gui.windowSize.x()), .height = CLAY_SIZING_FIT(gui.windowSize.y())}, .padding = CLAY_PADDING_ALL(io->theme->padding1), @@ -445,7 +445,7 @@ void Toolbar::paint_popup(Vector2f popupPos) { } void Toolbar::top_toolbar() { - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIT(0) }, .padding = CLAY_PADDING_ALL(static_cast(io->theme->padding1 / 2)), @@ -502,7 +502,7 @@ void Toolbar::top_toolbar() { if(bookMenu.popupOpen) bookmark_menu(bookmarkMenuPopUpJustOpen); if(menuPopUpOpen) { - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_FIT(100), .height = CLAY_SIZING_FIT(0) }, .padding = CLAY_PADDING_ALL(io->theme->padding1), @@ -586,7 +586,7 @@ void Toolbar::top_toolbar() { } void Toolbar::web_version_welcome() { - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_FIXED(700), .height = CLAY_SIZING_FIT(0) }, .padding = CLAY_PADDING_ALL(io->theme->padding1), @@ -661,7 +661,7 @@ void Toolbar::update_notification_check() { } void Toolbar::update_notification_gui() { - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_FIXED(700), .height = CLAY_SIZING_FIT(0) }, .padding = CLAY_PADDING_ALL(io->theme->padding1), @@ -693,7 +693,7 @@ void Toolbar::update_notification_gui() { void Toolbar::grid_menu(bool justOpened) { gui.push_id("grid menu"); - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_FIT(300), .height = CLAY_SIZING_FIT(0, 600) }, .padding = CLAY_PADDING_ALL(io->theme->padding1), @@ -715,7 +715,7 @@ void Toolbar::grid_menu(bool justOpened) { ServerClientID gridID = main.world->gridMan.sorted_grid_ids()[i]; WorldGrid& grid = main.world->gridMan.grids[gridID]; bool selectedEntry = gridID == gridMenu.gridSelected; - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIXED(entryHeight)}, .childGap = 2, @@ -726,7 +726,7 @@ void Toolbar::grid_menu(bool justOpened) { }) { gui.text_label(grid.get_display_name()); bool miniButtonClicked = false; - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)}, .childGap = 1, @@ -787,7 +787,7 @@ void Toolbar::stop_displaying_grid_menu() { void Toolbar::bookmark_menu(bool justOpened) { gui.push_id("bookmark menu"); - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_FIT(300), .height = CLAY_SIZING_FIT(0, 600) }, .padding = CLAY_PADDING_ALL(io->theme->padding1), @@ -808,7 +808,7 @@ void Toolbar::bookmark_menu(bool justOpened) { gui.scroll_bar_many_entries_area("bookmark menu entries", entryHeight, main.world->bMan.sorted_names().size(), true, [&](size_t i, bool isListHovered) { const std::string& bookmark = main.world->bMan.sorted_names()[i]; bool selectedEntry = bookmark == bookMenu.newName; - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIXED(entryHeight)}, .childGap = 2, @@ -819,7 +819,7 @@ void Toolbar::bookmark_menu(bool justOpened) { }) { gui.text_label(bookmark); bool miniButtonClicked = false; - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)}, .childGap = 1, @@ -894,7 +894,7 @@ std::unique_ptr Toolbar::build_paragraph_from_chat_ void Toolbar::chat_box() { constexpr float CHATBOX_WIDTH = 700; if(main.world->network_being_used()) { - CLAY({ + CLAY_AUTO_ID({ .layout = { .layoutDirection = CLAY_LEFT_TO_RIGHT }, @@ -911,7 +911,7 @@ void Toolbar::chat_box() { gui.pop_id(); } } - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_FIXED(CHATBOX_WIDTH), .height = CLAY_SIZING_FIT(0) }, .childGap = 0, @@ -924,7 +924,7 @@ void Toolbar::chat_box() { gui.push_id("chat box"); if(chatBoxState == CHATBOXSTATE_JUSTOPEN || chatBoxState == CHATBOXSTATE_OPEN) { gui.push_id("messages"); - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIT(0) }, .padding = CLAY_PADDING_ALL(0), @@ -979,7 +979,7 @@ void Toolbar::chat_box() { chatMessage.time.update_time_since(); if(chatMessage.time < DISPLAY_TIME) { float a = 1.0f - lerp_time(chatMessage.time, DISPLAY_TIME, FADE_START_TIME); - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIT(0) }, .padding = CLAY_PADDING_ALL(0), @@ -1004,7 +1004,7 @@ void Toolbar::chat_box() { } void Toolbar::global_log() { - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_FIXED(300), .height = CLAY_SIZING_FIT(0) }, .childGap = io->theme->childGap1, @@ -1019,7 +1019,7 @@ void Toolbar::global_log() { logM.time.update_time_since(); if(logM.time < DISPLAY_TIME) { float a = 1.0f - lerp_time(logM.time, DISPLAY_TIME, FADE_START_TIME); - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_FIT(300), .height = CLAY_SIZING_FIT(0) }, .padding = CLAY_PADDING_ALL(io->theme->padding1), @@ -1050,7 +1050,7 @@ void Toolbar::global_log() { } void Toolbar::drawing_program_gui() { - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0) }, .childGap = io->theme->childGap1, @@ -1061,12 +1061,12 @@ void Toolbar::drawing_program_gui() { main.world->drawProg.toolbar_gui(); isUpdatingColorLeft = isUpdatingColorRight = false; if(colorLeft) { - CLAY({ + CLAY_AUTO_ID({ .layout = { .padding = {.top = 40, .bottom = 40} } }) { - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_FIT(300), .height = CLAY_SIZING_FIT(0)}, .padding = CLAY_PADDING_ALL(io->theme->padding1), @@ -1086,18 +1086,18 @@ void Toolbar::drawing_program_gui() { } } } - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)} } }) {} if(colorRight) { - CLAY({ + CLAY_AUTO_ID({ .layout = { .padding = {.top = 40, .bottom = 40} } }) { - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_FIT(300), .height = CLAY_SIZING_FIT(0)}, .padding = CLAY_PADDING_ALL(io->theme->padding1), @@ -1128,7 +1128,7 @@ bool Toolbar::color_palette(const std::string& id, Vector4f* color, bool& hoveri constexpr float COLOR_BUTTON_SIZE = GUIStuff::GUIManager::BIG_BUTTON_SIZE; gui.scroll_bar_area("color palette scroll area", false, [&](float, float, float &) { - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)}, .childGap = io->theme->childGap1, @@ -1137,7 +1137,7 @@ bool Toolbar::color_palette(const std::string& id, Vector4f* color, bool& hoveri }) { size_t i = 0; while(i < palette.size()) { - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIXED(COLOR_BUTTON_SIZE)}, .childGap = io->theme->childGap1, @@ -1146,7 +1146,7 @@ bool Toolbar::color_palette(const std::string& id, Vector4f* color, bool& hoveri } }) { while(i < palette.size()) { - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_FIXED(COLOR_BUTTON_SIZE), .height = CLAY_SIZING_FIXED(COLOR_BUTTON_SIZE)} } @@ -1173,7 +1173,7 @@ bool Toolbar::color_palette(const std::string& id, Vector4f* color, bool& hoveri }); if(paletteData.selectedPalette != 0) { - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIT(0)}, .padding = {.top = 3, .bottom = 3}, @@ -1194,7 +1194,7 @@ bool Toolbar::color_palette(const std::string& id, Vector4f* color, bool& hoveri } } } - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIT(0)}, .padding = {.top = 3, .bottom = 3}, @@ -1232,7 +1232,7 @@ bool Toolbar::color_palette(const std::string& id, Vector4f* color, bool& hoveri } void Toolbar::performance_metrics() { - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_FIT(0), .height = CLAY_SIZING_FIT(0) }, .padding = CLAY_PADDING_ALL(io->theme->padding1), @@ -1260,7 +1260,7 @@ void Toolbar::performance_metrics() { } void Toolbar::player_list() { - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_FIT(500), .height = CLAY_SIZING_FIT(0) }, .padding = CLAY_PADDING_ALL(io->theme->padding1), @@ -1276,7 +1276,7 @@ void Toolbar::player_list() { gui.push_id("client list"); gui.text_label_centered("Player List"); gui.left_to_right_line_layout([&]() { - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_FIXED(20), .height = CLAY_SIZING_FIXED(20)} }, @@ -1289,7 +1289,7 @@ void Toolbar::player_list() { for(auto& [id, client] : main.world->clients) { gui.push_id(num++); gui.left_to_right_line_layout([&]() { - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_FIXED(20), .height = CLAY_SIZING_FIXED(20)} }, @@ -1297,7 +1297,7 @@ void Toolbar::player_list() { .cornerRadius = CLAY_CORNER_RADIUS(3) }) {} gui.text_label(client.displayName); - CLAY({.layout = {.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)}}}) {} + CLAY_AUTO_ID({.layout = {.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)}}}) {} if(gui.text_button("teleport button", "Jump To")) main.world->drawData.cam.smooth_move_to(*main.world, client.camCoords, client.windowSize); }); @@ -1349,7 +1349,7 @@ void Toolbar::options_menu() { switch(optionsMenuType) { case HOST_MENU: case CONNECT_MENU: { - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_FIT(650), .height = CLAY_SIZING_FIT(0) }, .padding = CLAY_PADDING_ALL(io->theme->padding1), @@ -1405,7 +1405,7 @@ void Toolbar::options_menu() { break; } case GENERAL_SETTINGS_MENU: { - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_FIXED(600), .height = CLAY_SIZING_FIXED(500) }, .childAlignment = { .x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_TOP}, @@ -1416,7 +1416,7 @@ void Toolbar::options_menu() { .floating = {.attachPoints = {.element = CLAY_ATTACH_POINT_CENTER_CENTER, .parent = CLAY_ATTACH_POINT_CENTER_CENTER}, .attachTo = CLAY_ATTACH_TO_PARENT} }) { gui.push_id("gsettings"); - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)}, .padding = CLAY_PADDING_ALL(io->theme->padding1), @@ -1426,7 +1426,7 @@ void Toolbar::options_menu() { } }) { gui.obstructing_window(); - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_FIT(150), .height = CLAY_SIZING_GROW(0) }, .padding = CLAY_PADDING_ALL(io->theme->padding1), @@ -1446,7 +1446,7 @@ void Toolbar::options_menu() { themeData.selectedThemeIndex = std::nullopt; } } - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0) }, .childAlignment = { .x = CLAY_ALIGN_X_LEFT, .y = CLAY_ALIGN_Y_TOP}, @@ -1454,7 +1454,7 @@ void Toolbar::options_menu() { } }) { gui.scroll_bar_area("general settings scroll area", false, [&](float, float, float) { - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0) }, .padding = CLAY_PADDING_ALL(io->theme->padding1), @@ -1514,7 +1514,7 @@ void Toolbar::options_menu() { if(!themeData.selectedThemeIndex) reload_theme_list(); - CLAY({.layout = { + CLAY_AUTO_ID({.layout = { .childGap = io->theme->childGap1, .childAlignment = {.x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_CENTER}, .layoutDirection = CLAY_LEFT_TO_RIGHT, @@ -1597,7 +1597,7 @@ void Toolbar::options_menu() { gui.push_id("keybind entries"); for(unsigned i = 0; i < InputManager::KEY_ASSIGNABLE_COUNT; i++) { gui.push_id(i); - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIT(0) }, .padding = CLAY_PADDING_ALL(0), @@ -1645,7 +1645,7 @@ void Toolbar::options_menu() { break; } case LOBBY_INFO_MENU: { - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_FIT(650), .height = CLAY_SIZING_FIT(0) }, .padding = CLAY_PADDING_ALL(io->theme->padding1), @@ -1677,7 +1677,7 @@ void Toolbar::options_menu() { break; } case CANVAS_SETTINGS_MENU: { - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_FIT(500), .height = CLAY_SIZING_FIT(0) }, .padding = CLAY_PADDING_ALL(io->theme->padding1), @@ -1701,7 +1701,7 @@ void Toolbar::options_menu() { break; } case SET_DOWNLOAD_NAME: { - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_FIT(500), .height = CLAY_SIZING_FIT(0) }, .padding = CLAY_PADDING_ALL(io->theme->padding1), @@ -1738,7 +1738,7 @@ void Toolbar::options_menu() { } void Toolbar::about_menu_gui() { - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_FIXED(700), .height = CLAY_SIZING_FIXED(600) }, .padding = CLAY_PADDING_ALL(io->theme->padding1), @@ -1754,7 +1754,7 @@ void Toolbar::about_menu_gui() { gui.obstructing_window(); gui.left_to_right_line_layout([&]() { gui.push_id("Menu Selector"); - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_FIT(200), .height = CLAY_SIZING_FIT(0) }, .padding = CLAY_PADDING_ALL(io->theme->padding1), @@ -1763,7 +1763,7 @@ void Toolbar::about_menu_gui() { } }) { gui.scroll_bar_area("About Menu Selector Scroll Area", true, [&](float, float, float) { - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIT(0)} } @@ -1772,7 +1772,7 @@ void Toolbar::about_menu_gui() { } gui.text_label_light_centered("Third Party Components"); for(int i = 0; i < static_cast(thirdPartyLicenses.size()); i++) { - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIT(0) }, .padding = CLAY_PADDING_ALL(1) @@ -1821,7 +1821,7 @@ void Toolbar::reload_theme_list() { void Toolbar::file_picker_gui() { gui.push_id("filepicker"); bool isDoneByDoubleClick = false; - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_FIXED(700), .height = CLAY_SIZING_FIXED(500) }, .padding = CLAY_PADDING_ALL(io->theme->padding1), @@ -1845,7 +1845,7 @@ void Toolbar::file_picker_gui() { if(pathDiff != filePicker.currentSearchPath) filePicker.refreshEntries = true; }); - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)}, .childAlignment = { .x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_TOP}, @@ -1905,7 +1905,7 @@ void Toolbar::file_picker_gui() { gui.scroll_bar_many_entries_area("file picker entries", entryHeight, filePicker.entries.size(), true, [&](size_t i, bool isListHovered) { const std::filesystem::path& entry = filePicker.entries[i]; bool selectedEntry = filePicker.currentSelectedPath == entry; - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIXED(entryHeight)}, .childGap = 1, @@ -1914,7 +1914,7 @@ void Toolbar::file_picker_gui() { }, .backgroundColor = selectedEntry ? convert_vec4(io->theme->backColor1) : convert_vec4(io->theme->backColor2) }) { - CLAY({ + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_FIXED(20), .height = CLAY_SIZING_FIXED(20)} },