Browse Source

GUILayout changes:
- Centered layout on Y
- Fixed an issue with fixed height

Marko Pintera 12 years ago
parent
commit
ff723c2a08

+ 1 - 1
BansheeEngine/Source/BsGUILabel.cpp

@@ -112,7 +112,7 @@ namespace BansheeEngine
 		{
 		{
 			layoutOptions.fixedWidth = false;
 			layoutOptions.fixedWidth = false;
 			layoutOptions.fixedHeight = true;
 			layoutOptions.fixedHeight = true;
-			layoutOptions.height = 20;
+			layoutOptions.height = 16;
 			layoutOptions.minWidth = 10;
 			layoutOptions.minWidth = 10;
 
 
 			layoutOptionsInitialized = true;
 			layoutOptionsInitialized = true;

+ 43 - 29
BansheeEngine/Source/BsGUILayoutX.cpp

@@ -10,16 +10,43 @@ namespace BansheeEngine
 {
 {
 	void GUILayoutX::updateInternal(UINT32 x, UINT32 y, UINT32 width, UINT32 height, UINT32 depth)
 	void GUILayoutX::updateInternal(UINT32 x, UINT32 y, UINT32 width, UINT32 height, UINT32 depth)
 	{
 	{
+		// Calculate flexible space sizes
 		std::vector<UINT32> flexibleSpaceSizes;
 		std::vector<UINT32> flexibleSpaceSizes;
+		UINT32 minimalTotalSize = 0;
 		for(auto& child : mChildren)
 		for(auto& child : mChildren)
 		{
 		{
 			if(child.isFlexibleSpace())
 			if(child.isFlexibleSpace())
 			{
 			{
 				flexibleSpaceSizes.push_back(0);
 				flexibleSpaceSizes.push_back(0);
 			}
 			}
+			else if(child.isFixedSpace())
+			{
+				minimalTotalSize += child.space->getSize();
+			}
+			else if(child.isElement())
+			{
+				const GUI_LAYOUT_OPTIONS& layoutOptions = child.element->_getLayoutOptions();
+
+				if(layoutOptions.fixedWidth)
+					minimalTotalSize += layoutOptions.width;
+				else if(layoutOptions.minWidth > 0)
+					minimalTotalSize += layoutOptions.minWidth;
+				else
+					minimalTotalSize += child.element->_getOptimalWidth();
+			}
 		}
 		}
 
 
-		// TODO - Calculate flexible space sizes
+		float avgFlexibleSpaceSize = minimalTotalSize / (float)flexibleSpaceSizes.size();
+		UINT32 remainingMinSize = minimalTotalSize;
+
+		for(size_t i = 0; i < flexibleSpaceSizes.size(); i++)
+		{
+			UINT32 spaceSize = (UINT32)Math::CeilToInt(avgFlexibleSpaceSize);
+			spaceSize = std::min(remainingMinSize, spaceSize);
+
+			remainingMinSize -= spaceSize;
+			flexibleSpaceSizes[i] = spaceSize;
+		}
 
 
 		// Get a basic estimate of the average width
 		// Get a basic estimate of the average width
 		UINT32 totalWidth = 0;
 		UINT32 totalWidth = 0;
@@ -98,21 +125,6 @@ namespace BansheeEngine
 				}
 				}
 
 
 				child.element->_setWidth(elementWidth);
 				child.element->_setWidth(elementWidth);
-
-				if(layoutOptions.fixedHeight)
-					child.element->_setHeight(layoutOptions.fixedHeight);
-				else
-				{
-					UINT32 optimalHeight = child.element->_getOptimalHeight();
-					
-					if(layoutOptions.minHeight > 0)
-						optimalHeight = std::max(layoutOptions.minHeight, optimalHeight);
-
-					if(layoutOptions.maxHeight > 0)
-						optimalHeight = std::min(layoutOptions.maxHeight, optimalHeight);
-
-					child.element->_setHeight(optimalHeight);
-				}
 			}
 			}
 		}
 		}
 
 
@@ -134,27 +146,29 @@ namespace BansheeEngine
 					leftoverWidth = (UINT32)std::max(0, (INT32)leftoverWidth - (INT32)elementWidth);
 					leftoverWidth = (UINT32)std::max(0, (INT32)leftoverWidth - (INT32)elementWidth);
 
 
 					child.element->_setWidth(elementWidth);
 					child.element->_setWidth(elementWidth);
+				}
 
 
-					if(layoutOptions.fixedHeight)
-						child.element->_setHeight(layoutOptions.fixedHeight);
-					else
-					{
-						UINT32 optimalHeight = child.element->_getOptimalHeight();
+				if(layoutOptions.fixedHeight)
+					child.element->_setHeight(layoutOptions.height);
+				else
+				{
+					UINT32 optimalHeight = child.element->_getOptimalHeight();
 
 
-						if(layoutOptions.minHeight > 0)
-							optimalHeight = std::max(layoutOptions.minHeight, optimalHeight);
+					if(layoutOptions.minHeight > 0)
+						optimalHeight = std::max(layoutOptions.minHeight, optimalHeight);
 
 
-						if(layoutOptions.maxHeight > 0)
-							optimalHeight = std::min(layoutOptions.maxHeight, optimalHeight);
+					if(layoutOptions.maxHeight > 0)
+						optimalHeight = std::min(layoutOptions.maxHeight, optimalHeight);
 
 
-						child.element->_setHeight(optimalHeight);
-					}
+					child.element->_setHeight(optimalHeight);
 				}
 				}
 
 
