Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Eisel <julian@blender.org>2021-10-04 17:17:59 +0300
committerJulian Eisel <julian@blender.org>2021-10-04 18:03:12 +0300
commit2b6f2072f1eecd43080821bb7b55f5313f890ddb (patch)
tree54ec409e85c4322e5968a7cf3be457c29af897d0 /source/blender/editors/interface
parent4fd7ce321d7352570a5cbb08d66b1c635d234689 (diff)
UI Tree-View API: Enforce active item to be un-collapsed
Makes sure that the active item of a tree never has collapsed parent items, which can be confusing if it happens. E.g. for the asset catalogs UI, the active catalog decides which assets are visible. Having it hidden while being the main factor deciding which assets are visible is quite confusing. I think it makes sense to have this at the UI Tree-View level, rather than doing it manually in the asset catalog code for example. Seems like something you'd commonly want. We can make it optional in the API if needed. Renamed the `set_active()` function to make clear that it is more than a mere setter.
Diffstat (limited to 'source/blender/editors/interface')
-rw-r--r--source/blender/editors/interface/tree_view.cc32
1 files changed, 25 insertions, 7 deletions
diff --git a/source/blender/editors/interface/tree_view.cc b/source/blender/editors/interface/tree_view.cc
index 0ea15a2a5bb..202e3dba2ab 100644
--- a/source/blender/editors/interface/tree_view.cc
+++ b/source/blender/editors/interface/tree_view.cc
@@ -184,14 +184,25 @@ int AbstractTreeViewItem::count_parents() const
return i;
}
-void AbstractTreeViewItem::set_active(bool value)
+void AbstractTreeViewItem::activate()
{
- if (value && !is_active()) {
- /* Deactivate other items in the tree. */
- get_tree_view().foreach_item([](auto &item) { item.set_active(false); });
- on_activate();
+ if (is_active()) {
+ return;
}
- is_active_ = value;
+
+ /* Deactivate other items in the tree. */
+ get_tree_view().foreach_item([](auto &item) { item.deactivate(); });
+
+ on_activate();
+ /* Make sure the active item is always visible. */
+ ensure_parents_uncollapsed();
+
+ is_active_ = true;
+}
+
+void AbstractTreeViewItem::deactivate()
+{
+ is_active_ = false;
}
bool AbstractTreeViewItem::is_active() const
@@ -219,6 +230,13 @@ bool AbstractTreeViewItem::is_collapsible() const
return !children_.is_empty();
}
+void AbstractTreeViewItem::ensure_parents_uncollapsed()
+{
+ for (AbstractTreeViewItem *parent = parent_; parent; parent = parent->parent_) {
+ parent->set_collapsed(false);
+ }
+}
+
/* ---------------------------------------------------------------------- */
TreeViewBuilder::TreeViewBuilder(uiBlock &block) : block_(block)
@@ -277,7 +295,7 @@ static void tree_row_click_fn(struct bContext *UNUSED(C), void *but_arg1, void *
if (tree_item.is_collapsed() || tree_item.is_active()) {
tree_item.toggle_collapsed();
}
- tree_item.set_active();
+ tree_item.activate();
}
void BasicTreeViewItem::build_row(uiLayout &row)