Browse Source

Fixed project window so it doesn't cause horizontal scroll to show up
Fixed project window so element bounds are valid

Marko Pintera 10 years ago
parent
commit
7458bc642f

+ 6 - 1
BansheeEngine/Include/BsGUIScrollArea.h

@@ -154,6 +154,12 @@ namespace BansheeEngine
 		 *			(i.e. only the portion that contains the contents).
 		 *			(i.e. only the portion that contains the contents).
 		 */
 		 */
 		Rect2I getContentBounds();
 		Rect2I getContentBounds();
+
+		/**
+		 * @brief	Number of pixels the scroll bar will occupy when active. This is width
+		 *			for vertical scrollbar, and height for horizontal scrollbar.
+		 */
+		static const UINT32 ScrollBarWidth;
 	protected:
 	protected:
 		~GUIScrollArea();
 		~GUIScrollArea();
 
 
@@ -227,7 +233,6 @@ namespace BansheeEngine
 		Vector2I mVisibleSize;
 		Vector2I mVisibleSize;
 		Vector2I mContentSize;
 		Vector2I mContentSize;
 
 
-		static const UINT32 ScrollBarWidth;
 		static const UINT32 MinHandleSize;
 		static const UINT32 MinHandleSize;
 		static const UINT32 WheelScrollAmount;
 		static const UINT32 WheelScrollAmount;
 	};
 	};

+ 3 - 5
BansheeEngine/Source/BsGUIPanel.cpp

