Просмотр исходного кода

Updated GUIFoldout with sub styles, renamed it to GUIComponentFoldout and added a way to change its contents

Marko Pintera 11 лет назад
Родитель
Сommit
6b8cb68575

+ 2 - 2
BansheeEditor/BansheeEditor.vcxproj

@@ -282,7 +282,7 @@
     <ClInclude Include="Include\BsGUIColorField.h" />
     <ClInclude Include="Include\BsGUIFieldBase.h" />
     <ClInclude Include="Include\BsGUIFloatField.h" />
-    <ClInclude Include="Include\BsGUIFoldout.h" />
+    <ClInclude Include="Include\BsGUIComponentFoldout.h" />
     <ClInclude Include="Include\BsGUIIntField.h" />
     <ClInclude Include="Include\BsGUIDropButton.h" />
     <ClInclude Include="Include\BsGUITextField.h" />
@@ -341,7 +341,7 @@
     <ClCompile Include="Source\BsGUIDockSlider.cpp" />
     <ClCompile Include="Source\BsGUIFieldBase.cpp" />
     <ClCompile Include="Source\BsGUIFloatField.cpp" />
-    <ClCompile Include="Source\BsGUIFoldout.cpp" />
+    <ClCompile Include="Source\BsGUIComponentFoldout.cpp" />
     <ClCompile Include="Source\BsGUIIntField.cpp" />
     <ClCompile Include="Source\BsGUIMenuBar.cpp" />
     <ClCompile Include="Source\BsGUIDropButton.cpp" />

+ 6 - 6
BansheeEditor/BansheeEditor.vcxproj.filters

@@ -168,9 +168,6 @@
     <ClInclude Include="Include\BsGUIColorField.h">
       <Filter>Header Files\Editor</Filter>
     </ClInclude>
-    <ClInclude Include="Include\BsGUIFoldout.h">
-      <Filter>Header Files\Editor</Filter>
-    </ClInclude>
     <ClInclude Include="Include\BsGUIDropButton.h">
       <Filter>Header Files\Editor</Filter>
     </ClInclude>
@@ -201,6 +198,9 @@
     <ClInclude Include="Include\BsEditorTestSuite.h">
       <Filter>Header Files\Editor</Filter>
     </ClInclude>
+    <ClInclude Include="Include\BsGUIComponentFoldout.h">
+      <Filter>Header Files\Editor</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="Source\BsEditorWidgetContainer.cpp">
@@ -323,9 +323,6 @@
     <ClCompile Include="Source\BsGUIColorField.cpp">
       <Filter>Source Files\Editor</Filter>
     </ClCompile>
-    <ClCompile Include="Source\BsGUIFoldout.cpp">
-      <Filter>Source Files\Editor</Filter>
-    </ClCompile>
     <ClCompile Include="Source\BsGUIDropButton.cpp">
       <Filter>Source Files\Editor</Filter>
     </ClCompile>
@@ -350,5 +347,8 @@
     <ClCompile Include="Source\BsEditorTestSuite.cpp">
       <Filter>Source Files\Editor</Filter>
     </ClCompile>
+    <ClCompile Include="Source\BsGUIComponentFoldout.cpp">
+      <Filter>Source Files\Editor</Filter>
+    </ClCompile>
   </ItemGroup>
 </Project>

+ 1 - 1
BansheeEditor/Include/BsEditorPrerequisites.h

@@ -40,7 +40,7 @@ namespace BansheeEngine
 	class GUIVector4Field;
 	class GUIColorField;
 	class GUIColor;
-	class GUIFoldout;
+	class GUIComponentFoldout;
 	class GUIDropButton;
 	class EditorWindowManager;
 	class DockManager;

+ 49 - 0
BansheeEditor/Include/BsGUIComponentFoldout.h

@@ -0,0 +1,49 @@
+#pragma once
+
+#include "BsEditorPrerequisites.h"
+#include "BsGUIElementContainer.h"
+
+namespace BansheeEngine
+{
+	class BS_ED_EXPORT GUIComponentFoldout : public GUIElementContainer
+	{
+		struct PrivatelyConstruct {};
+
+	public:
+		static const String& getGUITypeName();
+		static const String& getFoldoutButtonStyleType();
+		static const String& getBackgroundStyleType();
+		static const String& getLabelStyleType();
+
+		static GUIComponentFoldout* create(const HString& label, const GUIOptions& layoutOptions, const String& style = StringUtil::BLANK);
+		static GUIComponentFoldout* create(const HString& label, const String& style = StringUtil::BLANK);
+
+		GUIComponentFoldout(const PrivatelyConstruct& dummy, const HString& label, const String& style, const GUILayoutOptions& layoutOptions);
+
+		bool isExpanded() const { return mIsExpanded; }
+		void setExpanded(bool expanded);
+
+		/**
+		 * Changes the label of the foldout.
+		 */
+		void setContent(const GUIContent& content);
+
+		void _updateLayoutInternal(INT32 x, INT32 y, UINT32 width, UINT32 height,
+			RectI clipRect, UINT8 widgetDepth, UINT16 areaDepth);
+
+		Vector2I _getOptimalSize() const;
+
+		Event<void(bool)> onStateChanged;
+	protected:
+		virtual ~GUIComponentFoldout();
+
+		void toggleTriggered(bool value);
+		void styleUpdated();
+
+		GUILabel* mLabel;
+		GUIToggle* mToggle;
+		GUITexture* mBackground;
+
+		bool mIsExpanded;
+	};
+}

+ 0 - 48
BansheeEditor/Include/BsGUIFoldout.h

