Bladeren bron

FIxing up the flexible space calculations

Marko Pintera 12 jaren geleden
bovenliggende
commit
cf498e86e6
3 gewijzigde bestanden met toevoegingen van 17 en 12 verwijderingen
  1. 16 8
      BansheeEngine/Source/BsGUILayoutX.cpp
  2. 1 0
      CamelotClient/CmEditorWindow.cpp
  3. 0 4
      TODO.txt

+ 16 - 8
BansheeEngine/Source/BsGUILayoutX.cpp

@@ -29,22 +29,30 @@ namespace BansheeEngine
 
 				if(layoutOptions.fixedWidth)
 					minimalTotalSize += layoutOptions.width;
-				else if(layoutOptions.minWidth > 0)
-					minimalTotalSize += layoutOptions.minWidth;
 				else
-					minimalTotalSize += child.element->_getOptimalWidth();
+				{
+					UINT32 optimalWidth = child.element->_getOptimalWidth();
+
+					if(layoutOptions.minHeight > 0)
+						optimalWidth = std::max(layoutOptions.minWidth, optimalWidth);
+
+					if(layoutOptions.maxHeight > 0)
+						optimalWidth = std::min(layoutOptions.maxWidth, optimalWidth);
+
+					minimalTotalSize += optimalWidth;
+				}
 			}
 		}
 
-		float avgFlexibleSpaceSize = minimalTotalSize / (float)flexibleSpaceSizes.size();
-		UINT32 remainingMinSize = minimalTotalSize;
-
+		UINT32 remainingFlexSpaceSize = (UINT32)std::max(0, (INT32)width - (INT32)minimalTotalSize);
+		float avgFlexibleSpaceSize = remainingFlexSpaceSize / (float)flexibleSpaceSizes.size();
+		
 		for(size_t i = 0; i < flexibleSpaceSizes.size(); i++)
 		{
 			UINT32 spaceSize = (UINT32)Math::CeilToInt(avgFlexibleSpaceSize);
-			spaceSize = std::min(remainingMinSize, spaceSize);
+			spaceSize = std::min(remainingFlexSpaceSize, spaceSize);
 
-			remainingMinSize -= spaceSize;
+			remainingFlexSpaceSize -= spaceSize;
 			flexibleSpaceSizes[i] = spaceSize;
 		}
 

+ 1 - 0
CamelotClient/CmEditorWindow.cpp

@@ -61,6 +61,7 @@ namespace BansheeEditor
 		otherLayout.addElement(mDbgLabel);
 
 		//GUIFixedSpace& space = otherLayout.addSpace(10); // Due to bug in MSVC compiler I need to store return value
+		GUIFlexibleSpace& space3 = otherLayout.addFlexibleSpace();
 		otherLayout.addElement(GUIWindowFrame::create(*mGUI, GUILayoutOptions::expandableX(20, 100)));
 		//GUIFixedSpace& space2 = otherLayout.addSpace(10);
 		otherLayout.addElement(GUIWindowFrame::create(*mGUI));

+ 0 - 4
TODO.txt

@@ -23,12 +23,8 @@ GUIWidget::updateMeshes leaks. If I leave the game running I can see memory cont
 
 IMMEDIATE:
  - Implement GUILayoutY
- - Clip rect: Fixed size (or min clamped) elements that don't fit within the layout?!
-   - Imagine two vertical layouts next to each other, each 100 pixels, and the left one has 200 pix wide elements which crosses over to the next layout.
 
- Test multiple layout elements
 Test nested elements
-Test with clamped min/max elements
 Test with flexible space, left center and right
 
 -----------