Browse Source

Fixed a GUI layout squishing issue that was caused by GUI panels not having their minimal layout size calculated
Fixed an issue where inspector window title background was causing the scrollbar to appear when not really needed

BearishSun 10 years ago
parent
commit
b489b88a5a

+ 0 - 14
BansheeEngine/Include/BsGUILayout.h

@@ -96,20 +96,6 @@ namespace BansheeEngine
 		 */
 		virtual Type _getType() const override { return GUIElementBase::Type::Layout; }
 
-		/**
-		 * @brief	Calculates the actual size of the layout taken up by all of its elements.
-		 *
-		 * @param	x				Origin based on which to calculate the size.
-		 * @param	y				Origin based on which to calculate the size.
-		 * @param	elementAreas	Array containing areas of all child elements.
-		 * @param	numElements		Number of elements in the elements array.
-		 *			
-		 * @note	Actual size means the bounds might be smaller or larger than the layout area itself.
-		 *			If larger that means certain portions of the child elements will be clipped, and if
-		 *			smaller certain portions of the layout area will be empty.
-		 */
-		virtual Vector2I _calcActualSize(INT32 x, INT32 y, Rect2I* elementAreas, UINT32 numElements) const = 0;
-
 		/**
 		 * @brief	Destroy the layout. Removes it from parent and widget, and deletes it.
 		 */	

+ 0 - 5
BansheeEngine/Include/BsGUILayoutX.h

@@ -32,11 +32,6 @@ namespace BansheeEngine
 		void _getElementAreas(const Rect2I& layoutArea, Rect2I* elementAreas, UINT32 numElements,
 			const Vector<LayoutSizeRange>& sizeRanges, const LayoutSizeRange& mySizeRange) const override;
 
-		/**
-		 * @copydoc	GUILayout::_calcActualSize
-		 */
-		virtual Vector2I _calcActualSize(INT32 x, INT32 y, Rect2I* elementAreas, UINT32 numElements) const override;
-
 		/**
 		 * @brief	Creates a new horizontal layout.
 		 */

+ 0 - 5
BansheeEngine/Include/BsGUILayoutY.h

@@ -32,11 +32,6 @@ namespace BansheeEngine
 		void _getElementAreas(const Rect2I& layoutArea, Rect2I* elementAreas, UINT32 numElements,
 			const Vector<LayoutSizeRange>& sizeRanges, const LayoutSizeRange& mySizeRange) const override;
 
-		/**
-		 * @copydoc	GUILayout::_calcActualSize
-		 */
-		 virtual Vector2I _calcActualSize(INT32 x, INT32 y, Rect2I* elementAreas, UINT32 numElements) const override;
-
 		/**
 		 * @brief	Creates a new vertical layout.
 		 */

+ 0 - 5
BansheeEngine/Include/BsGUIPanel.h

@@ -59,11 +59,6 @@ namespace BansheeEngine
 		 */
 		void _updateChildLayout(GUIElementBase* element, const GUILayoutData& data);
 
-		/**
-		 * @copydoc	GUILayout::_calcActualSize
-		 */
-		virtual Vector2I _calcActualSize(INT32 x, INT32 y, Rect2I* elementAreas, UINT32 numElements) const override;
-
 		/**
 		 * @copydoc	GUIElementBase::_updateLayoutInternal
 		 */

+ 23 - 1
BansheeEngine/Source/BsGUILayoutUtility.cpp

@@ -63,7 +63,29 @@ namespace BansheeEngine
 			}
 		}
 
