Ver Fonte

Hide added item in hierarchy ListView if parent item is collapsed.

Eugene Kozlov há 8 anos atrás
pai
commit
abf556c66a
1 ficheiros alterados com 7 adições e 2 exclusões
  1. 7 2
      Source/Urho3D/UI/ListView.cpp

+ 7 - 2
Source/Urho3D/UI/ListView.cpp

@@ -358,7 +358,7 @@ void ListView::InsertItem(unsigned index, UIElement* item, UIElement* parentItem
     item->SetEnabled(true);
     item->SetSelected(false);
 
-    unsigned numItems = contentElement_->GetNumChildren();
+    const unsigned numItems = contentElement_->GetNumChildren();
     if (hierarchyMode_)
     {
         int baseIndent = baseIndent_;
@@ -367,8 +367,13 @@ void ListView::InsertItem(unsigned index, UIElement* item, UIElement* parentItem
             baseIndent = parentItem->GetIndent();
             SetItemHierarchyParent(parentItem, true);
 
+            // Hide item if parent is collapsed
+            const unsigned parentIndex = FindItem(parentItem);
+            if (!IsExpanded(parentIndex))
+                item->SetVisible(false);
+
             // Adjust the index to ensure it is within the children index limit of the parent item
-            unsigned indexLimit = FindItem(parentItem);
+            unsigned indexLimit = parentIndex;
             if (index <= indexLimit)
                 index = indexLimit + 1;
             else