Przeglądaj źródła

Properly change toggle button state when expanding/collapsing list or dictionary elements externally

BearishSun 9 lat temu
rodzic
commit
0a598268ff

+ 19 - 10
Source/MBansheeEditor/GUI/GUIDictionaryField.cs

@@ -26,6 +26,8 @@ namespace BansheeEditor
         protected GUILayoutX guiTitleLayout;
         protected GUILayoutX guiInternalTitleLayout;
         protected GUILayoutY guiContentLayout;
+        protected GUIToggle guiFoldout;
+
         protected bool isExpanded;
         protected int depth;
         protected LocString title;
@@ -47,7 +49,7 @@ namespace BansheeEditor
             set
             {
                 if (isExpanded != value)
-                    ToggleFoldout(value);
+                    ToggleFoldout(value, true);
             }
         }
 
@@ -136,9 +138,9 @@ namespace BansheeEditor
             {
                 guiInternalTitleLayout = guiTitleLayout.InsertLayoutX(0);
 
-                GUIToggle guiFoldout = new GUIToggle(title, EditorStyles.Foldout);
+                guiFoldout = new GUIToggle(title, EditorStyles.Foldout);
                 guiFoldout.Value = isExpanded;
-                guiFoldout.OnToggled += ToggleFoldout;
+                guiFoldout.OnToggled += x => ToggleFoldout(x, false);
 
                 GUIContent clearIcon = new GUIContent(EditorBuiltin.GetInspectorWindowIcon(InspectorWindowIcon.Clear), 
                     new LocEdString("Clear"));
@@ -176,7 +178,7 @@ namespace BansheeEditor
                 GUITexture inspectorContentBg = new GUITexture(null, bgPanelStyle);
                 backgroundPanel.AddElement(inspectorContentBg);
 
-                ToggleFoldout(isExpanded);
+                ToggleFoldout(isExpanded, false);
             };
 
             if (state == State.None)
@@ -457,13 +459,20 @@ namespace BansheeEditor
         /// Hides or shows the dictionary rows.
         /// </summary>
         /// <param name="expanded">True if the rows should be displayed, false otherwise.</param>
-        private void ToggleFoldout(bool expanded)
+        /// <param name="external">True if the foldout was expanded/collapsed from outside code.</param>
+        private void ToggleFoldout(bool expanded, bool external)
         {
             isExpanded = expanded;
 
             if (guiChildLayout != null)
                 guiChildLayout.Active = isExpanded && (rows.Count > 0 || IsEditInProgress());
 
+            if (external)
+            {
+                if (guiFoldout != null)
+                    guiFoldout.Value = isExpanded;
+            }
+
             if (OnExpand != null)
                 OnExpand(expanded);
         }
@@ -513,7 +522,7 @@ namespace BansheeEditor
             else
             {
                 if (!isExpanded)
-                    ToggleFoldout(true);
+                    ToggleFoldout(true, true);
 
                 StartAdd();
             }
@@ -657,7 +666,7 @@ namespace BansheeEditor
             editRow.Enabled = true;
             editRow.EditMode = true;
 
-            ToggleFoldout(isExpanded);
+            ToggleFoldout(isExpanded, false);
         }
 
         /// <summary>
@@ -679,7 +688,7 @@ namespace BansheeEditor
             editRow.Enabled = true;
             editRow.EditMode = true;
 
-            ToggleFoldout(isExpanded);
+            ToggleFoldout(isExpanded, false);
         }
 
         /// <summary>
@@ -733,7 +742,7 @@ namespace BansheeEditor
                 editOriginalKey = null;
                 editRowIdx = -1;
 
-                ToggleFoldout(isExpanded);
+                ToggleFoldout(isExpanded, false);
                 isModified = true;
 
                 return true;
@@ -763,7 +772,7 @@ namespace BansheeEditor
                 editRow.Enabled = false;
                 editRowIdx = -1;
 
-                ToggleFoldout(isExpanded);
+                ToggleFoldout(isExpanded, false);
             }
         }
 

+ 12 - 4
Source/MBansheeEditor/GUI/GUIListField.cs

@@ -25,6 +25,7 @@ namespace BansheeEditor
         protected GUILayoutX guiTitleLayout;
         protected GUILayoutX guiInternalTitleLayout;
         protected GUILayoutY guiContentLayout;
+        protected GUIToggle guiFoldout;
 
         protected bool isExpanded;
         protected int depth;
@@ -42,7 +43,7 @@ namespace BansheeEditor
             set
             {
                 if (isExpanded != value)
-                    ToggleFoldout(value);
+                    ToggleFoldout(value, true);
             }
         }
 
@@ -131,9 +132,9 @@ namespace BansheeEditor
             {
                 guiInternalTitleLayout = guiTitleLayout.InsertLayoutX(0);
 
-                GUIToggle guiFoldout = new GUIToggle(title, EditorStyles.Foldout);
+                guiFoldout = new GUIToggle(title, EditorStyles.Foldout);
                 guiFoldout.Value = isExpanded;
-                guiFoldout.OnToggled += ToggleFoldout;
+                guiFoldout.OnToggled += x => ToggleFoldout(x, false);
                 guiSizeField = new GUIIntField("", GUIOption.FixedWidth(50));
                 guiSizeField.SetRange(0, int.MaxValue);
 
@@ -302,13 +303,20 @@ namespace BansheeEditor
         /// Triggered when the user clicks on the expand/collapse toggle in the title bar.
         /// </summary>
         /// <param name="expanded">Determines whether the contents were expanded or collapsed.</param>
-        private void ToggleFoldout(bool expanded)
+        /// <param name="external">True if the foldout was expanded/collapsed from outside code.</param>
+        private void ToggleFoldout(bool expanded, bool external)
         {
             isExpanded = expanded;
 
             if (guiChildLayout != null)
                 guiChildLayout.Active = isExpanded;
 
+            if (external)
+            {
+                if (guiFoldout != null)
+                    guiFoldout.Value = isExpanded;
+            }
+
             if (OnExpand != null)
                 OnExpand(expanded);
         }