-				child.element->_setOffset(Int2(x + xOffset, y));
+				UINT32 yOffset = (UINT32)Math::CeilToInt((height - child.element->_getHeight()) * 0.5f);
+
+				child.element->_setOffset(Int2(x + xOffset, y + yOffset));
 				child.element->_setDepth(depth);
 				child.element->_setDepth(depth);
 
 
-				// TODO - Set clip rect
+				child.element->_setClipRect(Rect(0, 0, child.element->_getWidth(), child.element->_getHeight()));
 
 
 				xOffset += child.element->_getWidth();
 				xOffset += child.element->_getWidth();
 			}
 			}

+ 9 - 5
CamelotClient/CmEditorWindow.cpp

@@ -49,16 +49,20 @@ namespace BansheeEditor
 		//// DEBUG
 		//// DEBUG
 		mGUI->setSkin(&EngineGUI::instance().getSkin());
 		mGUI->setSkin(&EngineGUI::instance().getSkin());
 
 
-		GUIArea* backgroundArea = GUIArea::create(*mGUI, 0, 0, 0, 0, 0);
-		GUILayout& layout = backgroundArea->getLayout();
+		//GUIArea* backgroundArea = GUIArea::create(*mGUI, 0, 0, 0, 0, 0);
+		//GUILayout& layout = backgroundArea->getLayout();
 		
 		
 		mDbgLabel = GUILabel::create(*mGUI, "Testing test");
 		mDbgLabel = GUILabel::create(*mGUI, "Testing test");
-		layout.addElement(mDbgLabel);
+		/*layout.addElement(mDbgLabel);*/
 
 
 		GUIArea* mainArea = GUIArea::create(*mGUI, 0, 0, 0, 0, 1);
 		GUIArea* mainArea = GUIArea::create(*mGUI, 0, 0, 0, 0, 1);
 		GUILayout& otherLayout = mainArea->getLayout();
 		GUILayout& otherLayout = mainArea->getLayout();
 
 
-		otherLayout.addElement(GUIWindowFrame::create(*mGUI));
+		otherLayout.addElement(mDbgLabel);
+
+		//GUIFixedSpace& space = otherLayout.addSpace(10); // Due to bug in MSVC compiler I need to store return value
+		otherLayout.addElement(GUIWindowFrame::create(*mGUI, GUI_LAYOUT_OPTIONS(20, 20)));
+		//GUIFixedSpace& space2 = otherLayout.addSpace(10);
 		otherLayout.addElement(GUIWindowFrame::create(*mGUI));
 		otherLayout.addElement(GUIWindowFrame::create(*mGUI));
 	}
 	}
 
 
@@ -71,6 +75,6 @@ namespace BansheeEditor
 	{
 	{
 		Int2 cursorPos = Cursor::getWindowPosition(*mRenderWindow);
 		Int2 cursorPos = Cursor::getWindowPosition(*mRenderWindow);
 		
 		
-		mDbgLabel->setText(toString(cursorPos.x) + ", " + toString(cursorPos.y));
+		mDbgLabel->setText("Position: " + toString(cursorPos.x) + ", " + toString(cursorPos.y));
 	}
 	}
 }
 }

+ 11 - 3
TODO.txt

@@ -22,12 +22,20 @@ I call waitUntilLoaded too many times. Sometimes 5-6 times in a single function.
 GUIWidget::updateMeshes leaks. If I leave the game running I can see memory continously going up
 GUIWidget::updateMeshes leaks. If I leave the game running I can see memory continously going up
 
 
 IMMEDIATE:
 IMMEDIATE:
- - On content change I need to notify parent layout
- - Add clip rectangles on GUILayoutX
- - Calculate flexible spaces in GUILyoutX
  - Call layout update before remesh and input in GUIManager
  - Call layout update before remesh and input in GUIManager
  - Implement GUILayoutY
  - Implement GUILayoutY
 
 
+ Test multiple layout elements
+Test nested elements
+Test with clamped min/max elements
+Test with flexible space, left center and right
+
+-----------
+
+I need to be able to provide smaller bounds used for UI input 
+ - Add padding - reduces the size of the element and that is used for input
+ - Add margins - spacing that is added when laying out multiple controls after each other
+
 Figure out how to deal with callbacks properly. I recently eliminated them from Input but I'll need them for my GUI elements...
 Figure out how to deal with callbacks properly. I recently eliminated them from Input but I'll need them for my GUI elements...
  - How do I implement them? I really don't want to do Unitys approach to GUI
  - How do I implement them? I really don't want to do Unitys approach to GUI
  - If I do figure out a good way to keep callbacks, maybe rethink Input and re-add them?
  - If I do figure out a good way to keep callbacks, maybe rethink Input and re-add them?