浏览代码

Inspector displays actual int fields instead of labels

Marko Pintera 11 年之前
父节点
当前提交
163de8cbd1

+ 3 - 3
BansheeEditor/Include/BsGUIFieldBase.h

@@ -17,7 +17,7 @@ namespace BansheeEngine
 		void _updateLayoutInternal(INT32 x, INT32 y, UINT32 width, UINT32 height,
 			RectI clipRect, UINT8 widgetDepth, UINT16 areaDepth);
 
-		Vector2I _getOptimalSize() const;
+		virtual Vector2I _getOptimalSize() const;
 	protected:
 		virtual ~GUIFieldBase() { }
 
@@ -62,7 +62,7 @@ namespace BansheeEngine
 
 		static T* create(const GUIOptions& layoutOptions, const String& entryElementStyle = StringUtil::BLANK)
 		{
-			return bs_new<T>(PrivatelyConstruct(), GUIContent(), 0, nullptr, entryElementStyle, 
+			return bs_new<T>(PrivatelyConstruct(), GUIContent(), 0, StringUtil::BLANK, entryElementStyle,
 				GUILayoutOptions::create(layoutOptions), false);
 		}
 
@@ -96,7 +96,7 @@ namespace BansheeEngine
 
 		static T* create(const String& entryElementStyle = StringUtil::BLANK)
 		{
-			return bs_new<T>(PrivatelyConstruct(), GUIContent(), 0, nullptr, entryElementStyle, 
+			return bs_new<T>(PrivatelyConstruct(), GUIContent(), 0, StringUtil::BLANK, entryElementStyle,
 				GUILayoutOptions::create(), false);
 		}
 

+ 2 - 0
BansheeEditor/Include/BsGUIIntField.h

@@ -18,6 +18,8 @@ namespace BansheeEngine
 
 		Event<void(INT32)> onValueChanged;
 
+		virtual Vector2I _getOptimalSize() const;
+
 	protected:
 		virtual ~GUIIntField();
 

+ 1 - 1
BansheeEditor/Source/BsGUIFieldBase.cpp

@@ -10,7 +10,7 @@ namespace BansheeEngine
 
 	GUIFieldBase::GUIFieldBase(const PrivatelyConstruct& dummy, const GUIContent& labelContent, UINT32 labelWidth,
 		const String& labelStyle, const GUILayoutOptions& layoutOptions, bool withLabel)
-		:GUIElementContainer(layoutOptions)
+		:GUIElementContainer(layoutOptions), mLabel(nullptr)
 	{
 		mLayout = &addLayoutXInternal(this);
 

+ 14 - 0
BansheeEditor/Source/BsGUIIntField.cpp

@@ -42,6 +42,20 @@ namespace BansheeEngine
 
 	}
 
+	Vector2I GUIIntField::_getOptimalSize() const
+	{
+		UINT32 width = (UINT32)mInputBox->_getOptimalSize().x;
+		UINT32 height = (UINT32)mInputBox->_getOptimalSize().y;
+
+		if (mLabel != nullptr)
+		{
+			width += mLabel->_getOptimalSize().x;
+			height = std::max(height, (UINT32)mLabel->_getOptimalSize().y);
+		}
+
+		return Vector2I(width, height);
+	}
+
 	bool GUIIntField::_hasCustomCursor(const Vector2I position, CursorType& type) const
 	{
 		RectI draggableArea;

+ 14 - 6
MBansheeEditor/Inspector/InspectableInt.cs

@@ -10,7 +10,7 @@ namespace BansheeEditor
     public class InspectableInt : InspectableObjectBase
     {
         private int oldPropertyValue;
-        private GUILabel guiLabel;
+        private GUIIntField guiIntField;
         private bool isInitialized = false;
 
         public InspectableInt(string title, SerializableProperty property)
@@ -23,8 +23,9 @@ namespace BansheeEditor
         {
             if(property.Type == SerializableProperty.FieldType.Int)
             {
-                guiLabel = new GUILabel(title);
-                layout.AddElement(guiLabel); // TODO - Use an IntEditorField
+                guiIntField = new GUIIntField(new GUIContent(title));
+                guiIntField.OnChanged += OnFieldValueChanged;
+                layout.AddElement(guiIntField); 
             }
 
             isInitialized = true;
@@ -53,13 +54,20 @@ namespace BansheeEditor
             if (!isInitialized)
                 Initialize(layout);
 
-            // TODO - Update GUI element(s) with value from property
+            // TODO - Skip update if it currently has input focus so user can modify the value in peace
+
+            guiIntField.Value = property.GetValue<int>();
+        }
+
+        private void OnFieldValueChanged(int newValue)
+        {
+            property.SetValue<int>(newValue);
         }
 
         public override void Destroy()
         {
-            if (guiLabel != null)
-                guiLabel.Destroy();
+            if (guiIntField != null)
+                guiIntField.Destroy();
 
             base.Destroy();
         }

+ 7 - 3
SBansheeEditor/Source/BsScriptGUIIntField.cpp

@@ -49,14 +49,18 @@ namespace BansheeEngine
 		GUIIntField* guiIntField = nullptr;
 		if(withTitle)
 		{
+			String titleStyleName = toString(MonoUtil::monoToWString(titleStyle));
+			String inputStyleName = toString(MonoUtil::monoToWString(inputStyle));
+
 			GUIContent nativeContent(ScriptGUIContent::getText(title), ScriptGUIContent::getImage(title), ScriptGUIContent::getTooltip(title));
 			guiIntField = GUIIntField::create(nativeContent, titleWidth, options,
-				toString(MonoUtil::monoToWString(titleStyle)),
-				toString(MonoUtil::monoToWString(inputStyle)));
+				titleStyleName, inputStyleName);
 		}
 		else
 		{
-			guiIntField = GUIIntField::create(options, toString(MonoUtil::monoToWString(inputStyle)));
+			String inputStyleName = toString(MonoUtil::monoToWString(inputStyle));
+
+			guiIntField = GUIIntField::create(options, inputStyleName);
 		}
 
 		guiIntField->onValueChanged.connect(std::bind(&ScriptGUIIntField::onChanged, instance, _1));