浏览代码

Added GUI padding

Marko Pintera 11 年之前
父节点
当前提交
f7d7777fc5

+ 1 - 0
BansheeEngine/BansheeEngine.vcxproj

@@ -287,6 +287,7 @@
     <ClInclude Include="Include\BsGUIWidget.h" />
     <ClInclude Include="Include\BsImageSprite.h" />
     <ClInclude Include="Include\BsProfilerOverlay.h" />
+    <ClInclude Include="Include\BsRectOffset.h" />
     <ClInclude Include="Include\BsSceneManager.h" />
     <ClInclude Include="Include\BsGUIScrollArea.h" />
     <ClInclude Include="Include\BsScriptManager.h" />

+ 3 - 0
BansheeEngine/BansheeEngine.vcxproj.filters

@@ -273,6 +273,9 @@
     <ClInclude Include="Include\BsEnums.h">
       <Filter>Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="Include\BsRectOffset.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="Source\BsGUIElement.cpp">

+ 1 - 0
BansheeEngine/Include/BsGUIElement.h

@@ -128,6 +128,7 @@ namespace BansheeEngine
 
 		const CM::RectI& _getClippedBounds() const { return mClippedBounds; }
 		const CM::RectI& _getClipRect() const { return mClipRect; }
+		const RectOffset& _getPadding() const;
 		CM::UINT32 _getDepth() const { return mDepth; }
 		GUIWidget& _getParentWidget() const { return *mParent; }
 		virtual bool _isInBounds(const CM::Vector2I position) const;

+ 2 - 0
BansheeEngine/Include/BsGUIElementBase.h

@@ -5,6 +5,7 @@
 #include "BsGUILayoutOptions.h"
 #include "CmRectI.h"
 #include "CmVector2I.h"
