Browse Source

Better GUILayoutOptions handling

Marko Pintera 12 years ago
parent
commit
a839103701

+ 4 - 4
BansheeEngine/Include/BsGUIElement.h

@@ -10,7 +10,7 @@ namespace BansheeEngine
 	class BS_EXPORT GUIElement
 	{
 	public:
-		GUIElement(GUIWidget& parent, const GUI_LAYOUT_OPTIONS& layoutOptions);
+		GUIElement(GUIWidget& parent, const GUILayoutOptions& layoutOptions);
 
 		/**
 		 * @brief	Returns the number of separate render elements in the GUI element.
@@ -99,7 +99,7 @@ namespace BansheeEngine
 		GUIWidget& _getParentWidget() const { return mParent; }
 		bool _isDirty() const { return mIsDirty; }
 
-		const GUI_LAYOUT_OPTIONS& _getLayoutOptions() const { return mLayoutOptions; }
+		const GUILayoutOptions& _getLayoutOptions() const { return mLayoutOptions; }
 
 		static void _destroyInternal(GUIElement* element);
 
@@ -113,14 +113,14 @@ namespace BansheeEngine
 
 		virtual void updateRenderElementsInternal() = 0;
 
-		void setLayoutOptions(const GUI_LAYOUT_OPTIONS& layoutOptions);
+		void setLayoutOptions(const GUILayoutOptions& layoutOptions);
 		
 		void markAsClean() { mIsDirty = false; }
 		void markAsDirty();
 
 		GUIWidget& mParent;
 		GUILayout* mParentLayout;
-		GUI_LAYOUT_OPTIONS mLayoutOptions;
+		GUILayoutOptions mLayoutOptions;
 		CM::Rect mBounds;
 
 		bool mIsDirty;

+ 4 - 4
BansheeEngine/Include/BsGUILabel.h

@@ -12,11 +12,11 @@ namespace BansheeEngine
 		static const CM::String& getGUITypeName();
 
 		static GUILabel* create(GUIWidget& parent, const CM::String& text, bool wordWrap = false);
-		static GUILabel* create(GUIWidget& parent, const CM::String& text, const GUI_LAYOUT_OPTIONS& layoutOptions, bool wordWrap = false);
+		static GUILabel* create(GUIWidget& parent, const CM::String& text, const GUILayoutOptions& layoutOptions, bool wordWrap = false);
 
 		static GUILabel* create(GUIWidget& parent, const CM::String& text, TextHorzAlign horzAlign, 
 			TextVertAlign vertAlign = TVA_Top, bool wordWrap = false);
-		static GUILabel* create(GUIWidget& parent, const CM::String& text, const GUI_LAYOUT_OPTIONS& layoutOptions,
+		static GUILabel* create(GUIWidget& parent, const CM::String& text, const GUILayoutOptions& layoutOptions,
 			TextHorzAlign horzAlign, TextVertAlign vertAlign = TVA_Top, bool wordWrap = false);
 
 		void setText(const CM::String& text);
@@ -53,7 +53,7 @@ namespace BansheeEngine
 		virtual UINT32 _getOptimalWidth() const;
 		virtual UINT32 _getOptimalHeight() const;
 
-		static const GUI_LAYOUT_OPTIONS& getDefaultLayoutOptions();
+		static const GUILayoutOptions& getDefaultLayoutOptions();
 	private:
 		TextSprite* mTextSprite;
 		CM::String mText;
@@ -63,6 +63,6 @@ namespace BansheeEngine
 		TEXT_SPRITE_DESC mDesc;
 		
 		GUILabel(GUIWidget& parent, const CM::String& text, bool wordWrap, TextHorzAlign horzAlign, TextVertAlign vertAlign, 
-			const GUI_LAYOUT_OPTIONS& layoutOptions);
+			const GUILayoutOptions& layoutOptions);
 	};
 }

+ 71 - 5
BansheeEngine/Include/BsGUILayoutOptions.h

@@ -4,20 +4,86 @@
 
 namespace BansheeEngine
 {
-	struct GUI_LAYOUT_OPTIONS
+	/**
+	 * @brief	Options that control how an element is positioned and sized in a GUI layout.
+	 */
+	struct GUILayoutOptions
 	{
-		GUI_LAYOUT_OPTIONS()
+		GUILayoutOptions()
 			:width(0), height(0), minWidth(0), maxWidth(0),
 			minHeight(0), maxHeight(0), fixedWidth(false), fixedHeight(false)
 		{
 
 		}
 
-		GUI_LAYOUT_OPTIONS(UINT32 _width, UINT32 _height)
-			:width(_width), height(_height), minWidth(0), maxWidth(0),
-			minHeight(0), maxHeight(0), fixedWidth(true), fixedHeight(true)
+		/**
+		 * @brief	Element is fixed to the specified width/height and will not resize.
+		 * 			If elements doesn't fully fit in the layout it will be clipped.
+		 */
+		static GUILayoutOptions fixed(UINT32 _width, UINT32 _height)
 		{
+			GUILayoutOptions layoutOptions;
+			layoutOptions.width = _width;
+			layoutOptions.height = _height;
+			layoutOptions.fixedWidth = true;
+			layoutOptions.fixedHeight = true;
 
+			return layoutOptions;
+		}
+
+		/**
+		 * @brief	Element will resize to fit the layout in both directions.
+		 * 			Optionally you may supply min and max constraints for both directions. 
+		 * 			
+		 *			If constraints are zero they will not be used.
+		 */
+		static GUILayoutOptions expandableXY(UINT32 _minWidth = 0, UINT32 _minHeight = 0, UINT32 _maxWidth = 0, UINT32 _maxHeight = 0)
+		{
+			GUILayoutOptions layoutOptions;
+			layoutOptions.minWidth = _minWidth;
+			layoutOptions.maxWidth = _maxWidth;
+			layoutOptions.minHeight = _minHeight;
+			layoutOptions.maxHeight = _maxHeight;
+			layoutOptions.fixedWidth = false;
+			layoutOptions.fixedHeight = false;
+
+			return layoutOptions;
+		}
+
+		/**
+		 * @brief	Element will resize to fit the layout in the X direction, while it will be fixed in the Y direction.
+		 * 			Optionally you may supply min and max constraints for width. 
+		 * 			
+		 *			If constraints are zero they will not be used.
+		 */
+		static GUILayoutOptions expandableX(UINT32 _height, UINT32 _minWidth = 0, UINT32 _maxWidth = 0)
+		{
+			GUILayoutOptions layoutOptions;
+			layoutOptions.height = _height;
+			layoutOptions.minWidth = _minWidth;
+			layoutOptions.maxWidth = _maxWidth;
+			layoutOptions.fixedWidth = false;
+			layoutOptions.fixedHeight = true;
+
+			return layoutOptions;
+		}
+
+		/**
+		 * @brief	Element will resize to fit the layout in the Y direction, while it will be fixed in the X direction.
+		 * 			Optionally you may supply min and max constraints for height. 
+		 * 			
+		 *			If constraints are zero they will not be used.
+		 */
+		static GUILayoutOptions expandableY(UINT32 _width, UINT32 _minHeight = 0, UINT32 _maxHeight = 0)
+		{
+			GUILayoutOptions layoutOptions;
+			layoutOptions.width = _width;
+			layoutOptions.minHeight = _minHeight;
+			layoutOptions.maxHeight = _maxHeight;
+			layoutOptions.fixedWidth = true;
+			layoutOptions.fixedHeight = false;
+
+			return layoutOptions;
 		}
 
 		UINT32 width, height;

+ 3 - 3
BansheeEngine/Include/BsGUIWindowFrame.h

@@ -12,7 +12,7 @@ namespace BansheeEngine
 		static const CM::String& getGUITypeName();
 
 		static GUIWindowFrame* create(GUIWidget& parent);
-		static GUIWindowFrame* create(GUIWidget& parent, const GUI_LAYOUT_OPTIONS& layoutOptions);
+		static GUIWindowFrame* create(GUIWidget& parent, const GUILayoutOptions& layoutOptions);
 	protected:
 		~GUIWindowFrame();
 
@@ -45,11 +45,11 @@ namespace BansheeEngine
 		virtual UINT32 _getOptimalWidth() const;
 		virtual UINT32 _getOptimalHeight() const;
 
-		static const GUI_LAYOUT_OPTIONS& getDefaultLayoutOptions();
+		static const GUILayoutOptions& getDefaultLayoutOptions();
 	private:
 		ImageSprite* mImageSprite;
 		IMAGE_SPRITE_DESC mDesc;
 
-		GUIWindowFrame(GUIWidget& parent, const GUI_LAYOUT_OPTIONS& layoutOptions);
+		GUIWindowFrame(GUIWidget& parent, const GUILayoutOptions& layoutOptions);
 	};
 }