-		Vector2I actualSize = layout->_calcActualSize(0, 0, actualAreas, numElements);
+		Vector2I min;
+		Vector2I max;
+
+		if (numElements > 0)
+		{
+			Rect2I childArea = actualAreas[0];
+
+			min = Vector2I(childArea.x, childArea.y);
+			max = Vector2I(childArea.x + childArea.width, childArea.y + childArea.height);
+		}
+
+		for (UINT32 i = 1; i < numElements; i++)
+		{
+			Rect2I childArea = actualAreas[i];
+
+			min.x = std::min(min.x, childArea.x);
+			min.y = std::min(min.y, childArea.y);
+
+			max.x = std::max(max.x, childArea.x + childArea.width);
+			max.y = std::max(max.y, childArea.y + childArea.height);
+		}
+
+		Vector2I actualSize = max - min;
 
 		if (elementAreas != nullptr)
 			bs_stack_free(elementAreas);

+ 0 - 14
BansheeEngine/Source/BsGUILayoutX.cpp

@@ -406,20 +406,6 @@ namespace BansheeEngine
 			bs_stack_free(elementAreas);
 	}
 
-	Vector2I GUILayoutX::_calcActualSize(INT32 x, INT32 y, Rect2I* elementAreas, UINT32 numElements) const
-	{
-		Vector2I actualArea;
-		for (UINT32 i = 0; i < numElements; i++)
-		{
-			Rect2I childArea = elementAreas[i];
-
-			actualArea.x += childArea.width;
-			actualArea.y = std::max(actualArea.y, childArea.height);
-		}
-
-		return actualArea;
-	}
-
 	GUILayoutX* GUILayoutX::create()
 	{
 		return bs_new<GUILayoutX>();

+ 1 - 15
BansheeEngine/Source/BsGUILayoutY.cpp

@@ -3,7 +3,6 @@
 #include "BsGUISpace.h"
 #include "BsMath.h"
 #include "BsVector2I.h"
-#include "BsProfilerCPU.h"
 
 namespace BansheeEngine
 {
@@ -18,6 +17,7 @@ namespace BansheeEngine
 
 		Vector2I optimalSize;
 		Vector2I minSize;
+
 		for (auto& child : mChildren)
 		{
 			LayoutSizeRange sizeRange = child->_calculateLayoutSizeRange();
@@ -404,20 +404,6 @@ namespace BansheeEngine
 			bs_stack_free(elementAreas);
 	}
 
-	Vector2I GUILayoutY::_calcActualSize(INT32 x, INT32 y, Rect2I* elementAreas, UINT32 numElements) const
-	{
-		Vector2I actualArea;
-		for (UINT32 i = 0; i < numElements; i++)
-		{
-			Rect2I childArea = elementAreas[i];
-
-			actualArea.x = std::max(actualArea.x, childArea.width);
-			actualArea.y += childArea.height;
-		}
-
-		return actualArea;
-	}
-
 	GUILayoutY* GUILayoutY::create()
 	{
 		return bs_new<GUILayoutY>();

+ 32 - 34
BansheeEngine/Source/BsGUIPanel.cpp

@@ -26,26 +26,40 @@ namespace BansheeEngine
 			return LayoutSizeRange();
 
 		Vector2I optimalSize;
+		Vector2I minSize;
 
 		for (auto& child : mChildren)
 		{
 			LayoutSizeRange sizeRange = child->_calculateLayoutSizeRange();
 
 			if (child->_getType() == GUIElementBase::Type::FixedSpace || child->_getType() == GUIElementBase::Type::FlexibleSpace)
+			{
 				sizeRange.optimal.x = sizeRange.optimal.y = 0;
+				sizeRange.min.x = sizeRange.min.y = 0;
+			}
 
 			UINT32 paddingX = child->_getPadding().left + child->_getPadding().right;
 			UINT32 paddingY = child->_getPadding().top + child->_getPadding().bottom;
 
-			Vector2I childMax(child->_getDimensions().x, child->_getDimensions().y);
-			childMax.x += sizeRange.optimal.x + paddingX;
-			childMax.y += sizeRange.optimal.y + paddingY;
+			Vector2I childMax;
+			childMax.x = child->_getDimensions().x + sizeRange.optimal.x + paddingX;
+			childMax.y = child->_getDimensions().y + sizeRange.optimal.y + paddingY;
 
 			optimalSize.x = std::max(optimalSize.x, childMax.x);
 			optimalSize.y = std::max(optimalSize.y, childMax.y);
+
+			childMax.x = child->_getDimensions().x + sizeRange.min.x + paddingX;
+			childMax.y = child->_getDimensions().y + sizeRange.min.y + paddingY;
+
+			minSize.x = std::max(minSize.x, childMax.x);
+			minSize.y = std::max(minSize.y, childMax.y);
 		}
 
-		return _getDimensions().calculateSizeRange(optimalSize);
+		LayoutSizeRange sizeRange = _getDimensions().calculateSizeRange(optimalSize);
+		sizeRange.min.x = std::max(sizeRange.min.x, minSize.x);
+		sizeRange.min.y = std::max(sizeRange.min.y, minSize.y);
+
+		return sizeRange;
 	}
 
 	LayoutSizeRange GUIPanel::_getElementSizeRange(const GUIElementBase* element) const
@@ -55,6 +69,8 @@ namespace BansheeEngine
 			LayoutSizeRange sizeRange = element->_getLayoutSizeRange();
 			sizeRange.optimal.x = 0;
 			sizeRange.optimal.y = 0;
+			sizeRange.min.x = 0;
+			sizeRange.min.y = 0;
 
 			return sizeRange;
 		}
@@ -71,6 +87,7 @@ namespace BansheeEngine
 			mChildSizeRanges.resize(mChildren.size());
 
 		Vector2I optimalSize;
+		Vector2I minSize;
 
 		UINT32 childIdx = 0;
 		for (auto& child : mChildren)
@@ -81,17 +98,25 @@ namespace BansheeEngine
 			UINT32 paddingX = child->_getPadding().left + child->_getPadding().right;
 			UINT32 paddingY = child->_getPadding().top + child->_getPadding().bottom;
 
-			Vector2I childMax(child->_getDimensions().x, child->_getDimensions().y);
-			childMax.x += childSizeRange.optimal.x + paddingX;
-			childMax.y += childSizeRange.optimal.y + paddingY;
+			Vector2I childMax;
+			childMax.x = child->_getDimensions().x + childSizeRange.optimal.x + paddingX;
+			childMax.y = child->_getDimensions().y + childSizeRange.optimal.y + paddingY;
 
 			optimalSize.x = std::max(optimalSize.x, childMax.x);
 			optimalSize.y = std::max(optimalSize.y, childMax.y);
 
+			childMax.x = child->_getDimensions().x + childSizeRange.min.x + paddingX;
+			childMax.y = child->_getDimensions().y + childSizeRange.min.y + paddingY;
+
+			minSize.x = std::max(minSize.x, childMax.x);
+			minSize.y = std::max(minSize.y, childMax.y);
+
 			childIdx++;
 		}
 
 		mSizeRange = _getDimensions().calculateSizeRange(optimalSize);