@@ -1,48 +0,0 @@
-#pragma once
-
-#include "BsEditorPrerequisites.h"
-#include "BsGUIElementContainer.h"
-
-namespace BansheeEngine
-{
-	class BS_ED_EXPORT GUIFoldout : public GUIElementContainer
-	{
-		struct PrivatelyConstruct {};
-
-	public:
-		static const String& getGUITypeName();
-
-		static GUIFoldout* create(const HString& label, const GUIOptions& layoutOptions, const String& labelStyle = StringUtil::BLANK,
-			const String& toggleStyle = StringUtil::BLANK, const String& backgroundStyle = StringUtil::BLANK);
-
-		static GUIFoldout* create(const HString& label, const String& labelStyle = StringUtil::BLANK,
-			const String& toggleStyle = StringUtil::BLANK, const String& backgroundStyle = StringUtil::BLANK);
-
-		GUIFoldout(const PrivatelyConstruct& dummy, const HString& label, const String& labelStyle, const String& toggleStyle,
-			const String& backgroundStyle, const GUILayoutOptions& layoutOptions);
-
-		bool isExpanded() const { return mIsExpanded; }
-		void setExpanded(bool expanded);
-
-		void _updateLayoutInternal(INT32 x, INT32 y, UINT32 width, UINT32 height,
-			RectI clipRect, UINT8 widgetDepth, UINT16 areaDepth);
-
-		Vector2I _getOptimalSize() const;
-
-		Event<void(bool)> onStateChanged;
-	protected:
-		virtual ~GUIFoldout();
-
-		void toggleTriggered(bool value);
-
-		static const String FOLDOUT_BUTTON_STYLE;
-		static const String FOLDOUT_BG_STYLE;
-		static const String FOLDOUT_LABEL_STYLE;
-
-		GUILabel* mLabel;
-		GUIToggle* mToggle;
-		GUITexture* mBackground;
-
-		bool mIsExpanded;
-	};
-}

+ 35 - 22
BansheeEditor/Source/BsEditorGUI.cpp

@@ -18,6 +18,7 @@
 #include "BsGUIVector2Field.h"
 #include "BsGUIVector3Field.h"
 #include "BsGUIVector4Field.h"
+#include "BsGUIComponentFoldout.h"
 
 #include "BsFont.h"
 #include "BsFontImportOptions.h"
@@ -346,28 +347,6 @@ namespace BansheeEngine
 
 		mSkin.setStyle(GUIInputBox::getGUITypeName(), inputBoxStyle);
 
-		// Foldout
-		GUIElementStyle foldoutBtnStyle;
-		foldoutBtnStyle.normal.texture = getTexture(FoldoutClosedNormalTex);
-		foldoutBtnStyle.hover.texture = getTexture(FoldoutClosedHoverTex);
-		foldoutBtnStyle.active.texture = foldoutBtnStyle.hover.texture;
-		foldoutBtnStyle.normalOn.texture = getTexture(FoldoutOpenNormalTex);
-		foldoutBtnStyle.hoverOn.texture = getTexture(FoldoutOpenHoverTex);
-		foldoutBtnStyle.activeOn.texture = foldoutBtnStyle.hoverOn.texture;
-		foldoutBtnStyle.fixedHeight = true;
-		foldoutBtnStyle.fixedWidth = true;
-		foldoutBtnStyle.height = 10;
-		foldoutBtnStyle.width = 8;
-
-		mSkin.setStyle("FoldoutButton", foldoutBtnStyle);
-
-		GUIElementStyle foldoutBackgroundStyle;
-		foldoutBackgroundStyle.normal.texture = getTexture(FoldoutBackgroundTex);
-		foldoutBackgroundStyle.fixedHeight = true;
-		foldoutBackgroundStyle.height = 12;
-
-		mSkin.setStyle("FoldoutBackground", foldoutBackgroundStyle);
-
 		/************************************************************************/
 		/* 								SCROLL BAR                      		*/
 		/************************************************************************/
@@ -926,6 +905,40 @@ namespace BansheeEngine
 		editorVector4FieldStyle.subStyles[GUIVector4Field::getFloatFieldStyleType()] = GUIFloatField::getGUITypeName();
 
 		mSkin.setStyle(GUIVector4Field::getGUITypeName(), editorVector4FieldStyle);
+
+		/************************************************************************/
+		/* 							COMPONENT FOLDOUT                      		*/
+		/************************************************************************/
+		GUIElementStyle cmpFoldoutBtnStyle;
+		cmpFoldoutBtnStyle.normal.texture = getTexture(FoldoutClosedNormalTex);
+		cmpFoldoutBtnStyle.hover.texture = getTexture(FoldoutClosedHoverTex);
+		cmpFoldoutBtnStyle.active.texture = cmpFoldoutBtnStyle.hover.texture;
+		cmpFoldoutBtnStyle.normalOn.texture = getTexture(FoldoutOpenNormalTex);
+		cmpFoldoutBtnStyle.hoverOn.texture = getTexture(FoldoutOpenHoverTex);
+		cmpFoldoutBtnStyle.activeOn.texture = cmpFoldoutBtnStyle.hoverOn.texture;
+		cmpFoldoutBtnStyle.fixedHeight = true;
+		cmpFoldoutBtnStyle.fixedWidth = true;
+		cmpFoldoutBtnStyle.height = 10;
+		cmpFoldoutBtnStyle.width = 8;
+
+		mSkin.setStyle(GUIComponentFoldout::getFoldoutButtonStyleType(), cmpFoldoutBtnStyle);
+
+		GUIElementStyle cmpFoldoutBackgroundStyle;
+		cmpFoldoutBackgroundStyle.normal.texture = getTexture(FoldoutBackgroundTex);
+		cmpFoldoutBackgroundStyle.fixedHeight = true;
+		cmpFoldoutBackgroundStyle.height = 12;
+
+		mSkin.setStyle(GUIComponentFoldout::getBackgroundStyleType(), cmpFoldoutBackgroundStyle);
+
+		GUIElementStyle cmpFoldoutStyle;
+		cmpFoldoutStyle.fixedHeight = true;
+		cmpFoldoutStyle.height = 12;
+		cmpFoldoutStyle.minWidth = 30;
+		cmpFoldoutStyle.subStyles[GUIComponentFoldout::getLabelStyleType()] = GUIComponentFoldout::getLabelStyleType();
+		cmpFoldoutStyle.subStyles[GUIComponentFoldout::getFoldoutButtonStyleType()] = GUIComponentFoldout::getFoldoutButtonStyleType();
+		cmpFoldoutStyle.subStyles[GUIComponentFoldout::getBackgroundStyleType()] = GUIComponentFoldout::getBackgroundStyleType();
+
+		mSkin.setStyle(GUIComponentFoldout::getGUITypeName(), cmpFoldoutStyle);
 	}
 
 	HSpriteTexture EditorGUI::getTexture(const WString& name)