@@ -30,7 +30,7 @@ namespace BansheeEngine
 		{
 		{
 			LayoutSizeRange sizeRange = child->_calculateLayoutSizeRange();
 			LayoutSizeRange sizeRange = child->_calculateLayoutSizeRange();
 
 
-			if (child->_getType() == GUIElementBase::Type::FixedSpace)
+			if (child->_getType() == GUIElementBase::Type::FixedSpace || child->_getType() == GUIElementBase::Type::FlexibleSpace)
 				sizeRange.optimal.x = sizeRange.optimal.y = 0;
 				sizeRange.optimal.x = sizeRange.optimal.y = 0;
 
 
 			UINT32 paddingX = child->_getPadding().left + child->_getPadding().right;
 			UINT32 paddingX = child->_getPadding().left + child->_getPadding().right;
@@ -49,11 +49,9 @@ namespace BansheeEngine
 
 
 	LayoutSizeRange GUIPanel::_getElementSizeRange(const GUIElementBase* element) const
 	LayoutSizeRange GUIPanel::_getElementSizeRange(const GUIElementBase* element) const
 	{
 	{
-		if (element->_getType() == GUIElementBase::Type::FixedSpace)
+		if (element->_getType() == GUIElementBase::Type::FixedSpace || element->_getType() == GUIElementBase::Type::FlexibleSpace)
 		{
 		{
-			const GUIFixedSpace* fixedSpace = static_cast<const GUIFixedSpace*>(element);
-
-			LayoutSizeRange sizeRange = fixedSpace->_calculateLayoutSizeRange();
+			LayoutSizeRange sizeRange = element->_calculateLayoutSizeRange();
 			sizeRange.optimal.x = 0;
 			sizeRange.optimal.x = 0;
 			sizeRange.optimal.y = 0;
 			sizeRange.optimal.y = 0;
 
 

+ 12 - 9
MBansheeEditor/ProjectWindow.cs

@@ -680,6 +680,7 @@ namespace BansheeEditor
             ContentInfo contentInfo = new ContentInfo(this, viewType);
             ContentInfo contentInfo = new ContentInfo(this, viewType);
 
 
             Rect2I scrollBounds = contentScrollArea.Bounds;
             Rect2I scrollBounds = contentScrollArea.Bounds;
+            int availableWidth = scrollBounds.width;
             LibraryEntry[] childEntries = entry.Children;
             LibraryEntry[] childEntries = entry.Children;
 
 
             if (childEntries.Length == 0)
             if (childEntries.Length == 0)
@@ -713,7 +714,16 @@ namespace BansheeEditor
                 rowLayout.AddFlexibleSpace();
                 rowLayout.AddFlexibleSpace();
 
 
                 int elemSize = tileSize + GRID_ENTRY_SPACING;
                 int elemSize = tileSize + GRID_ENTRY_SPACING;
-                int elemsPerRow = (scrollBounds.width - GRID_ENTRY_SPACING*2)/elemSize;
+                int elemsPerRow = (availableWidth - GRID_ENTRY_SPACING * 2) / elemSize;
+                int numRows = MathEx.CeilToInt(childEntries.Length/(float) elemsPerRow);
+                int neededHeight = numRows*(elemSize);
+
+                bool requiresScrollbar = neededHeight > scrollBounds.height;
+                if (requiresScrollbar)
+                {
+                    availableWidth -= contentScrollArea.ScrollBarWidth;
+                    elemsPerRow = (availableWidth - GRID_ENTRY_SPACING * 2) / elemSize;
+                }
 
 
                 int elemsInRow = 0;
                 int elemsInRow = 0;
 
 
@@ -763,11 +773,8 @@ namespace BansheeEditor
 
 
             Rect2I contentBounds = contentInfo.main.Bounds;
             Rect2I contentBounds = contentInfo.main.Bounds;
             Rect2I minimalBounds = GetScrollAreaBounds();
             Rect2I minimalBounds = GetScrollAreaBounds();
-            contentBounds.width = Math.Max(contentBounds.width, minimalBounds.width);
             contentBounds.height = Math.Max(contentBounds.height, minimalBounds.height);
             contentBounds.height = Math.Max(contentBounds.height, minimalBounds.height);
 
 
-            Debug.Log(contentBounds + " - " + minimalBounds);
-
             GUIButton catchAll = new GUIButton("", EditorStyles.Blank);
             GUIButton catchAll = new GUIButton("", EditorStyles.Blank);
             catchAll.Bounds = contentBounds;
             catchAll.Bounds = contentBounds;
             catchAll.OnClick += OnCatchAllClicked;
             catchAll.OnClick += OnCatchAllClicked;
@@ -779,11 +786,6 @@ namespace BansheeEditor
 
 
         private void OnContentsFocusChanged(bool focus)
         private void OnContentsFocusChanged(bool focus)
         {
         {
-            if(focus)
-                Debug.Log("GOT FOCUS");
-            else
-                Debug.Log("LOST FOCUS");
-
             hasContentFocus = focus;
             hasContentFocus = focus;
         }
         }
 
 
@@ -879,6 +881,7 @@ namespace BansheeEditor
             bounds.y += searchBarBounds.height;
             bounds.y += searchBarBounds.height;
             bounds.height -= searchBarBounds.height;
             bounds.height -= searchBarBounds.height;
 
 
+
             return bounds;
             return bounds;
         }
         }
 
 

+ 8 - 1
MBansheeEngine/GUI/GUIScrollArea.cs

@@ -25,7 +25,6 @@ namespace BansheeEngine
             set { Internal_SetHorzScroll(mCachedPtr, value); }
             set { Internal_SetHorzScroll(mCachedPtr, value); }
         }
         }
 
 
-
         public float VerticalScroll
         public float VerticalScroll
         {
         {
             get { return Internal_GetVertScroll(mCachedPtr); }
             get { return Internal_GetVertScroll(mCachedPtr); }
@@ -37,6 +36,11 @@ namespace BansheeEngine
             get { return Internal_GetContentBounds(mCachedPtr); }
             get { return Internal_GetContentBounds(mCachedPtr); }
         }
         }
 
 
+        public int ScrollBarWidth
+        {
+            get { return Internal_GetScrollBarWidth(mCachedPtr); }
+        }
+
         public GUIScrollArea(ScrollBarType vertBarType, ScrollBarType horzBarType, string scrollBarStyle,
         public GUIScrollArea(ScrollBarType vertBarType, ScrollBarType horzBarType, string scrollBarStyle,
             string scrollAreaStyle, params GUIOption[] options)
             string scrollAreaStyle, params GUIOption[] options)
         {
         {
@@ -99,5 +103,8 @@ namespace BansheeEngine
 
 
         [MethodImpl(MethodImplOptions.InternalCall)]
         [MethodImpl(MethodImplOptions.InternalCall)]
         private static extern void Internal_SetVertScroll(IntPtr nativeInstance, float value);
         private static extern void Internal_SetVertScroll(IntPtr nativeInstance, float value);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern int Internal_GetScrollBarWidth(IntPtr nativeInstance);
     }
     }
 }
 }