+ 1 - 1
BansheeEngine/Include/BsPrerequisites.h

@@ -55,7 +55,7 @@ namespace BansheeEngine
 	class GUILayoutY;
 	class GUIFixedSpace;
 	class GUIFlexibleSpace;
-	struct GUI_LAYOUT_OPTIONS;
+	struct GUILayoutOptions;
 
 	// 2D
 	class TextSprite;

+ 2 - 2
BansheeEngine/Source/BsGUIElement.cpp

@@ -8,7 +8,7 @@ using namespace CamelotFramework;
 
 namespace BansheeEngine
 {
-	GUIElement::GUIElement(GUIWidget& parent, const GUI_LAYOUT_OPTIONS& layoutOptions)
+	GUIElement::GUIElement(GUIWidget& parent, const GUILayoutOptions& layoutOptions)
 		:mParent(parent), mIsDirty(true), mParentLayout(nullptr), mLayoutOptions(layoutOptions), mWidth(0), mHeight(0), mDepth(0)
 	{
 		mParent.registerElement(this);
@@ -26,7 +26,7 @@ namespace BansheeEngine
 		markAsClean();
 	}
 
-	void GUIElement::setLayoutOptions(const GUI_LAYOUT_OPTIONS& layoutOptions) 
+	void GUIElement::setLayoutOptions(const GUILayoutOptions& layoutOptions) 
 	{
 		if(layoutOptions.maxWidth < layoutOptions.minWidth)
 		{

+ 5 - 5
BansheeEngine/Source/BsGUILabel.cpp

@@ -11,7 +11,7 @@ using namespace CamelotFramework;
 namespace BansheeEngine
 {
 	GUILabel::GUILabel(GUIWidget& parent, const String& text, bool wordWrap, TextHorzAlign horzAlign, 
-		TextVertAlign vertAlign, const GUI_LAYOUT_OPTIONS& layoutOptions)
+		TextVertAlign vertAlign, const GUILayoutOptions& layoutOptions)
 		:GUIElement(parent, layoutOptions), mText(text), mWordWrap(wordWrap),
 		mHorzAlign(horzAlign), mVertAlign(vertAlign)
 	{
@@ -103,9 +103,9 @@ namespace BansheeEngine
 		mTextSprite->fillBuffer(vertices, uv, indices, startingQuad, maxNumQuads, vertexStride, indexStride, renderElementIdx);
 	}
 
-	const GUI_LAYOUT_OPTIONS& GUILabel::getDefaultLayoutOptions()
+	const GUILayoutOptions& GUILabel::getDefaultLayoutOptions()
 	{
-		static GUI_LAYOUT_OPTIONS layoutOptions;
+		static GUILayoutOptions layoutOptions;
 		static bool layoutOptionsInitialized = false;
 
 		if(!layoutOptionsInitialized)
@@ -136,7 +136,7 @@ namespace BansheeEngine
 		return CM_NEW(GUILabel, PoolAlloc) GUILabel(parent, text, wordWrap, THA_Left, TVA_Top, getDefaultLayoutOptions());
 	}
 
-	GUILabel* GUILabel::create(GUIWidget& parent, const String& text, const GUI_LAYOUT_OPTIONS& layoutOptions, bool wordWrap)
+	GUILabel* GUILabel::create(GUIWidget& parent, const String& text, const GUILayoutOptions& layoutOptions, bool wordWrap)
 	{
 		return CM_NEW(GUILabel, PoolAlloc) GUILabel(parent, text, wordWrap, THA_Left, TVA_Top, layoutOptions);
 	}
@@ -146,7 +146,7 @@ namespace BansheeEngine
 		return CM_NEW(GUILabel, PoolAlloc) GUILabel(parent, text, wordWrap, horzAlign, vertAlign, getDefaultLayoutOptions());
 	}
 
-	GUILabel* GUILabel::create(GUIWidget& parent, const String& text, const GUI_LAYOUT_OPTIONS& layoutOptions, TextHorzAlign horzAlign, TextVertAlign vertAlign, bool wordWrap)
+	GUILabel* GUILabel::create(GUIWidget& parent, const String& text, const GUILayoutOptions& layoutOptions, TextHorzAlign horzAlign, TextVertAlign vertAlign, bool wordWrap)
 	{
 		return CM_NEW(GUILabel, PoolAlloc) GUILabel(parent, text, wordWrap, horzAlign, vertAlign, layoutOptions);
 	}

+ 4 - 4
BansheeEngine/Source/BsGUILayoutX.cpp

@@ -25,7 +25,7 @@ namespace BansheeEngine
 			}
 			else if(child.isElement())
 			{
-				const GUI_LAYOUT_OPTIONS& layoutOptions = child.element->_getLayoutOptions();
+				const GUILayoutOptions& layoutOptions = child.element->_getLayoutOptions();
 
 				if(layoutOptions.fixedWidth)
 					minimalTotalSize += layoutOptions.width;
@@ -57,7 +57,7 @@ namespace BansheeEngine
 		{
 			if(child.isElement())
 			{
-				const GUI_LAYOUT_OPTIONS& layoutOptions = child.element->_getLayoutOptions();
+				const GUILayoutOptions& layoutOptions = child.element->_getLayoutOptions();
 
 				if(layoutOptions.fixedWidth)
 				{
@@ -91,7 +91,7 @@ namespace BansheeEngine
 		{
 			if(child.isElement())
 			{
-				const GUI_LAYOUT_OPTIONS& layoutOptions = child.element->_getLayoutOptions();
+				const GUILayoutOptions& layoutOptions = child.element->_getLayoutOptions();
 
 				UINT32 elementWidth = 0;
 
@@ -138,7 +138,7 @@ namespace BansheeEngine
 		{
 			if(child.isElement())
 			{
-				const GUI_LAYOUT_OPTIONS& layoutOptions = child.element->_getLayoutOptions();
+				const GUILayoutOptions& layoutOptions = child.element->_getLayoutOptions();
 
 				if(!layoutOptions.fixedWidth && layoutOptions.maxWidth == 0 && layoutOptions.minWidth == 0)
 				{

+ 4 - 4
BansheeEngine/Source/BsGUIWindowFrame.cpp

@@ -16,7 +16,7 @@ namespace BansheeEngine
 		return name;
 	}
 
-	GUIWindowFrame::GUIWindowFrame(GUIWidget& parent, const GUI_LAYOUT_OPTIONS& layoutOptions)
+	GUIWindowFrame::GUIWindowFrame(GUIWidget& parent, const GUILayoutOptions& layoutOptions)
 		:GUIElement(parent, layoutOptions)
 	{
 		const GUISkin* skin = parent.getGUISkin();
@@ -48,7 +48,7 @@ namespace BansheeEngine
 		return CM_NEW(GUIWindowFrame, PoolAlloc) GUIWindowFrame(parent, getDefaultLayoutOptions());
 	}
 
-	GUIWindowFrame* GUIWindowFrame::create(GUIWidget& parent, const GUI_LAYOUT_OPTIONS& layoutOptions)
+	GUIWindowFrame* GUIWindowFrame::create(GUIWidget& parent, const GUILayoutOptions& layoutOptions)
 	{
 		return CM_NEW(GUIWindowFrame, PoolAlloc) GUIWindowFrame(parent, layoutOptions);
 	}
@@ -105,9 +105,9 @@ namespace BansheeEngine
 		mImageSprite->fillBuffer(vertices, uv, indices, startingQuad, maxNumQuads, vertexStride, indexStride, renderElementIdx);
 	}
 
-	const GUI_LAYOUT_OPTIONS& GUIWindowFrame::getDefaultLayoutOptions()
+	const GUILayoutOptions& GUIWindowFrame::getDefaultLayoutOptions()
 	{
-		static GUI_LAYOUT_OPTIONS layoutOptions;
+		static GUILayoutOptions layoutOptions;
 		static bool layoutOptionsInitialized = false;
 
 		if(!layoutOptionsInitialized)

+ 1 - 1
CamelotClient/CmEditorWindow.cpp

@@ -61,7 +61,7 @@ namespace BansheeEditor
 		otherLayout.addElement(mDbgLabel);
 
 		//GUIFixedSpace& space = otherLayout.addSpace(10); // Due to bug in MSVC compiler I need to store return value
-		otherLayout.addElement(GUIWindowFrame::create(*mGUI, GUI_LAYOUT_OPTIONS(20, 20)));
+		otherLayout.addElement(GUIWindowFrame::create(*mGUI, GUILayoutOptions::fixed(20, 20)));
 		//GUIFixedSpace& space2 = otherLayout.addSpace(10);
 		otherLayout.addElement(GUIWindowFrame::create(*mGUI));
 	}

+ 0 - 1
TODO.txt

@@ -22,7 +22,6 @@ I call waitUntilLoaded too many times. Sometimes 5-6 times in a single function.
 GUIWidget::updateMeshes leaks. If I leave the game running I can see memory continously going up
 
 IMMEDIATE:
- - Call layout update before remesh and input in GUIManager
  - Implement GUILayoutY
 
  Test multiple layout elements