[Bf-blender-cvs] [381965eb568] master: UI: Activate parent when active child is collapsed

Julian Eisel noreply at git.blender.org
Wed Oct 20 12:32:18 CEST 2021


Commit: 381965eb568932b311fa23b7d8b70a7d6c1070dc
Author: Julian Eisel
Date:   Wed Oct 20 11:49:33 2021 +0200
Branches: master
https://developer.blender.org/rB381965eb568932b311fa23b7d8b70a7d6c1070dc

UI: Activate parent when active child is collapsed

Previously, when an item was active and its parent (or grand parent, etc.) was
collapsed, the active item would simply not be visible anymore. It seemed like
there was no active item. So instead, change the just collapsed parent to be
the active item then, so the active item stays visible.

===================================================================

M	source/blender/editors/include/UI_tree_view.hh
M	source/blender/editors/interface/tree_view.cc

===================================================================

diff --git a/source/blender/editors/include/UI_tree_view.hh b/source/blender/editors/include/UI_tree_view.hh
index ae85375ed2f..b1ec22c57a6 100644
--- a/source/blender/editors/include/UI_tree_view.hh
+++ b/source/blender/editors/include/UI_tree_view.hh
@@ -337,6 +337,8 @@ class AbstractTreeViewItem : public TreeViewItemContainer {
   void add_indent(uiLayout &row) const;
   void add_collapse_chevron(uiBlock &block) const;
   void add_rename_button(uiLayout &row);
+
+  bool has_active_child() const;
 };
 
 /** \} */
diff --git a/source/blender/editors/interface/tree_view.cc b/source/blender/editors/interface/tree_view.cc
index 3f3a8c5bce5..cf3ddcc3fff 100644
--- a/source/blender/editors/interface/tree_view.cc
+++ b/source/blender/editors/interface/tree_view.cc
@@ -227,6 +227,11 @@ void AbstractTreeViewItem::collapse_chevron_click_fn(struct bContext *C,
   BLI_assert(hovered_item != nullptr);
 
   hovered_item->toggle_collapsed();
+  /* When collapsing an item with an active child, make this collapsed item active instead so the
+   * active item stays visible. */
+  if (hovered_item->has_active_child()) {
+    hovered_item->activate();
+  }
 }
 
 bool AbstractTreeViewItem::is_collapse_chevron_but(const uiBut *but)
@@ -327,6 +332,18 @@ void AbstractTreeViewItem::add_rename_button(uiLayout &row)
   UI_block_layout_set_current(block, &row);
 }
 
+bool AbstractTreeViewItem::has_active_child() const
+{
+  bool found = false;
+  foreach_item_recursive([&found](const AbstractTreeViewItem &item) {
+    if (item.is_active()) {
+      found = true;
+    }
+  });
+
+  return found;
+}
+
 void AbstractTreeViewItem::on_activate()
 {
   /* Do nothing by default. */



More information about the Bf-blender-cvs mailing list