+ 188 - 181
BansheeEditor/Source/BsGUIFoldout.cpp → BansheeEditor/Source/BsGUIComponentFoldout.cpp

@@ -1,182 +1,189 @@
-#include "BsGUIFoldout.h"
-#include "BsGUIArea.h"
-#include "BsGUILayout.h"
-#include "BsGUILabel.h"
-#include "BsGUIToggle.h"
-#include "BsGUITexture.h"
-#include "BsBuiltinResources.h"
-#include "BsGUIWidget.h"
-#include "BsGUIMouseEvent.h"
-
-using namespace std::placeholders;
-
-namespace BansheeEngine
-{
-	const String GUIFoldout::FOLDOUT_BUTTON_STYLE = "FoldoutButton";
-	const String GUIFoldout::FOLDOUT_BG_STYLE = "FoldoutBackground";
-	const String GUIFoldout::FOLDOUT_LABEL_STYLE = "Label";
-
-	GUIFoldout::GUIFoldout(const PrivatelyConstruct& dummy, const HString& label, const String& labelStyle,
-		const String& toggleStyle, const String& backgroundStyle, const GUILayoutOptions& layoutOptions)
-		:GUIElementContainer(layoutOptions, backgroundStyle), mToggle(nullptr), mBackground(nullptr), mIsExpanded(false)
-	{
-		mLabel = GUILabel::create(label, labelStyle);
-		mToggle = GUIToggle::create(HString(L""), toggleStyle);
-		mBackground = GUITexture::create(backgroundStyle);
-
-		_registerChildElement(mLabel);
-		_registerChildElement(mToggle);
-		_registerChildElement(mBackground);
-
-		mToggle->onToggled.connect(std::bind(&GUIFoldout::toggleTriggered, this, _1));
-	}
-
-	GUIFoldout::~GUIFoldout()
-	{
-
-	}
-
-	GUIFoldout* GUIFoldout::create(const HString& label, const GUIOptions& layoutOptions,
-		const String& labelStyle, const String& toggleStyle, const String& backgroundStyle)
-	{
-		const String* curLabelStyle = &labelStyle;
-		if (*curLabelStyle == StringUtil::BLANK)
-			curLabelStyle = &FOLDOUT_LABEL_STYLE;
-
-		const String* curToggleStyle = &toggleStyle;
-		if(*curToggleStyle == StringUtil::BLANK)
-			curToggleStyle = &FOLDOUT_BUTTON_STYLE;
-
-		const String* curBackgroundStyle = &backgroundStyle;
-		if(*curBackgroundStyle == StringUtil::BLANK)
-			curBackgroundStyle = &FOLDOUT_BG_STYLE;
-
-		return bs_new<GUIFoldout>(PrivatelyConstruct(), label, *curLabelStyle, *curToggleStyle, *curBackgroundStyle,
-			GUILayoutOptions::create(layoutOptions));
-	}
-
-	GUIFoldout* GUIFoldout::create(const HString& label, const String& labelStyle,
-		const String& toggleStyle, const String& backgroundStyle)
-	{
-		const String* curLabelStyle = &labelStyle;
-		if (*curLabelStyle == StringUtil::BLANK)
-			curLabelStyle = &FOLDOUT_LABEL_STYLE;
-
-		const String* curToggleStyle = &toggleStyle;
-		if(*curToggleStyle == StringUtil::BLANK)
-			curToggleStyle = &FOLDOUT_BUTTON_STYLE;
-
-		const String* curBackgroundStyle = &backgroundStyle;
-		if(*curBackgroundStyle == StringUtil::BLANK)
-			curBackgroundStyle = &FOLDOUT_BG_STYLE;
-
-		return bs_new<GUIFoldout>(PrivatelyConstruct(), label, *curLabelStyle, *curToggleStyle, *curBackgroundStyle,
-			GUILayoutOptions::create());
-	}
-
-	void GUIFoldout::setExpanded(bool expanded)
-	{
-		if(mIsExpanded != expanded)
-		{
-			mIsExpanded = expanded;
-
-			if(mIsExpanded)
-				mToggle->toggleOn();
-			else
-				mToggle->toggleOff();
-
-			markContentAsDirty();
-
-			if(!onStateChanged.empty())
-				onStateChanged(mIsExpanded);
-		}
-	}
-
-	void GUIFoldout::toggleTriggered(bool value)
-	{
-		mIsExpanded = value;
-
-		markContentAsDirty();
-
-		onStateChanged(value);
-	}
-
-	void GUIFoldout::_updateLayoutInternal(INT32 x, INT32 y, UINT32 width, UINT32 height,
-		RectI clipRect, UINT8 widgetDepth, UINT16 areaDepth)
-	{
-		UINT32 toggleOffset = 0;
-
-		{
-			Vector2I optimalSize = mToggle->_getOptimalSize();
-			INT32 yOffset = Math::roundToInt(((INT32)height - optimalSize.y) * 0.5f);
-
-			Vector2I offset(x, y + yOffset);
-			mToggle->_setOffset(offset);
-			mToggle->_setWidth(optimalSize.x);
-			mToggle->_setHeight(optimalSize.y);
-			mToggle->_setAreaDepth(areaDepth);
-			mToggle->_setWidgetDepth(widgetDepth);
-
-			RectI elemClipRect(clipRect.x - offset.x, clipRect.y - offset.y, clipRect.width, clipRect.height);
-			mToggle->_setClipRect(elemClipRect);
-
-			toggleOffset = optimalSize.x;
-		}
-
-		{
-			Vector2I optimalSize = mLabel->_getOptimalSize();
-			INT32 yOffset = Math::roundToInt(((INT32)height - optimalSize.y) * 0.5f);
-
-			Vector2I offset(x + toggleOffset, y + yOffset);
-			mLabel->_setOffset(offset);
-			mLabel->_setWidth(optimalSize.x);
-			mLabel->_setHeight(optimalSize.y);
-			mLabel->_setAreaDepth(areaDepth);
-			mLabel->_setWidgetDepth(widgetDepth);
-
-			RectI elemClipRect(clipRect.x - offset.x, clipRect.y - offset.y, clipRect.width, clipRect.height);
-			mLabel->_setClipRect(elemClipRect);
-		}
-
-		{
-			Vector2I labelOptimalSize = mLabel->_getOptimalSize();
-			Vector2I toggleOptimalSize = mToggle->_getOptimalSize();
-			INT32 maxHeight = std::max(labelOptimalSize.y, toggleOptimalSize.y);
-
-			INT32 yOffset = Math::roundToInt(((INT32)height - maxHeight) * 0.5f);
-
-			Vector2I offset(x, y + yOffset);
-			mBackground->_setOffset(offset);
-			mBackground->_setWidth(mWidth);
-			mBackground->_setHeight(maxHeight);
-			mBackground->_setAreaDepth(areaDepth + 1);
-			mBackground->_setWidgetDepth(widgetDepth);
-
-			RectI elemClipRect(clipRect.x - offset.x, clipRect.y - offset.y, clipRect.width, clipRect.height);
-			mBackground->_setClipRect(elemClipRect);
-		}
-	}
-
-	Vector2I GUIFoldout::_getOptimalSize() const
-	{
-		Vector2I optimalsize = mToggle->_getOptimalSize();
-		Vector2I labelOptimalSize = mLabel->_getOptimalSize();
-
-		optimalsize.x += labelOptimalSize.x;
-		optimalsize.y = std::max(optimalsize.y, labelOptimalSize.y);
-
-		if(mBackground != nullptr)
-		{
-			optimalsize.x = std::max(optimalsize.x, mBackground->_getOptimalSize().x);
-			optimalsize.y = std::max(optimalsize.y, mBackground->_getOptimalSize().y);
-		}
-
-		return optimalsize;
-	}
-
-	const String& GUIFoldout::getGUITypeName()
-	{
-		static String typeName = "Foldout";
-		return typeName;
-	}
+#include "BsGUIComponentFoldout.h"
+#include "BsGUIArea.h"
+#include "BsGUILayout.h"
+#include "BsGUILabel.h"
+#include "BsGUIToggle.h"
+#include "BsGUITexture.h"
+#include "BsBuiltinResources.h"
+#include "BsGUIWidget.h"
+#include "BsGUIMouseEvent.h"
+
+using namespace std::placeholders;
+
+namespace BansheeEngine
+{
+	GUIComponentFoldout::GUIComponentFoldout(const PrivatelyConstruct& dummy, const HString& label, const String& style,
+		const GUILayoutOptions& layoutOptions)
+		:GUIElementContainer(layoutOptions, style), mToggle(nullptr), mBackground(nullptr), mIsExpanded(false)
+	{
+		mLabel = GUILabel::create(label, getSubStyleName(getLabelStyleType()));
+		mToggle = GUIToggle::create(HString(L""), getSubStyleName(getFoldoutButtonStyleType()));
+		mBackground = GUITexture::create(getSubStyleName(getBackgroundStyleType()));
+
+		_registerChildElement(mLabel);
+		_registerChildElement(mToggle);
+		_registerChildElement(mBackground);
+
+		mToggle->onToggled.connect(std::bind(&GUIComponentFoldout::toggleTriggered, this, _1));
+	}
+
+	GUIComponentFoldout::~GUIComponentFoldout()
+	{
+
+	}
+
+	GUIComponentFoldout* GUIComponentFoldout::create(const HString& label, const GUIOptions& layoutOptions,
+		const String& style)
+	{
+		const String* curStyle = &style;
+		if (*curStyle == StringUtil::BLANK)
+			curStyle = &getGUITypeName();
+
+		return bs_new<GUIComponentFoldout>(PrivatelyConstruct(), label, *curStyle, GUILayoutOptions::create(layoutOptions));
+	}
+
+	GUIComponentFoldout* GUIComponentFoldout::create(const HString& label, const String& style)
+	{
+		const String* curStyle = &style;
+		if (*curStyle == StringUtil::BLANK)
+			curStyle = &getGUITypeName();
+
+		return bs_new<GUIComponentFoldout>(PrivatelyConstruct(), label, *curStyle, GUILayoutOptions::create());
+	}
+
+	void GUIComponentFoldout::setExpanded(bool expanded)
+	{
+		if(mIsExpanded != expanded)
+		{
+			mIsExpanded = expanded;
+
+			if(mIsExpanded)
+				mToggle->toggleOn();
+			else
+				mToggle->toggleOff();
+
+			markContentAsDirty();
+
+			if(!onStateChanged.empty())
+				onStateChanged(mIsExpanded);
+		}
+	}
+
+	void GUIComponentFoldout::setContent(const GUIContent& content)
+	{
+		mLabel->setContent(content);
+	}
+
+	void GUIComponentFoldout::toggleTriggered(bool value)
+	{
+		mIsExpanded = value;
+
+		markContentAsDirty();
+
+		onStateChanged(value);
+	}
+
+	void GUIComponentFoldout::_updateLayoutInternal(INT32 x, INT32 y, UINT32 width, UINT32 height,
+		RectI clipRect, UINT8 widgetDepth, UINT16 areaDepth)
+	{
+		UINT32 toggleOffset = 0;
+
+		{
+			Vector2I optimalSize = mToggle->_getOptimalSize();
+			INT32 yOffset = Math::roundToInt(((INT32)height - optimalSize.y) * 0.5f);
+
+			Vector2I offset(x, y + yOffset);
+			mToggle->_setOffset(offset);
+			mToggle->_setWidth(optimalSize.x);
+			mToggle->_setHeight(optimalSize.y);
+			mToggle->_setAreaDepth(areaDepth);
+			mToggle->_setWidgetDepth(widgetDepth);
+
+			RectI elemClipRect(clipRect.x - offset.x, clipRect.y - offset.y, clipRect.width, clipRect.height);
+			mToggle->_setClipRect(elemClipRect);
+
+			toggleOffset = optimalSize.x;
+		}
+
+		{
+			Vector2I optimalSize = mLabel->_getOptimalSize();
+			INT32 yOffset = Math::roundToInt(((INT32)height - optimalSize.y) * 0.5f);
+
+			Vector2I offset(x + toggleOffset, y + yOffset);
+			mLabel->_setOffset(offset);
+			mLabel->_setWidth(optimalSize.x);
+			mLabel->_setHeight(optimalSize.y);
+			mLabel->_setAreaDepth(areaDepth);
+			mLabel->_setWidgetDepth(widgetDepth);
+
+			RectI elemClipRect(clipRect.x - offset.x, clipRect.y - offset.y, clipRect.width, clipRect.height);
+			mLabel->_setClipRect(elemClipRect);
+		}
+
+		{
+			Vector2I labelOptimalSize = mLabel->_getOptimalSize();
+			Vector2I toggleOptimalSize = mToggle->_getOptimalSize();
+			INT32 maxHeight = std::max(labelOptimalSize.y, toggleOptimalSize.y);
+
+			INT32 yOffset = Math::roundToInt(((INT32)height - maxHeight) * 0.5f);
+
+			Vector2I offset(x, y + yOffset);
+			mBackground->_setOffset(offset);
+			mBackground->_setWidth(mWidth);
+			mBackground->_setHeight(maxHeight);
+			mBackground->_setAreaDepth(areaDepth + 1);
+			mBackground->_setWidgetDepth(widgetDepth);
+
+			RectI elemClipRect(clipRect.x - offset.x, clipRect.y - offset.y, clipRect.width, clipRect.height);
+			mBackground->_setClipRect(elemClipRect);
+		}
+	}
+
+	Vector2I GUIComponentFoldout::_getOptimalSize() const
+	{
+		Vector2I optimalsize = mToggle->_getOptimalSize();
+		Vector2I labelOptimalSize = mLabel->_getOptimalSize();
+
+		optimalsize.x += labelOptimalSize.x;
+		optimalsize.y = std::max(optimalsize.y, labelOptimalSize.y);
+
+		if(mBackground != nullptr)
+		{
+			optimalsize.x = std::max(optimalsize.x, mBackground->_getOptimalSize().x);
+			optimalsize.y = std::max(optimalsize.y, mBackground->_getOptimalSize().y);
+		}
+
+		return optimalsize;
+	}
+
+	void GUIComponentFoldout::styleUpdated()
+	{
+		mLabel->setStyle(getSubStyleName(getLabelStyleType()));
+		mToggle->setStyle(getSubStyleName(getFoldoutButtonStyleType()));
+		mBackground->setStyle(getSubStyleName(getBackgroundStyleType()));
+	}
+
+	const String& GUIComponentFoldout::getGUITypeName()
+	{
+		static String typeName = "ComponentFoldout";
+		return typeName;
+	}
+
+	const String& GUIComponentFoldout::getFoldoutButtonStyleType()
+	{
+		static String FOLDOUT_BUTTON_STYLE = "ComponentFoldoutButton";
+		return FOLDOUT_BUTTON_STYLE;		
+	}
+
+	const String& GUIComponentFoldout::getBackgroundStyleType()
+	{
+		static String FOLDOUT_BG_STYLE = "ComponentFoldoutBackground";
+		return FOLDOUT_BG_STYLE;
+	}
+
+	const String& GUIComponentFoldout::getLabelStyleType()
+	{
+		static String FOLDOUT_LABEL_STYLE = "EditorFieldLabel";
+		return FOLDOUT_LABEL_STYLE;
+	}
 }

+ 2 - 2
BansheeEditor/Source/DbgEditorWidget2.cpp

@@ -15,7 +15,7 @@
 #include "BsGUIToggleField.h"
 #include "BsGUIColorField.h"
 #include "BsGUIButton.h"
-#include "BsGUIFoldout.h"
+#include "BsGUIComponentFoldout.h"
 #include "BsGUISpace.h"
 #include "BsHString.h"
 
@@ -57,7 +57,7 @@ namespace BansheeEngine
 		GUIVector2Field* vec2Field = GUIVector2Field::create(HString(L"Vec2 Field"), GUIOptions(GUIOption::fixedWidth(200)));
 		GUIToggleField* toggleField = GUIToggleField::create(HString(L"Toggle Field"), GUIOptions(GUIOption::fixedWidth(200)));
 		GUIColorField* colorField = GUIColorField::create(HString(L"Color Field"), GUIOptions(GUIOption::fixedWidth(200)));
-		GUIFoldout* foldout = GUIFoldout::create(HString(L"Test"), GUIOptions(GUIOption::fixedWidth(200)));
+		GUIComponentFoldout* foldout = GUIComponentFoldout::create(HString(L"Test"), GUIOptions(GUIOption::fixedWidth(200)));
 		colorField->setValue(Color::Red);
 
 		GUIButton* button = GUIButton::create(HString(L"Testing"), GUIOptions(GUIOption::fixedWidth(100)));

+ 6 - 3
Inspector.txt

@@ -1,6 +1,3 @@
-Update C# GUIElementStyle with sub styles
-Update GUIFoldout with sub styles
-
 Transient meshes don't seem to be released properly in 100% of the cases
  - Might be related to creating/destroying GUI elements?
 
@@ -59,6 +56,12 @@ KEEP IN MIND:
 
 
 
+
+
+
+
+
+
 
 
 

+ 5 - 5
MBansheeEditor/GUI/GUIFoldout.cs → MBansheeEditor/GUI/GUIComponentFoldout.cs

@@ -4,23 +4,23 @@ using BansheeEngine;
 
 namespace BansheeEditor
 {
-    public sealed class GUIFoldout : GUIElement
+    public sealed class GUIComponentFoldout : GUIElement
     {
         public delegate void OnToggledDelegate(bool expanded);
 
         public event OnToggledDelegate OnToggled;
 
-        public GUIFoldout(GUIContent content, string style, params GUIOption[] options)
+        public GUIComponentFoldout(GUIContent content, string style, params GUIOption[] options)
         {
             Internal_CreateInstance(this, content, style, options);
         }
 
-        public GUIFoldout(GUIContent content, string style)
+        public GUIComponentFoldout(GUIContent content, string style)
         {
             Internal_CreateInstance(this, content, style, new GUIOption[0]);
         }
 
-        public GUIFoldout(GUIContent content, params GUIOption[] options)
+        public GUIComponentFoldout(GUIContent content, params GUIOption[] options)
         {
             Internal_CreateInstance(this, content, "", options);
         }
@@ -49,7 +49,7 @@ namespace BansheeEditor
         }
 
         [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_CreateInstance(GUIFoldout instance, GUIContent content, string style, GUIOption[] options);
+        private static extern void Internal_CreateInstance(GUIComponentFoldout instance, GUIContent content, string style, GUIOption[] options);
 
         [MethodImpl(MethodImplOptions.InternalCall)]
         private static extern void Internal_SetContent(IntPtr nativeInstance, GUIContent content);

+ 2 - 2
MBansheeEditor/Inspector/InspectorWindow.cs

@@ -8,7 +8,7 @@ namespace BansheeEditor
     {
         private class InspectorData
         {
-            public GUIFoldout foldout;
+            public GUIComponentFoldout foldout;
             public GUIPanelContainer container;
             public Inspector inspector;
             public bool expanded = true;
@@ -31,7 +31,7 @@ namespace BansheeEditor
                 InspectorData data = new InspectorData();
                 GUIPanel inspectorPanel = CreatePanel(0, 0, 0, 0);
 
-                data.foldout = new GUIFoldout(allComponents[i].GetType().Name);
+                data.foldout = new GUIComponentFoldout(allComponents[i].GetType().Name);
                 inspectorLayout.AddElement(data.foldout);
                 data.container = new GUIPanelContainer(inspectorPanel);
                 inspectorLayout.AddElement(data.container);

+ 1 - 1
MBansheeEditor/MBansheeEditor.csproj

@@ -51,7 +51,7 @@
     <Compile Include="GUI\GUIVector3Field.cs" />
     <Compile Include="GUI\GUIColorField.cs" />
     <Compile Include="GUI\GUIFloatField.cs" />
-    <Compile Include="GUI\GUIFoldout.cs" />
+    <Compile Include="GUI\GUIComponentFoldout.cs" />
     <Compile Include="GUI\GUIIntField.cs" />
     <Compile Include="GUI\GUIPanelContainer.cs" />
     <Compile Include="GUI\GUITextField.cs" />

+ 27 - 0
SBansheeEditor/Include/BsScriptGUIComponentFoldout.h

@@ -0,0 +1,27 @@
+#pragma once
+
+#include "BsScriptEditorPrerequisites.h"
+#include "BsScriptGUIElement.h"
+
+namespace BansheeEngine
+{
+	class BS_SCR_BED_EXPORT ScriptGUIComponentFoldout : public TScriptGUIElement<ScriptGUIComponentFoldout>
+	{
+	public:
+		SCRIPT_OBJ(BansheeEditorAssemblyName, "BansheeEditor", "GUIComponentFoldout")
+
+	private:
+		static void internal_createInstance(MonoObject* instance, MonoObject* content, MonoString* style, MonoArray* guiOptions);
+		static void internal_setContent(ScriptGUIComponentFoldout* nativeInstance, MonoObject* content);
+		static void internal_setExpanded(ScriptGUIComponentFoldout* nativeInstance, bool expanded);
+		static void internal_getIsExpanded(ScriptGUIComponentFoldout* nativeInstance, bool* isExpanded);
+
+		static void onToggled(MonoObject* instance, bool expanded);
+
+		ScriptGUIComponentFoldout(MonoObject* instance, GUIComponentFoldout* foldout);
+
+		typedef void (__stdcall *OnToggledThunkDef) (MonoObject*, bool, MonoException**);
+
+		static OnToggledThunkDef onToggledThunk;
+	};
+}

+ 0 - 27
SBansheeEditor/Include/BsScriptGUIFoldout.h

@@ -1,27 +0,0 @@
-#pragma once
-
-#include "BsScriptEditorPrerequisites.h"
-#include "BsScriptGUIElement.h"
-
-namespace BansheeEngine
-{
-	class BS_SCR_BED_EXPORT ScriptGUIFoldout : public TScriptGUIElement<ScriptGUIFoldout>
-	{
-	public:
-		SCRIPT_OBJ(BansheeEditorAssemblyName, "BansheeEditor", "GUIFoldout")
-
-	private:
-		static void internal_createInstance(MonoObject* instance, MonoObject* content, MonoString* style, MonoArray* guiOptions);
-		static void internal_setContent(ScriptGUIFoldout* nativeInstance, MonoObject* content);
-		static void internal_setExpanded(ScriptGUIFoldout* nativeInstance, bool expanded);
-		static void internal_getIsExpanded(ScriptGUIFoldout* nativeInstance, bool* isExpanded);
-
-		static void onToggled(MonoObject* instance, bool expanded);
-
-		ScriptGUIFoldout(MonoObject* instance, GUIFoldout* foldout);
-
-		typedef void (__stdcall *OnToggledThunkDef) (MonoObject*, bool, MonoException**);
-
-		static OnToggledThunkDef onToggledThunk;
-	};
-}

+ 2 - 2
SBansheeEditor/SBansheeEditor.vcxproj

@@ -234,7 +234,7 @@
     <ClInclude Include="Include\BsScriptEditorWindow.h" />
     <ClInclude Include="Include\BsScriptGUIColorField.h" />
     <ClInclude Include="Include\BsScriptGUIFloatField.h" />
-    <ClInclude Include="Include\BsScriptGUIFoldout.h" />
+    <ClInclude Include="Include\BsScriptGUIComponentFoldout.h" />
     <ClInclude Include="Include\BsScriptGUIGameObjectField.h" />
     <ClInclude Include="Include\BsScriptGUIIntField.h" />
     <ClInclude Include="Include\BsScriptGUIPanelContainer.h" />
@@ -255,7 +255,7 @@
     <ClCompile Include="Source\BsScriptEditorWindow.cpp" />
     <ClCompile Include="Source\BsScriptGUIColorField.cpp" />
     <ClCompile Include="Source\BsScriptGUIFloatField.cpp" />
-    <ClCompile Include="Source\BsScriptGUIFoldout.cpp" />
+    <ClCompile Include="Source\BsScriptGUIComponentFoldout.cpp" />
     <ClCompile Include="Source\BsScriptGUIGameObjectField.cpp" />
     <ClCompile Include="Source\BsScriptGUIIntField.cpp" />
     <ClCompile Include="Source\BsScriptGUIPanelContainer.cpp" />

+ 6 - 6
SBansheeEditor/SBansheeEditor.vcxproj.filters

@@ -21,9 +21,6 @@
     <ClInclude Include="Include\BsScriptEditorWindow.h">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="Include\BsScriptGUIFoldout.h">
-      <Filter>Header Files</Filter>
-    </ClInclude>
     <ClInclude Include="Include\BsScriptGUIIntField.h">
       <Filter>Header Files</Filter>
     </ClInclude>
@@ -72,6 +69,9 @@
     <ClInclude Include="Include\BsEditorScriptManager.h">
       <Filter>Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="Include\BsScriptGUIComponentFoldout.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="Source\BsScriptEditorPlugin.cpp">
@@ -80,9 +80,6 @@
     <ClCompile Include="Source\BsScriptEditorWindow.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="Source\BsScriptGUIFoldout.cpp">
-      <Filter>Source Files</Filter>
-    </ClCompile>
     <ClCompile Include="Source\BsScriptGUIIntField.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
@@ -131,5 +128,8 @@
     <ClCompile Include="Source\BsEditorScriptManager.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="Source\BsScriptGUIComponentFoldout.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
 </Project>

+ 86 - 0
SBansheeEditor/Source/BsScriptGUIComponentFoldout.cpp

@@ -0,0 +1,86 @@
+#include "BsScriptGUIComponentFoldout.h"
+#include "BsScriptMeta.h"
+#include "BsMonoField.h"
+#include "BsMonoClass.h"
+#include "BsMonoManager.h"
+#include "BsMonoMethod.h"
+#include "BsSpriteTexture.h"
+#include "BsMonoUtil.h"
+#include "BsGUILayout.h"
+#include "BsGUIComponentFoldout.h"
+#include "BsGUIOptions.h"
+#include "BsGUIContent.h"
+#include "BsScriptGUIElementStyle.h"
+#include "BsScriptGUILayout.h"
+#include "BsScriptGUIArea.h"
+#include "BsScriptHString.h"
+#include "BsScriptGUIContent.h"
+
+using namespace std::placeholders;
+
+namespace BansheeEngine
+{
+	ScriptGUIComponentFoldout::OnToggledThunkDef ScriptGUIComponentFoldout::onToggledThunk;
+
+	ScriptGUIComponentFoldout::ScriptGUIComponentFoldout(MonoObject* instance, GUIComponentFoldout* foldout)
+		:TScriptGUIElement(instance, foldout)
+	{
+
+	}
+
+	void ScriptGUIComponentFoldout::initRuntimeData()
+	{
+		metaData.scriptClass->addInternalCall("Internal_CreateInstance", &ScriptGUIComponentFoldout::internal_createInstance);
+		metaData.scriptClass->addInternalCall("Internal_SetContent", &ScriptGUIComponentFoldout::internal_setContent);
+		metaData.scriptClass->addInternalCall("Internal_SetExpanded", &ScriptGUIComponentFoldout::internal_setExpanded);
+		metaData.scriptClass->addInternalCall("Internal_IsExpanded", &ScriptGUIComponentFoldout::internal_getIsExpanded);
+
+		onToggledThunk = (OnToggledThunkDef)metaData.scriptClass->getMethod("DoOnToggled", 1).getThunk();
+	}
+
+	void ScriptGUIComponentFoldout::internal_createInstance(MonoObject* instance, MonoObject* content, MonoString* style, MonoArray* guiOptions)
+	{
+		GUIOptions options;
+
+		UINT32 arrayLen = (UINT32)mono_array_length(guiOptions);
+		for(UINT32 i = 0; i < arrayLen; i++)
+			options.addOption(mono_array_get(guiOptions, GUIOption, i));
+
+		HString label = ScriptGUIContent::getText(content);
+		GUIComponentFoldout* guiFoldout = GUIComponentFoldout::create(label);
+
+		guiFoldout->onStateChanged.connect(std::bind(&ScriptGUIComponentFoldout::onToggled, instance, _1));
+
+		ScriptGUIComponentFoldout* nativeInstance = new (bs_alloc<ScriptGUIComponentFoldout>()) ScriptGUIComponentFoldout(instance, guiFoldout);
+	}
+
+	void ScriptGUIComponentFoldout::internal_setContent(ScriptGUIComponentFoldout* nativeInstance, MonoObject* content)
+	{
+		GUIContent nativeContent(ScriptGUIContent::getText(content), ScriptGUIContent::getImage(content), ScriptGUIContent::getTooltip(content));
+		
+		GUIComponentFoldout* guiFoldout = static_cast<GUIComponentFoldout*>(nativeInstance->getGUIElement());
+		guiFoldout->setContent(nativeContent);
+	}
+
+	void ScriptGUIComponentFoldout::internal_setExpanded(ScriptGUIComponentFoldout* nativeInstance, bool expanded)
+	{
+		GUIComponentFoldout* foldout = static_cast<GUIComponentFoldout*>(nativeInstance->getGUIElement());
+
+		foldout->setExpanded(expanded);
+	}
+
+	void ScriptGUIComponentFoldout::internal_getIsExpanded(ScriptGUIComponentFoldout* nativeInstance, bool* isExpanded)
+	{
+		GUIComponentFoldout* foldout = static_cast<GUIComponentFoldout*>(nativeInstance->getGUIElement());
+
+		*isExpanded = foldout->isExpanded();
+	}
+
+	void ScriptGUIComponentFoldout::onToggled(MonoObject* instance, bool expanded)
+	{
+		MonoException* exception = nullptr;
+		onToggledThunk(instance, expanded, &exception);
+
+		MonoUtil::throwIfException(exception);
+	}
+}

+ 0 - 85
SBansheeEditor/Source/BsScriptGUIFoldout.cpp

@@ -1,85 +0,0 @@
-#include "BsScriptGUIFoldout.h"
-#include "BsScriptMeta.h"
-#include "BsMonoField.h"
-#include "BsMonoClass.h"
-#include "BsMonoManager.h"
-#include "BsMonoMethod.h"
-#include "BsSpriteTexture.h"
-#include "BsMonoUtil.h"
-#include "BsGUILayout.h"
-#include "BsGUIFoldout.h"
-#include "BsGUIOptions.h"
-#include "BsGUIContent.h"
-#include "BsScriptGUIElementStyle.h"
-#include "BsScriptGUILayout.h"
-#include "BsScriptGUIArea.h"
-#include "BsScriptHString.h"
-#include "BsScriptGUIContent.h"
-
-using namespace std::placeholders;
-
-namespace BansheeEngine
-{
-	ScriptGUIFoldout::OnToggledThunkDef ScriptGUIFoldout::onToggledThunk;
-
-	ScriptGUIFoldout::ScriptGUIFoldout(MonoObject* instance, GUIFoldout* foldout)
-		:TScriptGUIElement(instance, foldout)
-	{
-
-	}
-
-	void ScriptGUIFoldout::initRuntimeData()
-	{
-		metaData.scriptClass->addInternalCall("Internal_CreateInstance", &ScriptGUIFoldout::internal_createInstance);
-		metaData.scriptClass->addInternalCall("Internal_SetContent", &ScriptGUIFoldout::internal_setContent);
-		metaData.scriptClass->addInternalCall("Internal_SetExpanded", &ScriptGUIFoldout::internal_setExpanded);
-		metaData.scriptClass->addInternalCall("Internal_IsExpanded", &ScriptGUIFoldout::internal_getIsExpanded);
-
-		onToggledThunk = (OnToggledThunkDef)metaData.scriptClass->getMethod("DoOnToggled", 1).getThunk();
-	}
-
-	void ScriptGUIFoldout::internal_createInstance(MonoObject* instance, MonoObject* content, MonoString* style, MonoArray* guiOptions)
-	{
-		GUIOptions options;
-
-		UINT32 arrayLen = (UINT32)mono_array_length(guiOptions);
-		for(UINT32 i = 0; i < arrayLen; i++)
-			options.addOption(mono_array_get(guiOptions, GUIOption, i));
-
-		HString label = ScriptGUIContent::getText(content);
-		GUIFoldout* guiFoldout = GUIFoldout::create(label);
-
-		guiFoldout->onStateChanged.connect(std::bind(&ScriptGUIFoldout::onToggled, instance, _1));
-
-		ScriptGUIFoldout* nativeInstance = new (bs_alloc<ScriptGUIFoldout>()) ScriptGUIFoldout(instance, guiFoldout);
-	}
-
-	void ScriptGUIFoldout::internal_setContent(ScriptGUIFoldout* nativeInstance, MonoObject* content)
-	{
-		GUIContent nativeContent(ScriptGUIContent::getText(content), ScriptGUIContent::getImage(content), ScriptGUIContent::getTooltip(content));
-		
-		// TODO - Update GUIFoldout once it has a label
-	}
-
-	void ScriptGUIFoldout::internal_setExpanded(ScriptGUIFoldout* nativeInstance, bool expanded)
-	{
-		GUIFoldout* foldout = static_cast<GUIFoldout*>(nativeInstance->getGUIElement());
-
-		foldout->setExpanded(expanded);
-	}
-
-	void ScriptGUIFoldout::internal_getIsExpanded(ScriptGUIFoldout* nativeInstance, bool* isExpanded)
-	{
-		GUIFoldout* foldout = static_cast<GUIFoldout*>(nativeInstance->getGUIElement());
-
-		*isExpanded = foldout->isExpanded();
-	}
-
-	void ScriptGUIFoldout::onToggled(MonoObject* instance, bool expanded)
-	{
-		MonoException* exception = nullptr;
-		onToggledThunk(instance, expanded, &exception);
-
-		MonoUtil::throwIfException(exception);
-	}
-}