+		mSizeRange.min.x = std::max(mSizeRange.min.x, minSize.x);
+		mSizeRange.min.y = std::max(mSizeRange.min.y, minSize.y);
 	}
 
 	void GUIPanel::_getElementAreas(const Rect2I& layoutArea, Rect2I* elementAreas, UINT32 numElements,
@@ -226,33 +251,6 @@ namespace BansheeEngine
 		element->_updateLayoutInternal(childData);
 	}
 
-	Vector2I GUIPanel::_calcActualSize(INT32 x, INT32 y, Rect2I* elementAreas, UINT32 numElements) const
-	{
-		Vector2I min;
-		Vector2I max;
-
-		if (numElements > 0)
-		{
-			Rect2I childArea = elementAreas[0];
-
-			min = Vector2I(childArea.x, childArea.y);
-			max = Vector2I(childArea.x + childArea.width, childArea.y + childArea.height);
-		}
-
-		for (UINT32 i = 1; i < numElements; i++)
-		{
-			Rect2I childArea = elementAreas[i];
-
-			min.x = std::min(min.x, childArea.x);
-			min.y = std::min(min.y, childArea.y);
-
-			max.x = std::max(max.x, childArea.x + childArea.width);
-			max.y = std::max(max.y, childArea.y + childArea.height);
-		}
-
-		return max - min;
-	}
-
 	GUIPanel* GUIPanel::create(INT16 depth, UINT16 depthRangeMin, UINT16 depthRangeMax)
 	{
 		return bs_new<GUIPanel>(depth, depthRangeMin, depthRangeMax, GUIDimensions::create());

+ 21 - 6
BansheeEngine/Source/BsGUIScrollArea.cpp

@@ -154,9 +154,14 @@ namespace BansheeEngine
 		{
 			// Make room for scrollbar
 			visibleSize.y = (UINT32)std::max(0, (INT32)layoutArea.height - (INT32)ScrollBarWidth);
-			layoutHeight = (UINT32)visibleSize.y;
+			optimalContentHeight = (UINT32)std::max(0, (INT32)optimalContentHeight - (INT32)ScrollBarWidth);
 
-			contentSize = GUILayoutUtility::calcActualSize(layoutWidth, layoutHeight, mContentLayout, false);
+			if (sizeRanges[layoutIdx].min.y > 0)
+				optimalContentHeight = std::max((UINT32)sizeRanges[layoutIdx].min.y, optimalContentHeight);
+
+			layoutHeight = std::max(optimalContentHeight, (UINT32)visibleSize.y); // Never go below optimal size
+
+			contentSize = GUILayoutUtility::calcActualSize(layoutWidth, layoutHeight, mContentLayout, true);
 			hasHorzScrollbar = true;
 		}
 
@@ -167,9 +172,14 @@ namespace BansheeEngine
 		{
 			// Make room for scrollbar
 			visibleSize.x = (UINT32)std::max(0, (INT32)layoutArea.width - (INT32)ScrollBarWidth);
-			layoutWidth = (UINT32)visibleSize.x;
+			optimalContentWidth = (UINT32)std::max(0, (INT32)optimalContentWidth - (INT32)ScrollBarWidth);
+
+			if (sizeRanges[layoutIdx].min.x > 0)
+				optimalContentWidth = std::max((UINT32)sizeRanges[layoutIdx].min.x, optimalContentWidth);
 
-			contentSize = GUILayoutUtility::calcActualSize(layoutWidth, layoutHeight, mContentLayout, false);
+			layoutWidth = std::max(optimalContentWidth, (UINT32)visibleSize.x); // Never go below optimal size
+
+			contentSize = GUILayoutUtility::calcActualSize(layoutWidth, layoutHeight, mContentLayout, true);
 			hasVertScrollbar = true;
 
 			if (!hasHorzScrollbar) // Since width has been reduced, we need to check if we require the horizontal scrollbar
@@ -180,9 +190,14 @@ namespace BansheeEngine
 				{
 					// Make room for scrollbar
 					visibleSize.y = (UINT32)std::max(0, (INT32)layoutArea.height - (INT32)ScrollBarWidth);
-					layoutHeight = (UINT32)visibleSize.y;
+					optimalContentHeight = (UINT32)std::max(0, (INT32)optimalContentHeight - (INT32)ScrollBarWidth);
+
+					if (sizeRanges[layoutIdx].min.y > 0)
+						optimalContentHeight = std::max((UINT32)sizeRanges[layoutIdx].min.y, optimalContentHeight);
+
+					layoutHeight = std::max(optimalContentHeight, (UINT32)visibleSize.y); // Never go below optimal size
 
-					contentSize = GUILayoutUtility::calcActualSize(layoutWidth, layoutHeight, mContentLayout, false);
+					contentSize = GUILayoutUtility::calcActualSize(layoutWidth, layoutHeight, mContentLayout, true);
 					hasHorzScrollbar = true;
 				}
 			}

+ 1 - 1
Dependencies.txt

@@ -44,7 +44,7 @@ BansheeD3D11RenderAPI & BansheeD3D9RenderAPI (both optional) rely on:
  - Microsoft DirectX SDK June 2010
   - http://www.microsoft.com/en-us/download/details.aspx?id=6812
   - After installing the SDK make sure DXSDK_DIR environment variable is set up pointing to the installation path
- - Windows SDK 
+ - Windows SDK (Only required if on Windows 8 or higher)
   - Needed for DirectX 11 debug layer
   - This also contains DirectX SDK so you don't need to install it separately.
 

+ 0 - 12
MBansheeEditor/DbgEditorWindow.cs

@@ -1,12 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace BansheeEditor
-{
-    class DbgEditorWindow : EditorWindow
-    {
-    }
-}

+ 0 - 34
MBansheeEditor/DbgGizmo.cs

@@ -1,34 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using BansheeEngine;
-
-namespace BansheeEditor
-{
-    class DbgGizmo
-    {
-        private static SpriteTexture iconTexture;
-
-        [DrawGizmo(DrawGizmoFlags.NotSelected | DrawGizmoFlags.Pickable)]
-        private static void DrawDbgComponentGizmo(DbgGizmoComponent target)
-        {
-            if (iconTexture == null)
-            {
-                Texture2D iconTex = ProjectLibrary.Load<Texture2D>("debugIcon.psd");
-                iconTexture = new SpriteTexture(iconTex);
-            }
-
-            Gizmos.DrawCube(target.SceneObject.Position, new Vector3(1, 1, 1));
-            Gizmos.DrawSphere(target.SceneObject.Position + 2 * Vector3.XAxis, 1.0f);
-            Gizmos.DrawWireCube(target.SceneObject.Position + 4 * Vector3.XAxis, new Vector3(1, 1, 1));
-            Gizmos.DrawWireSphere(target.SceneObject.Position + 6 * Vector3.XAxis, 1.0f);
-            Gizmos.DrawLine(target.SceneObject.Position + 7.5f * Vector3.XAxis,
-                target.SceneObject.Position + 8.5f * Vector3.XAxis);
-            Gizmos.DrawFrustum(target.SceneObject.Position + 10 * Vector3.XAxis, 1920.0f / 1080.0f, 90, 1.0f, 1000.0f);
-
-            Gizmos.DrawIcon(target.SceneObject.Position + new Vector3(0, 10, 0), iconTexture, false);
-        }
-    }
-}

+ 0 - 8
MBansheeEditor/DbgGizmoComponent.cs

@@ -1,8 +0,0 @@
-using BansheeEngine;
-
-namespace BansheeEditor
-{
-    public class DbgGizmoComponent : Component
-    {
-    }
-}

+ 0 - 41
MBansheeEditor/DebugCameraHandle.cs

@@ -1,41 +0,0 @@
-using System;
-using BansheeEngine;
-
-namespace BansheeEditor
-{
-    [CustomHandle(typeof(Component))]
-    public class DebugCameraHandle : Handle
-    {
-        private Component target;
-        private HandleSliderLine xAxis;
-
-        public DebugCameraHandle(Component target)
-        {
-            this.target = target;
-
-            xAxis = new HandleSliderLine(this, Vector3.XAxis, 5.0f);
-        }
-
-        protected override void PreInput()
-        {
-            xAxis.Position = target.SceneObject.Position;
-        }
-
-        protected override void PostInput()
-        {
-            //target.sceneObject.Position = xAxis.NewPosition;
-        }
-
-        protected override void Draw()
-        {
-            Vector3 end = target.SceneObject.Position + Vector3.XAxis * 5;
-
-            if (xAxis.State == HandleSlider.StateType.Active)
-                HandleDrawing.SetColor(Color.White);
-            else
-                HandleDrawing.SetColor(Color.Green);
-
-            HandleDrawing.DrawLine(target.SceneObject.Position, end);
-        }
-    }
-}

+ 0 - 31
MBansheeEditor/Debug_Component1.cs

@@ -1,31 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-
-namespace BansheeEngine
-{
-    [SerializeObject]
-    public class DebugData
-    {
-        public int val3;
-        public int val4;
-        public float fltVal;
-        public bool boolVal;
-        public string strVal;
-        public Color colVal;
-        public Vector2 vec2Val;
-        public Vector3 vec3Val;
-        public Vector4 vec4Val;
-        public Component cmp1;
-        public Texture2D tex1;
-    }
-
-    public class Debug_Component1 : Component
-    {
-        public int value1;
-        public int value2;
-        public int[] intArray = new int[1];
-        public DebugData data;
-    }
-}

+ 0 - 13
MBansheeEditor/Debug_Component2.cs

@@ -1,13 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-
-namespace BansheeEngine
-{
-    public class Debug_Component2 : Component
-    {
-        public int value4;
-        public int value55;
-    }
-}

+ 2 - 9
MBansheeEditor/Inspector/InspectorWindow.cs

@@ -54,7 +54,6 @@ namespace BansheeEditor
         private GUILayoutY sceneObjectLayout;
         private GUIPanel highlightPanel;
         private GUITexture scrollAreaHighlight;
-        private GUITexture titleBg;
 
         private SceneObject activeSO;
         private GUITextBox soNameInput;
@@ -177,8 +176,6 @@ namespace BansheeEditor
 
             dropBounds = inspectorScrollArea.Bounds;
             scrollAreaHighlight.Bounds = dropBounds;
-
-            titleBg.Bounds = GetTitleBounds();
         }
 
         /// <summary>