+#include "BsRectOffset.h"
 
 namespace BansheeEngine
 {
@@ -49,6 +50,7 @@ namespace BansheeEngine
 		void _setParent(GUIElementBase* parent) { mParentElement = parent; }
 
 		virtual CM::Vector2I _getOptimalSize() const = 0;
+		virtual const RectOffset& _getPadding() const = 0;
 		virtual Type _getType() const = 0;
 		GUIElementBase* _getParent() const { return mParentElement; }
 

+ 2 - 9
BansheeEngine/Include/BsGUIElementStyle.h

@@ -1,21 +1,13 @@
 #pragma once
 
 #include "BsPrerequisites.h"
+#include "BsRectOffset.h"
 #include "BsTextSprite.h"
 #include "CmColor.h"
 #include "CmVector2I.h"
 
 namespace BansheeEngine
 {
-	struct RectOffset
-	{
-		RectOffset()
-			:left(0), right(0), top(0), bottom(0)
-		{ }
-
-		CM::INT32 left, right, top, bottom;
-	};
-
 	enum class GUIImagePosition
 	{
 		Left, Right
@@ -59,6 +51,7 @@ namespace BansheeEngine
 		RectOffset border; // Determines how the element is scaled (using the typical Scale9Grid approach)
 		RectOffset margins; // Determines offset from the background graphics to the content. Input uses bounds offset by this value.
 		RectOffset contentOffset; // Additional offset to the content, that doesn't effect the bounds. Applied on top of the margins offsets.
+		RectOffset padding; // Determines extra distance between this and other elements in a layout
 
 		CM::UINT32 width;
 		CM::UINT32 height;

+ 1 - 0
BansheeEngine/Include/BsGUILayout.h

@@ -34,6 +34,7 @@ namespace BansheeEngine
 		void removeChildAt(CM::UINT32 idx);
 
 		CM::Vector2I _getOptimalSize() const { return CM::Vector2I(mOptimalWidth, mOptimalHeight); }
+		const RectOffset& _getPadding() const;
 		Type _getType() const { return GUIElementBase::Type::Layout; }
 
 		/**

+ 12 - 0
BansheeEngine/Include/BsGUISpace.h

@@ -18,6 +18,12 @@ namespace BansheeEngine
 		Type _getType() const { return GUIElementBase::Type::FixedSpace; }
 
 		virtual CM::Vector2I _getOptimalSize() const { return CM::Vector2I(getSize(), getSize()); }
+		virtual const RectOffset& _getPadding() const 
+		{
+			static RectOffset padding;
+
+			return padding;
+		}
 
 	protected:
 		CM::UINT32 mSize;
@@ -34,5 +40,11 @@ namespace BansheeEngine
 		Type _getType() const { return GUIElementBase::Type::FlexibleSpace; }
 
 		virtual CM::Vector2I _getOptimalSize() const { return CM::Vector2I(0, 0); }
+		virtual const RectOffset& _getPadding() const 
+		{
+			static RectOffset padding;
+
+			return padding;
+		}
 	};
 }

+ 15 - 0
BansheeEngine/Include/BsRectOffset.h

@@ -0,0 +1,15 @@
+#pragma once
+
+#include "BsPrerequisites.h"
+
+namespace BansheeEngine
+{
+	struct RectOffset
+	{
+		RectOffset()
+			:left(0), right(0), top(0), bottom(0)
+		{ }
+
+		CM::INT32 left, right, top, bottom;
+	};
+}

+ 12 - 0
BansheeEngine/Source/BsGUIElement.cpp

@@ -137,6 +137,18 @@ namespace BansheeEngine
 		GUIElementBase::_changeParentWidget(widget);
 	}
 
+	const RectOffset& GUIElement::_getPadding() const
+	{
+		if(mStyle != nullptr)
+			return mStyle->padding;
+		else
+		{
+			static RectOffset padding;
+
+			return padding;
+		}
+	}
+
 	RectI GUIElement::getBounds() const
 	{
 		return RectI(mOffset.x, mOffset.y, mWidth, mHeight);

+ 7 - 0
BansheeEngine/Source/BsGUILayout.cpp

@@ -152,4 +152,11 @@ namespace BansheeEngine
 
 		return *entry;
 	}
+
+	const RectOffset& GUILayout::_getPadding() const
+	{
+		static RectOffset padding;
+
+		return padding;
+	}
 }

+ 10 - 5
BansheeEngine/Source/BsGUILayoutX.cpp

@@ -73,11 +73,14 @@ namespace BansheeEngine
 				optimalHeight = child->_getOptimalSize().y;
 			}
 
+			UINT32 paddingX = child->_getPadding().left + child->_getPadding().right;
+			UINT32 paddingY = child->_getPadding().top + child->_getPadding().bottom;
+
 			mOptimalSizes[childIdx].x = optimalWidth;
-			mOptimalWidth += optimalWidth;
+			mOptimalWidth += optimalWidth + paddingX;
 
 			mOptimalSizes[childIdx].y = optimalHeight;
-			mOptimalHeight = std::max(mOptimalHeight, optimalHeight);
+			mOptimalHeight = std::max(mOptimalHeight, optimalHeight + paddingY);
 
 			childIdx++;
 		}
@@ -345,6 +348,7 @@ namespace BansheeEngine
 		for(auto& child : mChildren)
 		{
 			UINT32 elemWidth = elementSizes[childIdx];
+			xOffset += child->_getPadding().left;
 
 			if(child->_getType() == GUIElementBase::Type::Element)
 			{
@@ -365,7 +369,8 @@ namespace BansheeEngine
 
 				element->_setHeight(elemHeight);
 
-				INT32 yOffset = Math::ceilToInt(((INT32)height - (INT32)element->_getHeight()) * 0.5f);
+				UINT32 yPadding = element->_getPadding().top + element->_getPadding().bottom;
+				INT32 yOffset = Math::ceilToInt(((INT32)height - (INT32)(element->_getHeight() + yPadding)) * 0.5f);
 				yOffset = std::max(0, yOffset);
 
 				Vector2I offset(x + xOffset, y + yOffset);
@@ -397,8 +402,8 @@ namespace BansheeEngine
 				elemWidth = layout->_getActualWidth();
 			}
 
-			mActualWidth += elemWidth;
-			xOffset += elemWidth;
+			mActualWidth += elemWidth + child->_getPadding().left + child->_getPadding().right;
+			xOffset += elemWidth + child->_getPadding().right;
 			childIdx++;
 		}
 

+ 10 - 5
BansheeEngine/Source/BsGUILayoutY.cpp

@@ -74,11 +74,14 @@ namespace BansheeEngine
 				optimalHeight = layout->_getOptimalSize().y;
 			}
 
+			UINT32 paddingX = child->_getPadding().left + child->_getPadding().right;
+			UINT32 paddingY = child->_getPadding().top + child->_getPadding().bottom;
+
 			mOptimalSizes[childIdx].y = optimalHeight;
-			mOptimalHeight += optimalHeight;
+			mOptimalHeight += optimalHeight + paddingY;
 
 			mOptimalSizes[childIdx].x = optimalWidth;
-			mOptimalWidth = std::max(mOptimalWidth, optimalWidth);
+			mOptimalWidth = std::max(mOptimalWidth, optimalWidth + paddingX);
 
 			childIdx++;
 		}
@@ -339,6 +342,7 @@ namespace BansheeEngine
 		for(auto& child : mChildren)
 		{
 			UINT32 elemHeight = elementSizes[childIdx];
+			yOffset += child->_getPadding().top;
 			
 			if(child->_getType() == GUIElementBase::Type::Element)
 			{
@@ -358,7 +362,8 @@ namespace BansheeEngine
 				element->_setWidth(elemWidth);
 				element->_setHeight(elemHeight);
 
-				INT32 xOffset = Math::ceilToInt((INT32)(width - (INT32)element->_getWidth()) * 0.5f);
+				UINT32 xPadding = element->_getPadding().left + element->_getPadding().right;
+				INT32 xOffset = Math::ceilToInt((INT32)(width - (INT32)(element->_getWidth() + xPadding)) * 0.5f);
 				xOffset = std::max(0, xOffset);
 
 				Vector2I offset(x + xOffset, y + yOffset);
@@ -389,8 +394,8 @@ namespace BansheeEngine
 				elemHeight = layout->_getActualHeight();
 			}
 
-			mActualHeight += elemHeight;
-			yOffset += elemHeight;
+			mActualHeight += elemHeight + child->_getPadding().top + child->_getPadding().bottom;
+			yOffset += elemHeight + child->_getPadding().bottom;
 			childIdx++;
 		}