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

Calculating optimal layout size now considers disabled elements
Refactored inspecto foldout so they actual remove elements instead of just hiding them

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

+ 3 - 0
BansheeEngine/Source/BsGUIElement.cpp

@@ -155,6 +155,9 @@ namespace BansheeEngine
 
 
 	Vector2I GUIElement::_calculateOptimalLayoutSize() const
 	Vector2I GUIElement::_calculateOptimalLayoutSize() const
 	{
 	{
+		if (mIsDisabled)
+			return Vector2I(0, 0);
+
 		const GUILayoutOptions& layoutOptions = _getLayoutOptions();
 		const GUILayoutOptions& layoutOptions = _getLayoutOptions();
 
 
 		UINT32 optimalWidth = 0;
 		UINT32 optimalWidth = 0;

+ 3 - 0
BansheeEngine/Source/BsGUIElementBase.cpp

@@ -72,6 +72,9 @@ namespace BansheeEngine
 
 
 	void GUIElementBase::enableRecursively()
 	void GUIElementBase::enableRecursively()
 	{
 	{
+		if (mParentElement != nullptr && mParentElement->mIsDisabled)
+			return; // Cannot enable if parent is disabled
+
 		// Make sure to mark everything as dirty, as we didn't track any dirty flags while the element was disabled
 		// Make sure to mark everything as dirty, as we didn't track any dirty flags while the element was disabled
 		mIsDisabled = false;
 		mIsDisabled = false;
 		markContentAsDirty();
 		markContentAsDirty();

+ 3 - 0
BansheeEngine/Source/BsGUILayoutX.cpp

@@ -12,6 +12,9 @@ namespace BansheeEngine
 
 
 	Vector2I GUILayoutX::_calculateOptimalLayoutSize() const
 	Vector2I GUILayoutX::_calculateOptimalLayoutSize() const
 	{
 	{
+		if (mIsDisabled)
+			return Vector2I(0, 0);
+
 		UINT32 optimalWidth = 0;
 		UINT32 optimalWidth = 0;
 		UINT32 optimalHeight = 0;
 		UINT32 optimalHeight = 0;
 
 

+ 3 - 0
BansheeEngine/Source/BsGUILayoutY.cpp

@@ -12,6 +12,9 @@ namespace BansheeEngine
 
 
 	Vector2I GUILayoutY::_calculateOptimalLayoutSize() const
 	Vector2I GUILayoutY::_calculateOptimalLayoutSize() const
 	{
 	{
+		if (mIsDisabled)
+			return Vector2I(0, 0);
+
 		UINT32 optimalWidth = 0;
 		UINT32 optimalWidth = 0;
 		UINT32 optimalHeight = 0;
 		UINT32 optimalHeight = 0;
 
 

+ 18 - 17
MBansheeEditor/Inspector/InspectableArray.cs

@@ -137,34 +137,35 @@ namespace BansheeEditor
                 guiTitleLayout.AddElement(guiResizeBtn);
                 guiTitleLayout.AddElement(guiResizeBtn);
                 guiTitleLayout.AddElement(guiClearBtn);
                 guiTitleLayout.AddElement(guiClearBtn);
 
 
-                guiChildLayout = layout.AddLayoutX(layoutIndex);
-                guiChildLayout.SetVisible(isExpanded);
-                guiChildLayout.AddSpace(IndentAmount);
-
-                GUILayoutY guiContentLayout = guiChildLayout.AddLayoutY();
                 SerializableArray array = property.GetArray();
                 SerializableArray array = property.GetArray();
-
                 numArrayElements = array.GetLength();
                 numArrayElements = array.GetLength();
-                for (int i = 0; i < numArrayElements; i++)
+                guiSizeField.Value = numArrayElements;
+
+                if (isExpanded)
                 {
                 {
-                    EntryRow newRow = new EntryRow(guiContentLayout, i, this);
-                    rows.Add(newRow);
+                    guiChildLayout = layout.AddLayoutX(layoutIndex);
+                    guiChildLayout.AddSpace(IndentAmount);
 
 
-                    InspectableObjectBase childObj = CreateDefaultInspectable(i + ".", new InspectableFieldLayout(newRow.contentLayout), array.GetProperty(i));
-                    AddChild(childObj);
+                    GUILayoutY guiContentLayout = guiChildLayout.AddLayoutY();
 
 
-                    childObj.Refresh(0);
-                }
+                    for (int i = 0; i < numArrayElements; i++)
+                    {
+                        EntryRow newRow = new EntryRow(guiContentLayout, i, this);
+                        rows.Add(newRow);
 
 
-                guiSizeField.Value = numArrayElements;
+                        InspectableObjectBase childObj = CreateDefaultInspectable(i + ".", new InspectableFieldLayout(newRow.contentLayout), array.GetProperty(i));
+                        AddChild(childObj);
+
+                        childObj.Refresh(0);
+                    }
+                }
+                else
+                    guiChildLayout = null;
             }
             }
         }
         }
 
 
         private void OnFoldoutToggled(bool expanded)
         private void OnFoldoutToggled(bool expanded)
         {
         {
-            if (guiChildLayout != null)
-                guiChildLayout.SetVisible(expanded);
-
             isExpanded = expanded;
             isExpanded = expanded;
             forceUpdate = true;
             forceUpdate = true;
         }
         }

+ 18 - 17
MBansheeEditor/Inspector/InspectableList.cs

@@ -135,34 +135,35 @@ namespace BansheeEditor
                 guiTitleLayout.AddElement(guiResizeBtn);
                 guiTitleLayout.AddElement(guiResizeBtn);
                 guiTitleLayout.AddElement(guiClearBtn);
                 guiTitleLayout.AddElement(guiClearBtn);
 
 
-                guiChildLayout = layout.AddLayoutX(layoutIndex);
-                guiChildLayout.SetVisible(isExpanded);
-                guiChildLayout.AddSpace(IndentAmount);
-
-                GUILayoutY guiContentLayout = guiChildLayout.AddLayoutY();
                 SerializableList list = property.GetList();
                 SerializableList list = property.GetList();
-
                 numArrayElements = list.GetLength();
                 numArrayElements = list.GetLength();
-                for (int i = 0; i < numArrayElements; i++)
+                guiSizeField.Value = numArrayElements;
+
+                if (isExpanded)
                 {
                 {
-                    EntryRow newRow = new EntryRow(guiContentLayout, i, this);
-                    rows.Add(newRow);
+                    guiChildLayout = layout.AddLayoutX(layoutIndex);
+                    guiChildLayout.AddSpace(IndentAmount);
 
 
-                    InspectableObjectBase childObj = CreateDefaultInspectable(i + ".", new InspectableFieldLayout(newRow.contentLayout), list.GetProperty(i));
-                    AddChild(childObj);
+                    GUILayoutY guiContentLayout = guiChildLayout.AddLayoutY();
 
 
-                    childObj.Refresh(0);
-                }
+                    for (int i = 0; i < numArrayElements; i++)
+                    {
+                        EntryRow newRow = new EntryRow(guiContentLayout, i, this);
+                        rows.Add(newRow);
 
 
-                guiSizeField.Value = numArrayElements;
+                        InspectableObjectBase childObj = CreateDefaultInspectable(i + ".", new InspectableFieldLayout(newRow.contentLayout), list.GetProperty(i));
+                        AddChild(childObj);
+
+                        childObj.Refresh(0);
+                    }
+                }
+                else
+                    guiChildLayout = null;
             }
             }
         }
         }
 
 
         private void OnFoldoutToggled(bool expanded)
         private void OnFoldoutToggled(bool expanded)
         {
         {
-            if (guiChildLayout != null)
-                guiChildLayout.SetVisible(expanded);
-
             isExpanded = expanded;
             isExpanded = expanded;
             forceUpdate = true;
             forceUpdate = true;
         }
         }