@@ -195,7 +192,7 @@ namespace BansheeEditor
             sceneObjectLayout.SetPosition(5, 5);
 
             GUIPanel sceneObjectBgPanel = sceneObjectPanel.AddPanel(1);
-            
+
             GUILayoutX nameLayout = sceneObjectLayout.AddLayoutX();
             GUILabel nameLbl = new GUILabel(new LocEdString("Name"), GUIOption.FixedWidth(50));
             soNameInput = new GUITextBox(false, GUIOption.FlexibleWidth(180));
@@ -272,7 +269,7 @@ namespace BansheeEditor
 
             inspectorLayout.AddSpace(5);
 
-            titleBg = new GUITexture(null, EditorStyles.InspectorTitleBg);
+            GUITexture titleBg = new GUITexture(null, EditorStyles.InspectorTitleBg);
             sceneObjectBgPanel.AddElement(titleBg);
         }
 
@@ -587,7 +584,6 @@ namespace BansheeEditor
             soScaleZ = null;
             dropBounds = new Rect2I();
             sceneObjectLayout = null;
-            titleBg = null;
 
             activeResource = null;
             currentType = InspectorType.None;
@@ -678,9 +674,6 @@ namespace BansheeEditor
 
             if (scrollAreaHighlight != null)
                 scrollAreaHighlight.Bounds = dropBounds;
-
-            if(titleBg != null)
-                titleBg.Bounds = GetTitleBounds();
         }
     }
 }

+ 0 - 6
MBansheeEditor/MBansheeEditor.csproj

@@ -43,14 +43,8 @@
     <Compile Include="BuildManager.cs" />
     <Compile Include="CodeEditor.cs" />
     <Compile Include="ColorPicker.cs" />
-    <Compile Include="DbgEditorWindow.cs" />
-    <Compile Include="DbgGizmo.cs" />
-    <Compile Include="DbgGizmoComponent.cs" />
     <Compile Include="DbgResource.cs" />
-    <Compile Include="DebugCameraHandle.cs" />
     <Compile Include="DebugWindow.cs" />
-    <Compile Include="Debug_Component1.cs" />
-    <Compile Include="Debug_Component2.cs" />
     <Compile Include="DialogBox.cs" />
     <Compile Include="DragDrop.cs" />
     <Compile Include="DropDownWindow.cs" />