Browse Source

Added dynamic sized handle for scroll bar

Marko Pintera 12 years ago
parent
commit
6f2b30ed4e

+ 1 - 0
BansheeEngine/Include/BsGUIScrollArea.h

@@ -59,6 +59,7 @@ namespace BansheeEngine
 		CM::UINT32 mContentWidth, mContentHeight;
 		CM::UINT32 mContentWidth, mContentHeight;
 
 
 		static const CM::UINT32 ScrollBarWidth;
 		static const CM::UINT32 ScrollBarWidth;
+		static const CM::UINT32 MinHandleSize;
 
 
 		void vertScrollUpdate(float pct);
 		void vertScrollUpdate(float pct);
 		void horzScrollUpdate(float pct);
 		void horzScrollUpdate(float pct);

+ 2 - 2
BansheeEngine/Include/BsGUIScrollBarHandle.h

@@ -19,6 +19,8 @@ namespace BansheeEngine
 		void setHandleSize(CM::UINT32 size);
 		void setHandleSize(CM::UINT32 size);
 		void setHandlePos(float pct);
 		void setHandlePos(float pct);
 
 
+		CM::UINT32 getMaxSize() const;
+
 		boost::signal<void(float newPosition)> handleMoved;
 		boost::signal<void(float newPosition)> handleMoved;
 	protected:
 	protected:
 		~GUIScrollBarHandle();
 		~GUIScrollBarHandle();
@@ -51,8 +53,6 @@ namespace BansheeEngine
 
 
 		virtual CM::UINT32 _getOptimalWidth() const;
 		virtual CM::UINT32 _getOptimalWidth() const;
 		virtual CM::UINT32 _getOptimalHeight() const;
 		virtual CM::UINT32 _getOptimalHeight() const;
-
-		CM::UINT32 getMaxSize() const;
 	private:
 	private:
 		ImageSprite* mImageSprite;
 		ImageSprite* mImageSprite;
 		CM::UINT32 mHandleSize;
 		CM::UINT32 mHandleSize;

+ 11 - 2
BansheeEngine/Source/BsGUIScrollArea.cpp

@@ -13,7 +13,8 @@ using namespace CamelotFramework;
 
 
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
-	const UINT32 GUIScrollArea::ScrollBarWidth = 6;
+	const UINT32 GUIScrollArea::ScrollBarWidth = 8;
+	const UINT32 GUIScrollArea::MinHandleSize = 4;
 
 
 	GUIScrollArea::GUIScrollArea(GUIWidget& parent, const GUIElementStyle* style, const GUILayoutOptions& layoutOptions)
 	GUIScrollArea::GUIScrollArea(GUIWidget& parent, const GUIElementStyle* style, const GUILayoutOptions& layoutOptions)
 		:GUIElement(parent, style, layoutOptions), mVertScroll(nullptr), mHorzScroll(nullptr), mVertOffset(0), mHorzOffset(0),
 		:GUIElement(parent, style, layoutOptions), mVertScroll(nullptr), mHorzScroll(nullptr), mVertOffset(0), mHorzOffset(0),
@@ -97,7 +98,15 @@ namespace BansheeEngine
 			Rect scrollBarLayoutClipRect(clipRect.x + contentWidth, clipRect.y, clippedScrollbarWidth, clipRect.height);
 			Rect scrollBarLayoutClipRect(clipRect.x + contentWidth, clipRect.y, clippedScrollbarWidth, clipRect.height);
 			mVertScroll->_updateLayout(offset.x, offset.y, ScrollBarWidth, height, scrollBarLayoutClipRect, widgetDepth, areaDepth);
 			mVertScroll->_updateLayout(offset.x, offset.y, ScrollBarWidth, height, scrollBarLayoutClipRect, widgetDepth, areaDepth);
 
 
-			// TODO - Update scroll handle size and update position to match
+			// Set new handle size and update position to match the new size
+			UINT32 newHandleSize = (UINT32)Math::FloorToInt(mVertScroll->getMaxHandleSize() * (mHeight / (float)contentHeight));
+			newHandleSize = std::max(newHandleSize, MinHandleSize);
+
+			UINT32 scrollableHeight = (UINT32)std::max(0, INT32(contentHeight) - INT32(mHeight));
+			float newScrollPct = mVertOffset / (float)scrollableHeight;
+
+			mVertScroll->setHandleSize(newHandleSize);
+			mVertScroll->setScrollPos(newScrollPct);
 		}
 		}
 		else
 		else
 		{
 		{