+ 1 - 0
SBansheeEngine/Include/BsScriptGUIScrollArea.h

@@ -19,6 +19,7 @@ namespace BansheeEngine
 		static void internal_setHorzScroll(ScriptGUIScrollArea* nativeInstance, float value);
 		static void internal_setHorzScroll(ScriptGUIScrollArea* nativeInstance, float value);
 		static float internal_getVertScroll(ScriptGUIScrollArea* nativeInstance);
 		static float internal_getVertScroll(ScriptGUIScrollArea* nativeInstance);
 		static void internal_setVertScroll(ScriptGUIScrollArea* nativeInstance, float value);
 		static void internal_setVertScroll(ScriptGUIScrollArea* nativeInstance, float value);
+		static int internal_getScrollBarWidth(ScriptGUIScrollArea* nativeInstance);
 
 
 		ScriptGUIScrollArea(MonoObject* instance, GUIScrollArea* scrollArea);
 		ScriptGUIScrollArea(MonoObject* instance, GUIScrollArea* scrollArea);
 	};
 	};

+ 6 - 0
SBansheeEngine/Source/BsScriptGUIScrollArea.cpp

@@ -30,6 +30,7 @@ namespace BansheeEngine
 		metaData.scriptClass->addInternalCall("Internal_SetHorzScroll", &ScriptGUIScrollArea::internal_setHorzScroll);
 		metaData.scriptClass->addInternalCall("Internal_SetHorzScroll", &ScriptGUIScrollArea::internal_setHorzScroll);
 		metaData.scriptClass->addInternalCall("Internal_GetVertScroll", &ScriptGUIScrollArea::internal_getVertScroll);
 		metaData.scriptClass->addInternalCall("Internal_GetVertScroll", &ScriptGUIScrollArea::internal_getVertScroll);
 		metaData.scriptClass->addInternalCall("Internal_SetVertScroll", &ScriptGUIScrollArea::internal_setVertScroll);
 		metaData.scriptClass->addInternalCall("Internal_SetVertScroll", &ScriptGUIScrollArea::internal_setVertScroll);
+		metaData.scriptClass->addInternalCall("Internal_GetScrollBarWidth", &ScriptGUIScrollArea::internal_getScrollBarWidth);
 	}
 	}
 
 
 	void ScriptGUIScrollArea::internal_createInstance(MonoObject* instance, ScrollBarType vertBarType, ScrollBarType horzBarType, 
 	void ScriptGUIScrollArea::internal_createInstance(MonoObject* instance, ScrollBarType vertBarType, ScrollBarType horzBarType, 
@@ -76,4 +77,9 @@ namespace BansheeEngine
 		GUIScrollArea* guiScrollArea = static_cast<GUIScrollArea*>(nativeInstance->getGUIElement());
 		GUIScrollArea* guiScrollArea = static_cast<GUIScrollArea*>(nativeInstance->getGUIElement());
 		guiScrollArea->scrollToVertical(value);
 		guiScrollArea->scrollToVertical(value);
 	}
 	}
+
+	int ScriptGUIScrollArea::internal_getScrollBarWidth(ScriptGUIScrollArea* nativeInstance)
+	{
+		return GUIScrollArea::ScrollBarWidth;
+	}
 }
 }

+ 0 - 3
TODO.txt

@@ -29,9 +29,6 @@ TODO - When importing/reimporting stuff there should be a progress bar
 TODO - Might need to handle overwritting better when importing/moving 
 TODO - Might need to handle overwritting better when importing/moving 
 TODO - When there's room between the elements, labels should probably make use of it (right now they tend to cut off a lot of text too often)
 TODO - When there's room between the elements, labels should probably make use of it (right now they tend to cut off a lot of text too often)
 
 
-TODO - GUI element selection outline seems to be slightly wrong now (it was fine before)
-TODO - Horizontal scroll bar seems to show up in GUI
-
 Simple tasks:
 Simple tasks:
  - Hook up scene view drag and drop instantiation
  - Hook up scene view drag and drop instantiation
  - Hook up search
  - Hook up search