Browse Source

Making sure elements dont lose focus when I scroll the scroll area

Marko Pintera 12 years ago
parent
commit
f4d94f0c09

+ 2 - 1
BansheeEngine/Include/BsGUIElement.h

@@ -11,7 +11,7 @@ namespace BansheeEngine
 	class BS_EXPORT GUIElement : public GUIElementBase
 	class BS_EXPORT GUIElement : public GUIElementBase
 	{
 	{
 	public:
 	public:
-		GUIElement(GUIWidget& parent, const GUIElementStyle* style, const GUILayoutOptions& layoutOptions, bool acceptsKeyboardFocus = false);
+		GUIElement(GUIWidget& parent, const GUIElementStyle* style, const GUILayoutOptions& layoutOptions, bool acceptsKeyboardFocus = true);
 		virtual ~GUIElement();
 		virtual ~GUIElement();
 
 
 		/**
 		/**
@@ -90,6 +90,7 @@ namespace BansheeEngine
 		void _setWidth(CM::UINT32 width);
 		void _setWidth(CM::UINT32 width);
 		void _setHeight(CM::UINT32 height);
 		void _setHeight(CM::UINT32 height);
 		void _setClipRect(const CM::Rect& clipRect);
 		void _setClipRect(const CM::Rect& clipRect);
+		void _setAcceptsKeyboardFocus(bool acceptsKeyboardFocus) { mAcceptsKeyboardFocus = acceptsKeyboardFocus; }
 		virtual void _setFocus(bool focus) {}
 		virtual void _setFocus(bool focus) {}
 		
 		
 		CM::UINT32 _getWidth() const { return mWidth; }
 		CM::UINT32 _getWidth() const { return mWidth; }

+ 1 - 1
BansheeEngine/Source/BsGUIManager.cpp

@@ -552,7 +552,7 @@ namespace BansheeEngine
 				mActiveMouseButton = guiButton;
 				mActiveMouseButton = guiButton;
 			}
 			}
 
 
-			if(mMouseOverElement != nullptr)
+			if(mMouseOverElement != nullptr && mMouseOverElement->_acceptsKeyboardFocus())
 			{
 			{
 				if(mKeyboardFocusElement != nullptr && mMouseOverElement != mKeyboardFocusElement)
 				if(mKeyboardFocusElement != nullptr && mMouseOverElement != mKeyboardFocusElement)
 					mKeyboardFocusElement->_setFocus(false);
 					mKeyboardFocusElement->_setFocus(false);

+ 3 - 1
BansheeEngine/Source/BsGUIScrollArea.cpp

@@ -19,7 +19,7 @@ namespace BansheeEngine
 	const UINT32 GUIScrollArea::WheelScrollAmount = 50;
 	const UINT32 GUIScrollArea::WheelScrollAmount = 50;
 
 
 	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, false), mVertScroll(nullptr), mHorzScroll(nullptr), mVertOffset(0), mHorzOffset(0),
 		mContentWidth(0), mContentHeight(0), mClippedContentWidth(0), mClippedContentHeight(0)
 		mContentWidth(0), mContentHeight(0), mClippedContentWidth(0), mClippedContentHeight(0)
 	{
 	{
 		mContentLayout = &addLayoutYInternal(this);
 		mContentLayout = &addLayoutYInternal(this);
@@ -112,6 +112,7 @@ namespace BansheeEngine
 			{
 			{
 				mVertScroll = GUIScrollBarVert::create(_getParentWidget());
 				mVertScroll = GUIScrollBarVert::create(_getParentWidget());
 				mVertScroll->onScrollPositionChanged.connect(boost::bind(&GUIScrollArea::vertScrollUpdate, this, _1));
 				mVertScroll->onScrollPositionChanged.connect(boost::bind(&GUIScrollArea::vertScrollUpdate, this, _1));
+				mVertScroll->_setAcceptsKeyboardFocus(false);
 			}
 			}
 
 
 			Int2 offset(x + mClippedContentWidth, y);
 			Int2 offset(x + mClippedContentWidth, y);
@@ -159,6 +160,7 @@ namespace BansheeEngine
 			{
 			{
 				mHorzScroll = GUIScrollBarHorz::create(_getParentWidget());
 				mHorzScroll = GUIScrollBarHorz::create(_getParentWidget());
 				mHorzScroll->onScrollPositionChanged.connect(boost::bind(&GUIScrollArea::horzScrollUpdate, this, _1));
 				mHorzScroll->onScrollPositionChanged.connect(boost::bind(&GUIScrollArea::horzScrollUpdate, this, _1));
+				mHorzScroll->_setAcceptsKeyboardFocus(false);
 			}
 			}
 
 
 			Int2 offset(x, y + mClippedContentHeight);
 			Int2 offset(x, y + mClippedContentHeight);

+ 4 - 0
BansheeEngine/Source/BsGUIScrollBar.cpp

@@ -52,6 +52,10 @@ namespace BansheeEngine
 
 
 		mUpBtn->onClick.connect(boost::bind(&GUIScrollBar::upButtonClicked, this));
 		mUpBtn->onClick.connect(boost::bind(&GUIScrollBar::upButtonClicked, this));
 		mDownBtn->onClick.connect(boost::bind(&GUIScrollBar::downButtonClicked, this));
 		mDownBtn->onClick.connect(boost::bind(&GUIScrollBar::downButtonClicked, this));
+
+		mHandleBtn->_setAcceptsKeyboardFocus(false);
+		mUpBtn->_setAcceptsKeyboardFocus(false);
+		mDownBtn->_setAcceptsKeyboardFocus(false);
 	}
 	}
 
 
 	GUIScrollBar::~GUIScrollBar()
 	GUIScrollBar::~GUIScrollBar()

+ 0 - 2
TODO.txt

@@ -36,8 +36,6 @@ IMMEDIATE:
 - Scrolling the window shouldn't remove text selection
 - Scrolling the window shouldn't remove text selection
  - In general focus shouldn't be lost at all
  - In general focus shouldn't be lost at all
 - Hover colors of the scroll bar are wrong
 - Hover colors of the scroll bar are wrong
-- Ability to scroll by just mousing over and moving the scroll wheel
- - ScrollArea has no way of receiving mouse events
 
 
 TextBox needed elements:
 TextBox needed elements:
  - Key-repeat? Pressing left/right/up/down arrows doesn't repeat the keys (also delete/backspace)
  - Key-repeat? Pressing left/right/up/down arrows doesn't repeat the keys (also delete/backspace)