Просмотр исходного кода

Fixed a few issue with layout sizes

Marko Pintera 12 лет назад
Родитель
Сommit
7efe1bfa77

+ 7 - 2
BansheeEngine/Source/BsGUILayoutX.cpp

@@ -245,7 +245,7 @@ namespace BansheeEngine
 							numNonClampedElements--;
 						}
 
-						extraWidth = elementWidth - elementSizes[childIdx];
+						extraWidth = elementSizes[childIdx] - elementWidth;
 						elementSizes[childIdx] = elementWidth;
 						remainingSize = (UINT32)std::max(0, (INT32)remainingSize - (INT32)extraWidth);
 					}
@@ -333,7 +333,6 @@ namespace BansheeEngine
 		for(auto& child : mChildren)
 		{
 			UINT32 elemWidth = elementSizes[childIdx];
-			mActualWidth += elemWidth;
 
 			if(child->_getType() == GUIElementBase::Type::Element)
 			{
@@ -379,8 +378,14 @@ namespace BansheeEngine
 
 				UINT32 childHeight = layout->_getActualHeight();
 				mActualHeight = std::max(mActualHeight, childHeight);
+
+				// It's possible all elements didn't fit in the child layout size we provided, in which case expand our measurements
+				CM::UINT32 childLayoutWidth = layout->_getActualWidth();
+				if(childLayoutWidth > elemWidth)
+					elemWidth = childLayoutWidth;
 			}
 
+			mActualWidth += elemWidth;
 			xOffset += elemWidth;
 			childIdx++;
 		}

+ 9 - 5
BansheeEngine/Source/BsGUILayoutY.cpp

@@ -246,7 +246,7 @@ namespace BansheeEngine
 							numNonClampedElements--;
 						}
 
-						extraHeight = elementHeight - elementSizes[childIdx];
+						extraHeight = elementSizes[childIdx] - elementHeight;
 						elementSizes[childIdx] = elementHeight;
 						remainingSize = (UINT32)std::max(0, (INT32)remainingSize - (INT32)extraHeight);
 					}
@@ -334,8 +334,7 @@ namespace BansheeEngine
 		for(auto& child : mChildren)
 		{
 			UINT32 elemHeight = elementSizes[childIdx];
-			mActualHeight += elemHeight;
-
+			
 			if(child->_getType() == GUIElementBase::Type::Element)
 			{
 				GUIElement* element = static_cast<GUIElement*>(child);
@@ -377,10 +376,15 @@ namespace BansheeEngine
 				newClipRect.clip(clipRect);
 				layout->_updateLayoutInternal(x, y + yOffset, width, elemHeight, newClipRect, widgetDepth, areaDepth);
 
-				UINT32 childWidth = layout->_getActualWidth();
-				mActualWidth = std::max(mActualWidth, childWidth);
+				mActualWidth = std::max(mActualWidth, layout->_getActualWidth());
+
+				// It's possible all elements didn't fit in the child layout size we provided, in which case expand our measurements
+				CM::UINT32 childLayoutHeight = layout->_getActualHeight();
+				if(childLayoutHeight > elemHeight)
+					elemHeight = childLayoutHeight;
 			}
 
+			mActualHeight += elemHeight;
 			yOffset += elemHeight;
 			childIdx++;
 		}

+ 10 - 14
BansheeEngine/Source/BsGUIScrollArea.cpp

