Browse Source

Foldout has label

Marko Pintera 11 years ago
parent
commit
4c40536bdd

+ 6 - 4
BansheeEditor/Include/BsGUIFoldout.h

@@ -12,13 +12,13 @@ namespace BansheeEngine
 	public:
 		static const String& getGUITypeName();
 
-		static GUIFoldout* create(const GUIOptions& layoutOptions, 
+		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 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 String& toggleStyle, 
+		GUIFoldout(const PrivatelyConstruct& dummy, const HString& label, const String& labelStyle, const String& toggleStyle,
 			const String& backgroundStyle, const GUILayoutOptions& layoutOptions);
 
 		bool isExpanded() const { return mIsExpanded; }
@@ -36,7 +36,9 @@ namespace BansheeEngine
 	protected:
 		static const String FOLDOUT_BUTTON_STYLE;
 		static const String FOLDOUT_BG_STYLE;
+		static const String FOLDOUT_LABEL_STYLE;
 
+		GUILabel* mLabel;
 		GUIToggle* mToggle;
 		GUITexture* mBackground;
 

+ 2 - 2
BansheeEditor/Source/BsEditorGUI.cpp

@@ -342,7 +342,7 @@ namespace BansheeEngine
 		foldoutBtnStyle.activeOn.texture = foldoutBtnStyle.hoverOn.texture;
 		foldoutBtnStyle.fixedHeight = true;
 		foldoutBtnStyle.fixedWidth = true;
-		foldoutBtnStyle.height = 8;
+		foldoutBtnStyle.height = 10;
 		foldoutBtnStyle.width = 8;
 
 		mSkin.setStyle("FoldoutButton", foldoutBtnStyle);
@@ -350,7 +350,7 @@ namespace BansheeEngine
 		GUIElementStyle foldoutBackgroundStyle;
 		foldoutBackgroundStyle.normal.texture = getTexture(FoldoutBackgroundTex);
 		foldoutBackgroundStyle.fixedHeight = true;
-		foldoutBackgroundStyle.height = 8;
+		foldoutBackgroundStyle.height = 12;
 
 		mSkin.setStyle("FoldoutBackground", foldoutBackgroundStyle);
 

+ 50 - 12
BansheeEditor/Source/BsGUIFoldout.cpp

@@ -1,6 +1,7 @@
 #include "BsGUIFoldout.h"
 #include "BsGUIArea.h"
 #include "BsGUILayout.h"
+#include "BsGUILabel.h"
 #include "BsGUIToggle.h"
 #include "BsGUITexture.h"
 #include "BsBuiltinResources.h"
@@ -11,14 +12,17 @@ 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 String& toggleStyle, 
-		const String& backgroundStyle, const GUILayoutOptions& layoutOptions)
+	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);
 	}
@@ -28,9 +32,13 @@ namespace BansheeEngine
 
 	}
 
-	GUIFoldout* GUIFoldout::create(const GUIOptions& layoutOptions, 
-		const String& toggleStyle, const String& backgroundStyle)
+	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;
@@ -39,13 +47,17 @@ namespace BansheeEngine
 		if(*curBackgroundStyle == StringUtil::BLANK)
 			curBackgroundStyle = &FOLDOUT_BG_STYLE;
 
-		return bs_new<GUIFoldout>(PrivatelyConstruct(), *curToggleStyle, *curBackgroundStyle, 
+		return bs_new<GUIFoldout>(PrivatelyConstruct(), label, *curLabelStyle, *curToggleStyle, *curBackgroundStyle,
 			GUILayoutOptions::create(layoutOptions));
 	}
 
-	GUIFoldout* GUIFoldout::create(const String& toggleStyle, 
-		const String& backgroundStyle)
+	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;
@@ -54,7 +66,7 @@ namespace BansheeEngine
 		if(*curBackgroundStyle == StringUtil::BLANK)
 			curBackgroundStyle = &FOLDOUT_BG_STYLE;
 
