mirror of
https://github.com/nicbarker/clay.git
synced 2025-09-18 04:26:18 +00:00
[Core] Fix incorrect percentage sizing of floating elements
This commit is contained in:
parent
8dfcc944fa
commit
d9d0b6c37b
24
clay.h
24
clay.h
|
@ -2232,17 +2232,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) {
|
||||
switch (rootElement->layoutConfig->sizing.width.type) {
|
||||
case CLAY__SIZING_TYPE_GROW: {
|
||||
rootElement->dimensions.width = parentLayoutElement->dimensions.width;
|
||||
break;
|
||||
}
|
||||
if (rootElement->layoutConfig->sizing.height.type == CLAY__SIZING_TYPE_GROW) {
|
||||
case CLAY__SIZING_TYPE_PERCENT: {
|
||||
rootElement->dimensions.width = parentLayoutElement->dimensions.width * rootElement->layoutConfig->sizing.width.size.percent;
|
||||
break;
|
||||
}
|
||||
default: break;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
|
|
@ -69,7 +69,7 @@ Clay_RenderCommandArray CreateLayout(void) {
|
|||
})
|
||||
{
|
||||
CLAY({ .id = CLAY_ID("FloatingContainer"),
|
||||
.layout = { .sizing = { .width = CLAY_SIZING_FIXED(300), .height = CLAY_SIZING_FIXED(300) }, .padding = { 16, 16, 16, 16 }},
|
||||
.layout = { .sizing = { .width = CLAY_SIZING_PERCENT(0.5), .height = CLAY_SIZING_FIXED(300) }, .padding = { 16, 16, 16, 16 }},
|
||||
.backgroundColor = { 140, 80, 200, 200 },
|
||||
.floating = { .attachTo = CLAY_ATTACH_TO_PARENT, .zIndex = 1, .attachPoints = { CLAY_ATTACH_POINT_CENTER_TOP, CLAY_ATTACH_POINT_CENTER_TOP }, .offset = {0, 0} },
|
||||
.border = { .width = CLAY_BORDER_OUTSIDE(2), .color = {80, 80, 80, 255} },
|
||||
|
@ -108,8 +108,8 @@ Clay_RenderCommandArray CreateLayout(void) {
|
|||
|
||||
CLAY({ .id = CLAY_ID("Blob4Floating2"), .floating = { .attachTo = CLAY_ATTACH_TO_ELEMENT_WITH_ID, .zIndex = 1, .parentId = Clay_GetElementId(CLAY_STRING("SidebarBlob4")).id } }) {
|
||||
CLAY({ .id = CLAY_ID("ScrollContainer"), .layout = { .sizing = { .height = CLAY_SIZING_FIXED(200) }, .childGap = 2 }, .clip = { .vertical = true, .childOffset = Clay_GetScrollOffset() } }) {
|
||||
CLAY({ .id = CLAY_ID("FloatingContainer2"), .floating = { .attachTo = CLAY_ATTACH_TO_PARENT, .zIndex = 1 } }) {
|
||||
CLAY({ .id = CLAY_ID("FloatingContainerInner"), .layout = { .sizing = { .width = CLAY_SIZING_FIXED(300), .height = CLAY_SIZING_FIXED(300) }, .padding = {16, 16, 16, 16} }, .backgroundColor = {140,80, 200, 200} }) {
|
||||
CLAY({ .id = CLAY_ID("FloatingContainer2"), .layout.sizing.height = CLAY_SIZING_GROW(), .floating = { .attachTo = CLAY_ATTACH_TO_PARENT, .zIndex = 1 } }) {
|
||||
CLAY({ .id = CLAY_ID("FloatingContainerInner"), .layout = { .sizing = { .width = CLAY_SIZING_FIXED(300), .height = CLAY_SIZING_GROW() }, .padding = {16, 16, 16, 16} }, .backgroundColor = {140,80, 200, 200} }) {
|
||||
CLAY_TEXT(CLAY_STRING("I'm an inline floating container."), CLAY_TEXT_CONFIG({ .fontSize = 24, .textColor = {255,255,255,255} }));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue