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

Properly rebuild all list/dictionary rows when they need refresh
Add/remove rows when list/array size changes

BearishSun 10 лет назад
Родитель
Сommit
a29f7f1376
2 измененных файлов с 24 добавлено и 14 удалено
  1. 7 9
      MBansheeEditor/GUI/GUIDictionaryField.cs
  2. 17 5
      MBansheeEditor/GUI/GUIListField.cs

+ 7 - 9
MBansheeEditor/GUI/GUIDictionaryField.cs

@@ -198,7 +198,7 @@ namespace BansheeEditor
             if (!IsNull())
             {
                 editRow.BuildGUI(this, guiContentLayout, rows.Count, depth + 1);
-                editRow.Enabled = false;
+                editRow.Enabled = editRowIdx == rows.Count;
 
                 foreach (var KVP in rows)
                     KVP.Value.BuildGUI(this, guiContentLayout, KVP.Key, depth + 1);
@@ -223,18 +223,16 @@ namespace BansheeEditor
         /// </summary>
         public void Refresh()
         {
+            bool anythingModified = false;
             for (int i = 0; i < rows.Count; i++)
-            {
-                if (rows[i].Refresh())
-                    rows[i].BuildGUI(this, guiContentLayout, i, depth + 1);
-            }
+                anythingModified |= rows[i].Refresh();
 
             if (editRow != null && editRow.Enabled)
-            {
-                if (editRow.Refresh())
-                    editRow.BuildGUI(this, guiContentLayout, rows.Count, depth + 1);
-            }
+                anythingModified |= editRow.Refresh();
 
+            // Note: I could just rebuild the individual rows but I'd have to remember their layout positions
+            if (anythingModified)
+                BuildRows();
         }
 
         /// <summary>

+ 17 - 5
MBansheeEditor/GUI/GUIListField.cs

@@ -210,11 +210,13 @@ namespace BansheeEditor
         /// </summary>
         public void Refresh()
         {
+            bool requiresRebuild = false;
             for (int i = 0; i < rows.Count; i++)
-            {
-                if (rows[i].Refresh())
-                    rows[i].BuildGUI(this, guiContentLayout, i, depth);
-            }
+                requiresRebuild |= rows[i].Refresh();
+
+            // Note: I could just rebuild the individual rows but I'd have to remember their layout positions
+            if (requiresRebuild)
+                BuildRows();
         }
 
         /// <summary>
@@ -301,6 +303,16 @@ namespace BansheeEditor
         {
             ResizeList();
 
+            int numRows = GetNumRows();
+            for (int i = numRows; i < rows.Count;)
+            {
+                rows[i].Destroy();
+                rows.RemoveAt(i);
+            }
+
+            for (int i = rows.Count; i < numRows; i++)
+                rows.Add(CreateRow());
+
             BuildRows();
         }
 
@@ -914,7 +926,7 @@ namespace BansheeEditor
         /// <summary>
         /// Refreshes the GUI for the list row and checks if anything was modified.
         /// </summary>
-        /// <returns>True if any modifications were made, false otherwise.</returns>
+        /// <returns>True if the row requires a rebuild, false otherwise.</returns>
         internal protected virtual bool Refresh()
         {
             return false;