-		return bs_new<GUIFoldout>(PrivatelyConstruct(), *curToggleStyle, *curBackgroundStyle, 
+		return bs_new<GUIFoldout>(PrivatelyConstruct(), label, *curLabelStyle, *curToggleStyle, *curBackgroundStyle,
 			GUILayoutOptions::create());
 	}
 
@@ -79,9 +91,11 @@ namespace BansheeEngine
 	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((height - optimalSize.y) * 0.5f);
+			INT32 yOffset = Math::roundToInt(((INT32)height - optimalSize.y) * 0.5f);
 
 			Vector2I offset(x, y + yOffset);
 			mToggle->_setOffset(offset);
@@ -92,16 +106,36 @@ namespace BansheeEngine
 
 			RectI elemClipRect(clipRect.x - offset.x, clipRect.y - offset.y, clipRect.width, clipRect.height);
 			mToggle->_setClipRect(elemClipRect);
+
+			toggleOffset = optimalSize.x;
 		}
 
 		{
-			Vector2I optimalSize = mToggle->_getOptimalSize();
-			INT32 yOffset = Math::roundToInt((height - optimalSize.y) * 0.5f);
+			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(optimalSize.y);
+			mBackground->_setHeight(maxHeight);
 			mBackground->_setAreaDepth(areaDepth + 1);
 			mBackground->_setWidgetDepth(widgetDepth);
 
@@ -113,6 +147,10 @@ namespace BansheeEngine
 	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)
 		{

+ 1 - 1
BansheeEditor/Source/DbgEditorWidget2.cpp

@@ -58,7 +58,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(GUIOptions(GUIOption::fixedWidth(200)));
+		GUIFoldout* foldout = GUIFoldout::create(HString(L"Test"), GUIOptions(GUIOption::fixedWidth(200)));
 		GUIGameObjectField* gameObjectField = GUIGameObjectField::create(HString(L"Object Field"), GUIOptions(GUIOption::fixedWidth(200)));
 		colorField->setValue(Color::Red);
 

+ 6 - 3
Inspector.txt

@@ -8,11 +8,13 @@ IMPLEMENTATION STEPS:
    This will also likely require a refactor. Related to above.
 
 TODO:
- - Test GUIPanelContainer and make a C# wrapper. Ensure Inspector uses it.
+ - Hook up int field set/get callbacks
+    - Ensure int field isn't updated from app when in focus
+ - Hook up foldout expand/collapse callbacks
  - Think about how to handle arrays, adding and deleting elements from them.
  - Add labels to foldouts
  - Extend text field so it can be multi-line
- - Port to C#:
+ - Port to C# (+ see below for additional fixes to C++ versions):
    - IntField
    - FloatField
    - ColorField
@@ -41,7 +43,8 @@ KEEP IN MIND:
 BUGS
  - Composite GUI elements like Vector3Field need to set a style with min/max or fixed bounds to their GUIElementContainer
    otherwise they get clipped when their parent layout is too small
-
+ - Modify all editor fields so they implement virtual Vector2I _getOptimalSize() const; and remove it from GUIFieldBase.
+   See IntField for example
 
 
 

BIN
License/BansheeLogo.png


+ 2 - 2
SBansheeEditor/Source/BsScriptGUIFoldout.cpp

@@ -44,8 +44,8 @@ namespace BansheeEngine
 		for(UINT32 i = 0; i < arrayLen; i++)
 			options.addOption(mono_array_get(guiOptions, GUIOption, i));
 
-		GUIContent nativeContent(ScriptGUIContent::getText(content), ScriptGUIContent::getImage(content), ScriptGUIContent::getTooltip(content));
-		GUIFoldout* guiFoldout = GUIFoldout::create(options, toString(MonoUtil::monoToWString(style))); // TODO - Add label
+		HString label = ScriptGUIContent::getText(content);
+		GUIFoldout* guiFoldout = GUIFoldout::create(label);
 
 		guiFoldout->onStateChanged.connect(std::bind(&ScriptGUIFoldout::onToggled, instance, _1));