mirror of
				https://github.com/nicbarker/clay.git
				synced 2025-11-04 00:26:17 +00:00 
			
		
		
		
	Support passing declaration by pointer as well
This commit is contained in:
		
							parent
							
								
									22e8cc318c
								
							
						
					
					
						commit
						33b8e76903
					
				
							
								
								
									
										55
									
								
								clay.h
									
									
									
									
									
								
							
							
						
						
									
										55
									
								
								clay.h
									
									
									
									
									
								
							| 
						 | 
					@ -880,6 +880,7 @@ CLAY_DLL_EXPORT void Clay_ResetMeasureTextCache(void);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
CLAY_DLL_EXPORT void Clay__OpenElement(void);
 | 
					CLAY_DLL_EXPORT void Clay__OpenElement(void);
 | 
				
			||||||
CLAY_DLL_EXPORT void Clay__ConfigureOpenElement(const Clay_ElementDeclaration config);
 | 
					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 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 offset, uint32_t seed);
 | 
				
			||||||
CLAY_DLL_EXPORT void Clay__OpenTextElement(Clay_String text, Clay_TextElementConfig *textConfig);
 | 
					CLAY_DLL_EXPORT void Clay__OpenTextElement(Clay_String text, Clay_TextElementConfig *textConfig);
 | 
				
			||||||
