MCPcopy Create free account
hub / github.com/ErrorAtLine0/infinipaint / Clay__CloseElement

Function Clay__CloseElement

include/clay.h:1867–1974  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1865}
1866
1867void Clay__CloseElement(void) {
1868 Clay_Context* context = Clay_GetCurrentContext();
1869 if (context->booleanWarnings.maxElementsExceeded) {
1870 return;
1871 }
1872 Clay_LayoutElement *openLayoutElement = Clay__GetOpenLayoutElement();
1873 Clay_LayoutConfig *layoutConfig = &openLayoutElement->config.layout;
1874 bool elementHasClipHorizontal = openLayoutElement->config.clip.horizontal;
1875 bool elementHasClipVertical = openLayoutElement->config.clip.vertical;
1876 if (elementHasClipHorizontal || elementHasClipVertical || openLayoutElement->config.floating.attachTo != CLAY_ATTACH_TO_NONE) {
1877 context->openClipElementStack.length--;
1878 }
1879
1880 float leftRightPadding = (float)(layoutConfig->padding.left + layoutConfig->padding.right);
1881 float topBottomPadding = (float)(layoutConfig->padding.top + layoutConfig->padding.bottom);
1882
1883 // Attach children to the current open element
1884 openLayoutElement->children.elements = &context->layoutElementChildren.internalArray[context->layoutElementChildren.length];
1885 if (layoutConfig->layoutDirection == CLAY_LEFT_TO_RIGHT) {
1886 openLayoutElement->dimensions.width = leftRightPadding;
1887 openLayoutElement->minDimensions.width = leftRightPadding;
1888 for (int32_t i = 0; i < openLayoutElement->children.length; i++) {
1889 int32_t childIndex = Clay__int32_tArray_GetValue(&context->layoutElementChildrenBuffer, (int)context->layoutElementChildrenBuffer.length - openLayoutElement->children.length + i);
1890 Clay_LayoutElement *child = Clay_LayoutElementArray_Get(&context->layoutElements, childIndex);
1891 openLayoutElement->dimensions.width += child->dimensions.width;
1892 openLayoutElement->dimensions.height = CLAY__MAX(openLayoutElement->dimensions.height, child->dimensions.height + topBottomPadding);
1893 // Minimum size of child elements doesn't matter to clip containers as they can shrink and hide their contents
1894 if (!elementHasClipHorizontal) {
1895 openLayoutElement->minDimensions.width += child->minDimensions.width;
1896 }
1897 if (!elementHasClipVertical) {
1898 openLayoutElement->minDimensions.height = CLAY__MAX(openLayoutElement->minDimensions.height, child->minDimensions.height + topBottomPadding);
1899 }
1900 Clay__int32_tArray_Add(&context->layoutElementChildren, childIndex);
1901 }
1902 float childGap = (float)(CLAY__MAX(openLayoutElement->children.length - 1, 0) * layoutConfig->childGap);
1903 openLayoutElement->dimensions.width += childGap;
1904 if (!elementHasClipHorizontal) {
1905 openLayoutElement->minDimensions.width += childGap;
1906 }
1907 }
1908 else if (layoutConfig->layoutDirection == CLAY_TOP_TO_BOTTOM) {
1909 openLayoutElement->dimensions.height = topBottomPadding;
1910 openLayoutElement->minDimensions.height = topBottomPadding;
1911 for (int32_t i = 0; i < openLayoutElement->children.length; i++) {
1912 int32_t childIndex = Clay__int32_tArray_GetValue(&context->layoutElementChildrenBuffer, (int)context->layoutElementChildrenBuffer.length - openLayoutElement->children.length + i);
1913 Clay_LayoutElement *child = Clay_LayoutElementArray_Get(&context->layoutElements, childIndex);
1914 openLayoutElement->dimensions.height += child->dimensions.height;
1915 openLayoutElement->dimensions.width = CLAY__MAX(openLayoutElement->dimensions.width, child->dimensions.width + leftRightPadding);
1916 // Minimum size of child elements doesn't matter to clip containers as they can shrink and hide their contents
1917 if (!elementHasClipVertical) {
1918 openLayoutElement->minDimensions.height += child->minDimensions.height;
1919 }
1920 if (!elementHasClipHorizontal) {
1921 openLayoutElement->minDimensions.width = CLAY__MAX(openLayoutElement->minDimensions.width, child->minDimensions.width + leftRightPadding);
1922 }
1923 Clay__int32_tArray_Add(&context->layoutElementChildren, childIndex);
1924 }

Callers 2

Clay_EndLayoutFunction · 0.85

Calls 3

Clay_GetCurrentContextFunction · 0.85

Tested by

no test coverage detected