diff options
author | Hans Goudey <h.goudey@me.com> | 2021-11-20 01:36:11 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2021-11-20 01:36:11 +0300 |
commit | 01df48a983944ab3f8a6f3be926f825ac83bbc14 (patch) | |
tree | 8fab42eb2a468786351e274027faa4538ecc631a /source/blender/editors/interface/tree_view.cc | |
parent | a0780ad6253fcb9768dd3184351998effef6d178 (diff) |
Refactor: Port spreadsheet data set to UI tree view
This patch removes a bunch of specific code for drawing the spreadsheet
data set region, which was an overly specific solution for a generic UI.
Nowadays, the UI tree view API used for asset browser catalogs is a much
better way to implement this behavior.
To make this possible, the tree view API is extended in a few ways.
Collapsibility can now be turned off, and whether an item should
be active is moved to a separate virtual function.
The only visual change is that the items are now drawn in a box,
just like the asset catalog.
Differential Revision: https://developer.blender.org/D13198
Diffstat (limited to 'source/blender/editors/interface/tree_view.cc')
-rw-r--r-- | source/blender/editors/interface/tree_view.cc | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/source/blender/editors/interface/tree_view.cc b/source/blender/editors/interface/tree_view.cc index fabb2c2187a..e9d68a734d2 100644 --- a/source/blender/editors/interface/tree_view.cc +++ b/source/blender/editors/interface/tree_view.cc @@ -350,9 +350,14 @@ void AbstractTreeViewItem::on_activate() /* Do nothing by default. */ } -void AbstractTreeViewItem::is_active(IsActiveFn is_active_fn) +std::optional<bool> AbstractTreeViewItem::should_be_active() const { - is_active_fn_ = is_active_fn; + return std::nullopt; +} + +bool AbstractTreeViewItem::supports_collapsing() const +{ + return true; } std::unique_ptr<AbstractTreeViewItemDragController> AbstractTreeViewItem::create_drag_controller() @@ -504,7 +509,10 @@ void AbstractTreeViewItem::set_collapsed(bool collapsed) bool AbstractTreeViewItem::is_collapsible() const { - return !children_.is_empty(); + if (children_.is_empty()) { + return false; + } + return this->supports_collapsing(); } bool AbstractTreeViewItem::is_renaming() const @@ -546,7 +554,8 @@ uiButTreeRow *AbstractTreeViewItem::tree_row_button() void AbstractTreeViewItem::change_state_delayed() { - if (is_active_fn_ && is_active_fn_()) { + const std::optional<bool> should_be_active = this->should_be_active(); + if (should_be_active.has_value() && *should_be_active) { activate(); } } @@ -670,11 +679,24 @@ void BasicTreeViewItem::on_activate() } } -void BasicTreeViewItem::on_activate(ActivateFn fn) +void BasicTreeViewItem::set_on_activate_fn(ActivateFn fn) { activate_fn_ = fn; } +void BasicTreeViewItem::set_is_active_fn(IsActiveFn is_active_fn) +{ + is_active_fn_ = is_active_fn; +} + +std::optional<bool> BasicTreeViewItem::should_be_active() const +{ + if (is_active_fn_) { + return is_active_fn_(); + } + return std::nullopt; +} + } // namespace blender::ui using namespace blender::ui; |