浏览代码

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

Eugene Kozlov 8 年之前
父节点
当前提交
abf556c66a
共有 1 个文件被更改,包括 7 次插入2 次删除
  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