@@ -78,13 +78,11 @@ namespace BansheeEngine
 		if(contentHeight > mHeight)
 		{
 			// Make room for scrollbar
-			UINT32 contentWidth = (UINT32)std::max(0, (INT32)width - (INT32)ScrollBarWidth);
+			UINT32 clippedContentWidth = (UINT32)std::max(0, (INT32)width - (INT32)ScrollBarWidth);
 
-			Rect layoutClipRect(clipRect.x, clipRect.y, contentWidth, clipRect.height);
-			mContentLayout->_updateLayoutInternal(x, y - Math::FloorToInt(mVertOffset), contentWidth, height + Math::FloorToInt(mVertOffset), 
+			Rect layoutClipRect(clipRect.x, clipRect.y, clippedContentWidth, clipRect.height);
+			mContentLayout->_updateLayoutInternal(x, y - Math::FloorToInt(mVertOffset), clippedContentWidth, height + Math::FloorToInt(mVertOffset), 
 				layoutClipRect, widgetDepth, areaDepth);
-			contentWidth = mContentLayout->_getActualWidth();
-			contentHeight = mContentLayout->_getActualHeight();
 
 			if(mVertScroll == nullptr)
 			{
@@ -92,7 +90,7 @@ namespace BansheeEngine
 				mVertScroll->onScrollPositionChanged.connect(boost::bind(&GUIScrollArea::vertScrollUpdate, this, _1));
 			}
 
-			Int2 offset(x + contentWidth, y);
+			Int2 offset(x + clippedContentWidth, y);
 			mVertScroll->_setOffset(offset);
 			mVertScroll->_setWidth(ScrollBarWidth);
 			mVertScroll->_setHeight(height);
@@ -104,7 +102,7 @@ namespace BansheeEngine
 			mVertScroll->_setClipRect(elemClipRect);
 
 			// This element is not a child of any layout so we treat it as a root element
-			Rect scrollBarLayoutClipRect(clipRect.x + contentWidth, clipRect.y, clippedScrollbarWidth, clipRect.height);
+			Rect scrollBarLayoutClipRect(clipRect.x + clippedContentWidth, clipRect.y, clippedScrollbarWidth, clipRect.height);
 			mVertScroll->_updateLayout(offset.x, offset.y, ScrollBarWidth, height, scrollBarLayoutClipRect, widgetDepth, areaDepth);
 
 			// Set new handle size and update position to match the new size
@@ -130,13 +128,11 @@ namespace BansheeEngine
 		if(contentWidth > mWidth)
 		{ 
 			// Make room for scrollbar
-			UINT32 contentHeight = (UINT32)std::max(0, (INT32)height - (INT32)ScrollBarWidth);
+			UINT32 clippedContentHeight = (UINT32)std::max(0, (INT32)height - (INT32)ScrollBarWidth);
 
-			Rect layoutClipRect(clipRect.x, clipRect.y, clipRect.width, contentHeight);
+			Rect layoutClipRect(clipRect.x, clipRect.y, clipRect.width, clippedContentHeight);
 			mContentLayout->_updateLayoutInternal(x - Math::FloorToInt(mHorzOffset), y, width + Math::FloorToInt(mHorzOffset), 
-				contentHeight, layoutClipRect, widgetDepth, areaDepth);
-			contentWidth = mContentLayout->_getActualWidth();
-			contentHeight = mContentLayout->_getActualHeight();
+				clippedContentHeight, layoutClipRect, widgetDepth, areaDepth);
 
 			if(mHorzScroll == nullptr)
 			{
@@ -144,7 +140,7 @@ namespace BansheeEngine
 				mHorzScroll->onScrollPositionChanged.connect(boost::bind(&GUIScrollArea::horzScrollUpdate, this, _1));
 			}
 
-			Int2 offset(x, y + contentHeight);
+			Int2 offset(x, y + clippedContentHeight);
 			mHorzScroll->_setOffset(offset);
 			mHorzScroll->_setWidth(width);
 			mHorzScroll->_setHeight(ScrollBarWidth);
@@ -156,7 +152,7 @@ namespace BansheeEngine
 			mHorzScroll->_setClipRect(elemClipRect);
 
 			// This element is not a child of any layout so we treat it as a root element
-			Rect scrollBarLayoutClipRect(clipRect.x, clipRect.y + contentHeight, clipRect.width, clippedScrollbarHeight);
+			Rect scrollBarLayoutClipRect(clipRect.x, clipRect.y + clippedContentHeight, clipRect.width, clippedScrollbarHeight);
 			mHorzScroll->_updateLayout(offset.x, offset.y, width, ScrollBarWidth, scrollBarLayoutClipRect, widgetDepth, areaDepth);
 
 			// Set new handle size and update position to match the new size

+ 16 - 13
CamelotClient/CmEditorWindow.cpp

@@ -80,19 +80,22 @@ namespace BansheeEditor
 
 		GUILayout& scrollLayout = scrollArea->getLayout().addLayoutX();
 
-		scrollLayout.addElement(GUIButton::create(*mGUI, L"Test A"));
-		scrollLayout.addElement(GUIButton::create(*mGUI, L"Test B"));
-		scrollLayout.addElement(GUIButton::create(*mGUI, L"Test C"));
-		scrollLayout.addElement(GUIButton::create(*mGUI, L"Test D"));
-		scrollLayout.addElement(GUIButton::create(*mGUI, L"Test E"));
-		scrollLayout.addElement(GUIButton::create(*mGUI, L"Test F"));
-		scrollLayout.addElement(GUIButton::create(*mGUI, L"Test G"));
-		scrollLayout.addElement(GUIButton::create(*mGUI, L"Test H"));
-		scrollLayout.addElement(GUIButton::create(*mGUI, L"Test I"));
-		scrollLayout.addElement(GUIButton::create(*mGUI, L"Test J"));
-		scrollLayout.addElement(GUIButton::create(*mGUI, L"Test K"));
-		scrollLayout.addElement(GUIButton::create(*mGUI, L"Test L"));
-
+		//scrollLayout.addElement(GUIButton::create(*mGUI, L"Test A"));
+		//scrollLayout.addElement(GUIButton::create(*mGUI, L"Test B"));
+		//scrollLayout.addElement(GUIButton::create(*mGUI, L"Test C"));
+		//scrollLayout.addElement(GUIButton::create(*mGUI, L"Test D"));
+		//scrollLayout.addElement(GUIButton::create(*mGUI, L"Test E"));
+		//scrollLayout.addElement(GUIButton::create(*mGUI, L"Test F"));
+		//scrollLayout.addElement(GUIButton::create(*mGUI, L"Test G"));
+		//scrollLayout.addElement(GUIButton::create(*mGUI, L"Test H"));
+		//scrollLayout.addElement(GUIButton::create(*mGUI, L"Test I"));
+		//scrollLayout.addElement(GUIButton::create(*mGUI, L"Test J"));
+		//scrollLayout.addElement(GUIButton::create(*mGUI, L"Test K"));
+		//scrollLayout.addElement(GUIButton::create(*mGUI, L"Test L"));
+
+		scrollLayout.addElement(GUIInputBox::create(*mGUI, GUILayoutOptions::fixed(100, 100), true));
+		scrollLayout.addElement(GUIInputBox::create(*mGUI, GUILayoutOptions::fixed(100, 100), true));
+		scrollLayout.addElement(GUIInputBox::create(*mGUI, GUILayoutOptions::fixed(100, 100), true));
 
 		//GUIFlexibleSpace& space4 = otherLayout.addFlexibleSpace();
 		//otherLayout.addElement(mDbgLabel);

+ 6 - 1
TODO.txt

@@ -17,7 +17,10 @@ GUIWidget::updateMeshes leaks. If I leave the game running I can see memory cont
 Over the holidays:
  - Get release mode working
  - Profile code to see why it runs to slow in debug (AQTime probably)
+ - Get DebugRelease mode working
+ - Edit solution so that 32 bit binaries end up it x86 folder
  - Window docking/undocking
+ - (More platform specific files to /PlatformSpecific subfolder)
 
 IMMEDIATE:
  - Clicking on a window to focus and immediately trying to drag/resize it, doesn't work. I first need to click, then click again to drag/resize.
@@ -30,7 +33,9 @@ IMMEDIATE:
     - Make sure GUI system uses a dummy texture if one isn't available
 	- SpriteTexture keeps a static reference to DUmmyTexture which I need to release before shutdown
 
-- Test if horizontal + vert scroll works together
+- Vertical and horizontal scrollbars overlap when they're both used
+- Right scrollbar overlaps the contents (they're not clipped right?)
+- Contents start too high so that their top is not visible
 - InputBox text clip rect is probably wrong as it doesn't account parent element clip rect
  (possibly selection and caret clip rects too)
 - Hover colors of the scroll bar are wrong