@@ -1299,6 +1299,12 @@ void UISystem::update(double dt){
12991299 container.maxHeight = 0 ;
13001300 int totalWidth = 0 ;
13011301 int totalHeight = 0 ;
1302+ // Content-min totals exclude children whose size is derived from parent via anchors
1303+ // to avoid a circular dependency that prevents the container from shrinking
1304+ int contentMinTotalWidth = 0 ;
1305+ int contentMinTotalHeight = 0 ;
1306+ unsigned int contentMinMaxWidth = 0 ;
1307+ unsigned int contentMinMaxHeight = 0 ;
13021308 for (int b = 0 ; b < container.numBoxes ; b++){
13031309 if (container.boxes [b].layout != NULL_ENTITY ){
13041310 if (!container.boxes [b].expand ){
@@ -1311,6 +1317,22 @@ void UISystem::update(double dt){
13111317 totalHeight += container.boxes [b].rect .getHeight ();
13121318 container.maxHeight = std::max (container.maxHeight , (unsigned int )container.boxes [b].rect .getHeight ());
13131319 container.maxWidth = std::max (container.maxWidth , (unsigned int )container.boxes [b].rect .getWidth ());
1320+
1321+ // Check if child size is anchor-derived from parent in each dimension
1322+ UILayoutComponent* childLayout = scene->findComponent <UILayoutComponent>(container.boxes [b].layout );
1323+ bool widthFromParent = childLayout && childLayout->usingAnchors &&
1324+ (childLayout->anchorPointLeft != childLayout->anchorPointRight );
1325+ bool heightFromParent = childLayout && childLayout->usingAnchors &&
1326+ (childLayout->anchorPointTop != childLayout->anchorPointBottom );
1327+
1328+ if (!widthFromParent){
1329+ contentMinTotalWidth += container.boxes [b].rect .getWidth ();
1330+ contentMinMaxWidth = std::max (contentMinMaxWidth, (unsigned int )container.boxes [b].rect .getWidth ());
1331+ }
1332+ if (!heightFromParent){
1333+ contentMinTotalHeight += container.boxes [b].rect .getHeight ();
1334+ contentMinMaxHeight = std::max (contentMinMaxHeight, (unsigned int )container.boxes [b].rect .getHeight ());
1335+ }
13141336 }
13151337 if (container.boxes [b].expand ){
13161338 container.numBoxExpand ++;
@@ -1319,11 +1341,11 @@ void UISystem::update(double dt){
13191341
13201342
13211343 if (container.type == ContainerType::HORIZONTAL ){
1322- layout.width = (layout.width > totalWidth )? layout.width : totalWidth ;
1323- layout.height = (layout.height > container. maxHeight )? layout.height : container. maxHeight ;
1344+ layout.width = (layout.width > contentMinTotalWidth )? layout.width : contentMinTotalWidth ;
1345+ layout.height = (layout.height > contentMinMaxHeight )? layout.height : contentMinMaxHeight ;
13241346 }else if (container.type == ContainerType::VERTICAL ){
1325- layout.width = (layout.width > container. maxWidth )? layout.width : container. maxWidth ;
1326- layout.height = (layout.height > totalHeight )? layout.height : totalHeight ;
1347+ layout.width = (layout.width > contentMinMaxWidth )? layout.width : contentMinMaxWidth ;
1348+ layout.height = (layout.height > contentMinTotalHeight )? layout.height : contentMinTotalHeight ;
13271349 }else if (container.type == ContainerType::HORIZONTAL_WRAP ){
13281350 if (layout.width == 0 ){
13291351 layout.width = container.maxWidth ;
@@ -1339,6 +1361,9 @@ void UISystem::update(double dt){
13391361 layout.height = container.maxHeight ;
13401362 }
13411363 }
1364+
1365+ if (layout.width < 1 ) layout.width = 1 ;
1366+ if (layout.height < 1 ) layout.height = 1 ;
13421367 }
13431368 }
13441369
0 commit comments