+ 19 - 19
MBansheeEditor/Inspector/InspectableObject.cs

@@ -74,32 +74,32 @@ namespace BansheeEditor
                 clearBtn.OnClick += OnClearButtonClicked;
                 clearBtn.OnClick += OnClearButtonClicked;
                 guiTitleLayout.AddElement(clearBtn);
                 guiTitleLayout.AddElement(clearBtn);
 
 
-                guiChildLayout = layout.AddLayoutX(index);
-                guiChildLayout.SetVisible(isExpanded);
-                guiChildLayout.AddSpace(IndentAmount);
-
-                GUILayoutY guiContentLayout = guiChildLayout.AddLayoutY();
-
-                SerializableObject serializableObject = property.GetObject();
-
-                foreach (var field in serializableObject.fields)
+                if (isExpanded)
                 {
                 {
-                    if (!field.Inspectable)
-                        continue;
-
-                    if (field.HasCustomInspector)
-                        AddChild(CreateCustomInspectable(field.CustomInspectorType, field.Name, new InspectableFieldLayout(guiContentLayout), field.GetProperty()));
-                    else
-                        AddChild(CreateDefaultInspectable(field.Name, new InspectableFieldLayout(guiContentLayout), field.GetProperty()));
+                    guiChildLayout = layout.AddLayoutX(index);
+                    guiChildLayout.AddSpace(IndentAmount);
+
+                    GUILayoutY guiContentLayout = guiChildLayout.AddLayoutY();
+
+                    SerializableObject serializableObject = property.GetObject();
+                    foreach (var field in serializableObject.fields)
+                    {
+                        if (!field.Inspectable)
+                            continue;
+
+                        if (field.HasCustomInspector)
+                            AddChild(CreateCustomInspectable(field.CustomInspectorType, field.Name, new InspectableFieldLayout(guiContentLayout), field.GetProperty()));
+                        else
+                            AddChild(CreateDefaultInspectable(field.Name, new InspectableFieldLayout(guiContentLayout), field.GetProperty()));
+                    }
                 }
                 }
+                else
+                    guiChildLayout = null;
             }
             }
         }
         }
 
 
         private void OnFoldoutToggled(bool expanded)
         private void OnFoldoutToggled(bool expanded)
         {
         {
-            if (guiChildLayout != null)
-                guiChildLayout.SetVisible(expanded);
-
             isExpanded = expanded;
             isExpanded = expanded;
             forceUpdate = true;
             forceUpdate = true;
         }
         }