| 
						 | 
					@ -1865,58 +1866,58 @@ Clay_ElementId Clay__AttachId(Clay_ElementId elementId) {
 | 
				
			||||||
    return elementId;
 | 
					    return elementId;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Clay__ConfigureOpenElement(const Clay_ElementDeclaration declaration) {
 | 
					void Clay__ConfigureOpenElementPtr(const Clay_ElementDeclaration *declaration) {
 | 
				
			||||||
    Clay_Context* context = Clay_GetCurrentContext();
 | 
					    Clay_Context* context = Clay_GetCurrentContext();
 | 
				
			||||||
    Clay_LayoutElement *openLayoutElement = Clay__GetOpenLayoutElement();
 | 
					    Clay_LayoutElement *openLayoutElement = Clay__GetOpenLayoutElement();
 | 
				
			||||||
    openLayoutElement->layoutConfig = Clay__StoreLayoutConfig(declaration.layout);
 | 
					    openLayoutElement->layoutConfig = Clay__StoreLayoutConfig(declaration->layout);
 | 
				
			||||||
    if ((declaration.layout.sizing.width.type == CLAY__SIZING_TYPE_PERCENT && declaration.layout.sizing.width.size.percent > 1) || (declaration.layout.sizing.height.type == CLAY__SIZING_TYPE_PERCENT && declaration.layout.sizing.height.size.percent > 1)) {
 | 
					    if ((declaration->layout.sizing.width.type == CLAY__SIZING_TYPE_PERCENT && declaration->layout.sizing.width.size.percent > 1) || (declaration->layout.sizing.height.type == CLAY__SIZING_TYPE_PERCENT && declaration->layout.sizing.height.size.percent > 1)) {
 | 
				
			||||||
        context->errorHandler.errorHandlerFunction(CLAY__INIT(Clay_ErrorData) {
 | 
					        context->errorHandler.errorHandlerFunction(CLAY__INIT(Clay_ErrorData) {
 | 
				
			||||||
                .errorType = CLAY_ERROR_TYPE_PERCENTAGE_OVER_1,
 | 
					                .errorType = CLAY_ERROR_TYPE_PERCENTAGE_OVER_1,
 | 
				
			||||||
                .errorText = CLAY_STRING("An element was configured with CLAY_SIZING_PERCENT, but the provided percentage value was over 1.0. Clay expects a value between 0 and 1, i.e. 20% is 0.2."),
 | 
					                .errorText = CLAY_STRING("An element was configured with CLAY_SIZING_PERCENT, but the provided percentage value was over 1.0. Clay expects a value between 0 and 1, i.e. 20% is 0.2."),
 | 
				
			||||||
                .userData = context->errorHandler.userData });
 | 
					                .userData = context->errorHandler.userData });
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    Clay_ElementId openLayoutElementId = declaration.id;
 | 
					    Clay_ElementId openLayoutElementId = declaration->id;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    openLayoutElement->elementConfigs.internalArray = &context->elementConfigs.internalArray[context->elementConfigs.length];
 | 
					    openLayoutElement->elementConfigs.internalArray = &context->elementConfigs.internalArray[context->elementConfigs.length];
 | 
				
			||||||
    Clay_SharedElementConfig *sharedConfig = NULL;
 | 
					    Clay_SharedElementConfig *sharedConfig = NULL;
 | 
				
			||||||
    if (declaration.backgroundColor.a > 0) {
 | 
					    if (declaration->backgroundColor.a > 0) {
 | 
				
			||||||
        sharedConfig = Clay__StoreSharedElementConfig(CLAY__INIT(Clay_SharedElementConfig) { .backgroundColor = declaration.backgroundColor });
 | 
					        sharedConfig = Clay__StoreSharedElementConfig(CLAY__INIT(Clay_SharedElementConfig) { .backgroundColor = declaration->backgroundColor });
 | 
				
			||||||
        Clay__AttachElementConfig(CLAY__INIT(Clay_ElementConfigUnion) { .sharedElementConfig = sharedConfig }, CLAY__ELEMENT_CONFIG_TYPE_SHARED);
 | 
					        Clay__AttachElementConfig(CLAY__INIT(Clay_ElementConfigUnion) { .sharedElementConfig = sharedConfig }, CLAY__ELEMENT_CONFIG_TYPE_SHARED);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (!Clay__MemCmp((char *)(&declaration.cornerRadius), (char *)(&Clay__CornerRadius_DEFAULT), sizeof(Clay_CornerRadius))) {
 | 
					    if (!Clay__MemCmp((char *)(&declaration->cornerRadius), (char *)(&Clay__CornerRadius_DEFAULT), sizeof(Clay_CornerRadius))) {
 | 
				
			||||||
        if (sharedConfig) {
 | 
					        if (sharedConfig) {
 | 
				
			||||||
            sharedConfig->cornerRadius = declaration.cornerRadius;
 | 
					            sharedConfig->cornerRadius = declaration->cornerRadius;
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            sharedConfig = Clay__StoreSharedElementConfig(CLAY__INIT(Clay_SharedElementConfig) { .cornerRadius = declaration.cornerRadius });
 | 
					            sharedConfig = Clay__StoreSharedElementConfig(CLAY__INIT(Clay_SharedElementConfig) { .cornerRadius = declaration->cornerRadius });
 | 
				
			||||||
            Clay__AttachElementConfig(CLAY__INIT(Clay_ElementConfigUnion) { .sharedElementConfig = sharedConfig }, CLAY__ELEMENT_CONFIG_TYPE_SHARED);
 | 
					            Clay__AttachElementConfig(CLAY__INIT(Clay_ElementConfigUnion) { .sharedElementConfig = sharedConfig }, CLAY__ELEMENT_CONFIG_TYPE_SHARED);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (declaration.userData != 0) {
 | 
					    if (declaration->userData != 0) {
 | 
				
			||||||
        if (sharedConfig) {
 | 
					        if (sharedConfig) {
 | 
				
			||||||
            sharedConfig->userData = declaration.userData;
 | 
					            sharedConfig->userData = declaration->userData;
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            sharedConfig = Clay__StoreSharedElementConfig(CLAY__INIT(Clay_SharedElementConfig) { .userData = declaration.userData });
 | 
					            sharedConfig = Clay__StoreSharedElementConfig(CLAY__INIT(Clay_SharedElementConfig) { .userData = declaration->userData });
 | 
				
			||||||
            Clay__AttachElementConfig(CLAY__INIT(Clay_ElementConfigUnion) { .sharedElementConfig = sharedConfig }, CLAY__ELEMENT_CONFIG_TYPE_SHARED);
 | 
					            Clay__AttachElementConfig(CLAY__INIT(Clay_ElementConfigUnion) { .sharedElementConfig = sharedConfig }, CLAY__ELEMENT_CONFIG_TYPE_SHARED);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (declaration.image.imageData) {
 | 
					    if (declaration->image.imageData) {
 | 
				
			||||||
        Clay__AttachElementConfig(CLAY__INIT(Clay_ElementConfigUnion) { .imageElementConfig = Clay__StoreImageElementConfig(declaration.image) }, CLAY__ELEMENT_CONFIG_TYPE_IMAGE);
 | 
					        Clay__AttachElementConfig(CLAY__INIT(Clay_ElementConfigUnion) { .imageElementConfig = Clay__StoreImageElementConfig(declaration->image) }, CLAY__ELEMENT_CONFIG_TYPE_IMAGE);
 | 
				
			||||||
        Clay__int32_tArray_Add(&context->imageElementPointers, context->layoutElements.length - 1);
 | 
					        Clay__int32_tArray_Add(&context->imageElementPointers, context->layoutElements.length - 1);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (declaration.floating.attachTo != CLAY_ATTACH_TO_NONE) {
 | 
					    if (declaration->floating.attachTo != CLAY_ATTACH_TO_NONE) {
 | 
				
			||||||
        Clay_FloatingElementConfig floatingConfig = declaration.floating;
 | 
					        Clay_FloatingElementConfig floatingConfig = declaration->floating;
 | 
				
			||||||
        // This looks dodgy but because of the auto generated root element the depth of the tree will always be at least 2 here
 | 
					        // This looks dodgy but because of the auto generated root element the depth of the tree will always be at least 2 here
 | 
				
			||||||
        Clay_LayoutElement *hierarchicalParent = Clay_LayoutElementArray_Get(&context->layoutElements, Clay__int32_tArray_GetValue(&context->openLayoutElementStack, context->openLayoutElementStack.length - 2));
 | 
					        Clay_LayoutElement *hierarchicalParent = Clay_LayoutElementArray_Get(&context->layoutElements, Clay__int32_tArray_GetValue(&context->openLayoutElementStack, context->openLayoutElementStack.length - 2));
 | 
				
			||||||
        if (hierarchicalParent) {
 | 
					        if (hierarchicalParent) {
 | 
				
			||||||
            uint32_t clipElementId = 0;
 | 
					            uint32_t clipElementId = 0;
 | 
				
			||||||
            if (declaration.floating.attachTo == CLAY_ATTACH_TO_PARENT) {
 | 
					            if (declaration->floating.attachTo == CLAY_ATTACH_TO_PARENT) {
 | 
				
			||||||
                // Attach to the element's direct hierarchical parent
 | 
					                // Attach to the element's direct hierarchical parent
 | 
				
			||||||
                floatingConfig.parentId = hierarchicalParent->id;
 | 
					                floatingConfig.parentId = hierarchicalParent->id;
 | 
				
			||||||
                if (context->openClipElementStack.length > 0) {
 | 
					                if (context->openClipElementStack.length > 0) {
 | 
				
			||||||
                    clipElementId = Clay__int32_tArray_GetValue(&context->openClipElementStack, (int)context->openClipElementStack.length - 1);
 | 
					                    clipElementId = Clay__int32_tArray_GetValue(&context->openClipElementStack, (int)context->openClipElementStack.length - 1);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            } else if (declaration.floating.attachTo == CLAY_ATTACH_TO_ELEMENT_WITH_ID) {
 | 
					            } else if (declaration->floating.attachTo == CLAY_ATTACH_TO_ELEMENT_WITH_ID) {
 | 
				
			||||||
                Clay_LayoutElementHashMapItem *parentItem = Clay__GetHashMapItem(floatingConfig.parentId);
 | 
					                Clay_LayoutElementHashMapItem *parentItem = Clay__GetHashMapItem(floatingConfig.parentId);
 | 
				
			||||||
                if (!parentItem) {
 | 
					                if (!parentItem) {
 | 
				
			||||||
                    context->errorHandler.errorHandlerFunction(CLAY__INIT(Clay_ErrorData) {
 | 
					                    context->errorHandler.errorHandlerFunction(CLAY__INIT(Clay_ErrorData) {
 | 
				
			||||||
| 
						 | 
					@ -1926,7 +1927,7 @@ void Clay__ConfigureOpenElement(const Clay_ElementDeclaration declaration) {
 | 
				
			||||||
                } else {
 | 
					                } else {
 | 
				
			||||||
                    clipElementId = Clay__int32_tArray_GetValue(&context->layoutElementClipElementIds, parentItem->layoutElement - context->layoutElements.internalArray);
 | 
					                    clipElementId = Clay__int32_tArray_GetValue(&context->layoutElementClipElementIds, parentItem->layoutElement - context->layoutElements.internalArray);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            } else if (declaration.floating.attachTo == CLAY_ATTACH_TO_ROOT) {
 | 
					            } else if (declaration->floating.attachTo == CLAY_ATTACH_TO_ROOT) {
 | 
				
			||||||
                floatingConfig.parentId = Clay__HashString(CLAY_STRING("Clay__RootContainer"), 0, 0).id;
 | 
					                floatingConfig.parentId = Clay__HashString(CLAY_STRING("Clay__RootContainer"), 0, 0).id;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            if (!openLayoutElementId.id) {
 | 
					            if (!openLayoutElementId.id) {
 | 
				
			||||||
| 
						 | 
					@ -1941,8 +1942,8 @@ void Clay__ConfigureOpenElement(const Clay_ElementDeclaration declaration) {
 | 
				
			||||||
            Clay__AttachElementConfig(CLAY__INIT(Clay_ElementConfigUnion) { .floatingElementConfig = Clay__StoreFloatingElementConfig(floatingConfig) }, CLAY__ELEMENT_CONFIG_TYPE_FLOATING);
 | 
					            Clay__AttachElementConfig(CLAY__INIT(Clay_ElementConfigUnion) { .floatingElementConfig = Clay__StoreFloatingElementConfig(floatingConfig) }, CLAY__ELEMENT_CONFIG_TYPE_FLOATING);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (declaration.custom.customData) {
 | 
					    if (declaration->custom.customData) {
 | 
				
			||||||
        Clay__AttachElementConfig(CLAY__INIT(Clay_ElementConfigUnion) { .customElementConfig = Clay__StoreCustomElementConfig(declaration.custom) }, CLAY__ELEMENT_CONFIG_TYPE_CUSTOM);
 | 
					        Clay__AttachElementConfig(CLAY__INIT(Clay_ElementConfigUnion) { .customElementConfig = Clay__StoreCustomElementConfig(declaration->custom) }, CLAY__ELEMENT_CONFIG_TYPE_CUSTOM);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (openLayoutElementId.id != 0) {
 | 
					    if (openLayoutElementId.id != 0) {
 | 
				
			||||||
| 
						 | 
					@ -1951,8 +1952,8 @@ void Clay__ConfigureOpenElement(const Clay_ElementDeclaration declaration) {
 | 
				
			||||||
        openLayoutElementId = Clay__GenerateIdForAnonymousElement(openLayoutElement);
 | 
					        openLayoutElementId = Clay__GenerateIdForAnonymousElement(openLayoutElement);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (declaration.scroll.horizontal | declaration.scroll.vertical) {
 | 
					    if (declaration->scroll.horizontal | declaration->scroll.vertical) {
 | 
				
			||||||
        Clay__AttachElementConfig(CLAY__INIT(Clay_ElementConfigUnion) { .scrollElementConfig = Clay__StoreScrollElementConfig(declaration.scroll) }, CLAY__ELEMENT_CONFIG_TYPE_SCROLL);
 | 
					        Clay__AttachElementConfig(CLAY__INIT(Clay_ElementConfigUnion) { .scrollElementConfig = Clay__StoreScrollElementConfig(declaration->scroll) }, CLAY__ELEMENT_CONFIG_TYPE_SCROLL);
 | 
				
			||||||
        Clay__int32_tArray_Add(&context->openClipElementStack, (int)openLayoutElement->id);
 | 
					        Clay__int32_tArray_Add(&context->openClipElementStack, (int)openLayoutElement->id);
 | 
				
			||||||
        // Retrieve or create cached data to track scroll position across frames
 | 
					        // Retrieve or create cached data to track scroll position across frames
 | 
				
			||||||
        Clay__ScrollContainerDataInternal *scrollOffset = CLAY__NULL;
 | 
					        Clay__ScrollContainerDataInternal *scrollOffset = CLAY__NULL;
 | 
				
			||||||
| 
						 | 
					@ -1971,11 +1972,15 @@ void Clay__ConfigureOpenElement(const Clay_ElementDeclaration declaration) {
 | 
				
			||||||
            scrollOffset->scrollPosition = Clay__QueryScrollOffset(scrollOffset->elementId, context->queryScrollOffsetUserData);
 | 
					            scrollOffset->scrollPosition = Clay__QueryScrollOffset(scrollOffset->elementId, context->queryScrollOffsetUserData);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (!Clay__MemCmp((char *)(&declaration.border.width), (char *)(&Clay__BorderWidth_DEFAULT), sizeof(Clay_BorderWidth))) {
 | 
					    if (!Clay__MemCmp((char *)(&declaration->border.width), (char *)(&Clay__BorderWidth_DEFAULT), sizeof(Clay_BorderWidth))) {
 | 
				
			||||||
        Clay__AttachElementConfig(CLAY__INIT(Clay_ElementConfigUnion) { .borderElementConfig = Clay__StoreBorderElementConfig(declaration.border) }, CLAY__ELEMENT_CONFIG_TYPE_BORDER);
 | 
					        Clay__AttachElementConfig(CLAY__INIT(Clay_ElementConfigUnion) { .borderElementConfig = Clay__StoreBorderElementConfig(declaration->border) }, CLAY__ELEMENT_CONFIG_TYPE_BORDER);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void Clay__ConfigureOpenElement(const Clay_ElementDeclaration declaration) {
 | 
				
			||||||
 | 
					    Clay__ConfigureOpenElementPtr(&declaration);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Clay__InitializeEphemeralMemory(Clay_Context* context) {
 | 
					void Clay__InitializeEphemeralMemory(Clay_Context* context) {
 | 
				
			||||||
    int32_t maxElementCount = context->maxElementCount;
 | 
					    int32_t maxElementCount = context->maxElementCount;
 | 
				
			||||||
    // Ephemeral Memory - reset every frame
 | 
					    // Ephemeral Memory - reset every frame
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue