2022-02-11 09:07:11 +11:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
2021-09-23 18:56:29 +02:00
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
|
* \ingroup edinterface
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "DNA_userdef_types.h"
|
2021-10-07 14:59:43 +02:00
|
|
|
#include "DNA_windowmanager_types.h"
|
2021-09-23 18:56:29 +02:00
|
|
|
|
2021-10-06 14:18:12 +02:00
|
|
|
#include "BKE_context.h"
|
|
|
|
|
|
2021-09-30 16:26:56 +02:00
|
|
|
#include "BLT_translation.h"
|
|
|
|
|
|
2022-11-26 00:21:17 -06:00
|
|
|
#include "interface_intern.hh"
|
2021-09-23 18:56:29 +02:00
|
|
|
|
|
|
|
|
#include "UI_interface.h"
|
|
|
|
|
|
2021-10-27 14:48:00 +02:00
|
|
|
#include "WM_api.h"
|
2021-10-07 14:59:43 +02:00
|
|
|
#include "WM_types.h"
|
|
|
|
|
|
2021-09-23 18:56:29 +02:00
|
|
|
#include "UI_tree_view.hh"
|
|
|
|
|
|
|
|
|
|
namespace blender::ui {
|
|
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
|
|
/**
|
2021-12-09 00:55:11 +11:00
|
|
|
* Add a tree-item to the container. This is the only place where items should be added, it
|
|
|
|
|
* handles important invariants!
|
2021-09-23 18:56:29 +02:00
|
|
|
*/
|
|
|
|
|
AbstractTreeViewItem &TreeViewItemContainer::add_tree_item(
|
|
|
|
|
std::unique_ptr<AbstractTreeViewItem> item)
|
|
|
|
|
{
|
|
|
|
|
children_.append(std::move(item));
|
|
|
|
|
|
|
|
|
|
/* The first item that will be added to the root sets this. */
|
|
|
|
|
if (root_ == nullptr) {
|
|
|
|
|
root_ = this;
|
|
|
|
|
}
|
UI: Port view item features to base class, merge view item button types
No user visible changes expected.
Merges the tree row and grid tile button types, which were mostly doing
the same things. The idea is that there is a button type for
highlighting, as well as supporting general view item features (e.g.
renaming, drag/drop, etc.). So instead there is a view item button type
now. Also ports view item features like renaming, custom context menus,
drag controllers and drop controllers to `ui::AbstractViewItem` (the new
base class for all view items).
This should be quite an improvement because:
- Merges code that was duplicated over view items.
- Mentioned features (renaming, drag & drop, ...) are much easier to
implement in new view types now. Most of it comes "for free".
- Further features will immediately become availalbe to all views (e.g.
selection).
- Simplifies APIs, there don't have to be functions for individual view
item types anymore.
- View item classes are split and thus less overwhelming visually.
- View item buttons now share all code (drawing, handling, etc.)
- We're soon running out of available button types, this commit merges
two into one.
I was hoping I could do this in multiple smaller commits, but things
were quite intertwined so that would've taken quite some effort.
2022-07-19 16:14:42 +02:00
|
|
|
AbstractTreeView &tree_view = static_cast<AbstractTreeView &>(*root_);
|
2021-09-23 18:56:29 +02:00
|
|
|
AbstractTreeViewItem &added_item = *children_.last();
|
|
|
|
|
added_item.root_ = root_;
|
UI: Port view item features to base class, merge view item button types
No user visible changes expected.
Merges the tree row and grid tile button types, which were mostly doing
the same things. The idea is that there is a button type for
highlighting, as well as supporting general view item features (e.g.
renaming, drag/drop, etc.). So instead there is a view item button type
now. Also ports view item features like renaming, custom context menus,
drag controllers and drop controllers to `ui::AbstractViewItem` (the new
base class for all view items).
This should be quite an improvement because:
- Merges code that was duplicated over view items.
- Mentioned features (renaming, drag & drop, ...) are much easier to
implement in new view types now. Most of it comes "for free".
- Further features will immediately become availalbe to all views (e.g.
selection).
- Simplifies APIs, there don't have to be functions for individual view
item types anymore.
- View item classes are split and thus less overwhelming visually.
- View item buttons now share all code (drawing, handling, etc.)
- We're soon running out of available button types, this commit merges
two into one.
I was hoping I could do this in multiple smaller commits, but things
were quite intertwined so that would've taken quite some effort.
2022-07-19 16:14:42 +02:00
|
|
|
tree_view.register_item(added_item);
|
|
|
|
|
|
2021-09-23 18:56:29 +02:00
|
|
|
if (root_ != this) {
|
|
|
|
|
/* Any item that isn't the root can be assumed to the a #AbstractTreeViewItem. Not entirely
|
|
|
|
|
* nice to static_cast this, but well... */
|
|
|
|
|
added_item.parent_ = static_cast<AbstractTreeViewItem *>(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return added_item;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TreeViewItemContainer::foreach_item_recursive(ItemIterFn iter_fn, IterOptions options) const
|
|
|
|
|
{
|
2021-09-24 10:25:16 +02:00
|
|
|
for (const auto &child : children_) {
|
2021-09-23 18:56:29 +02:00
|
|
|
iter_fn(*child);
|
|
|
|
|
if (bool(options & IterOptions::SkipCollapsed) && child->is_collapsed()) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
child->foreach_item_recursive(iter_fn, options);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
|
|
void AbstractTreeView::foreach_item(ItemIterFn iter_fn, IterOptions options) const
|
|
|
|
|
{
|
|
|
|
|
foreach_item_recursive(iter_fn, options);
|
|
|
|
|
}
|
|
|
|
|
|
UI: Add AbstractView base class for views, unify reconstruction in there
No user visible changes expected.
There's plenty of duplicated code in the grid and the tree view, and I expect
this to become more. This starts the process of unifying these parts, which
should also make it easier to add new views. Complexity in the view classes is
reduced, and some type shenanigans for C compatibility and general view
management can be removed, since there is now a common base type.
For the start this ports some of the view reconstruction, where the view and
its items are compared to the version of itself in the previous redraw, so that
state (highlighted, active, renaming, collapsed, ...) can be preserved.
Notifier listening is also ported.
2022-07-02 21:49:21 +02:00
|
|
|
void AbstractTreeView::update_children_from_old(const AbstractView &old_view)
|
2021-09-23 18:56:29 +02:00
|
|
|
{
|
2022-07-02 22:36:50 +02:00
|
|
|
const AbstractTreeView &old_tree_view = dynamic_cast<const AbstractTreeView &>(old_view);
|
2021-10-05 16:01:01 +02:00
|
|
|
|
UI: Add AbstractView base class for views, unify reconstruction in there
No user visible changes expected.
There's plenty of duplicated code in the grid and the tree view, and I expect
this to become more. This starts the process of unifying these parts, which
should also make it easier to add new views. Complexity in the view classes is
reduced, and some type shenanigans for C compatibility and general view
management can be removed, since there is now a common base type.
For the start this ports some of the view reconstruction, where the view and
its items are compared to the version of itself in the previous redraw, so that
state (highlighted, active, renaming, collapsed, ...) can be preserved.
Notifier listening is also ported.
2022-07-02 21:49:21 +02:00
|
|
|
update_children_from_old_recursive(*this, old_tree_view);
|
2021-09-23 18:56:29 +02:00
|
|
|
}
|
|
|
|
|
|
2021-12-09 12:07:34 +01:00
|
|
|
void AbstractTreeView::update_children_from_old_recursive(const TreeViewOrItem &new_items,
|
|
|
|
|
const TreeViewOrItem &old_items)
|
2021-09-23 18:56:29 +02:00
|
|
|
{
|
|
|
|
|
for (const auto &new_item : new_items.children_) {
|
|
|
|
|
AbstractTreeViewItem *matching_old_item = find_matching_child(*new_item, old_items);
|
|
|
|
|
if (!matching_old_item) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
new_item->update_from_old(*matching_old_item);
|
|
|
|
|
|
|
|
|
|
/* Recurse into children of the matched item. */
|
|
|
|
|
update_children_from_old_recursive(*new_item, *matching_old_item);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AbstractTreeViewItem *AbstractTreeView::find_matching_child(
|
2021-12-09 12:07:34 +01:00
|
|
|
const AbstractTreeViewItem &lookup_item, const TreeViewOrItem &items)
|
2021-09-23 18:56:29 +02:00
|
|
|
{
|
|
|
|
|
for (const auto &iter_item : items.children_) {
|
UI: Port view item features to base class, merge view item button types
No user visible changes expected.
Merges the tree row and grid tile button types, which were mostly doing
the same things. The idea is that there is a button type for
highlighting, as well as supporting general view item features (e.g.
renaming, drag/drop, etc.). So instead there is a view item button type
now. Also ports view item features like renaming, custom context menus,
drag controllers and drop controllers to `ui::AbstractViewItem` (the new
base class for all view items).
This should be quite an improvement because:
- Merges code that was duplicated over view items.
- Mentioned features (renaming, drag & drop, ...) are much easier to
implement in new view types now. Most of it comes "for free".
- Further features will immediately become availalbe to all views (e.g.
selection).
- Simplifies APIs, there don't have to be functions for individual view
item types anymore.
- View item classes are split and thus less overwhelming visually.
- View item buttons now share all code (drawing, handling, etc.)
- We're soon running out of available button types, this commit merges
two into one.
I was hoping I could do this in multiple smaller commits, but things
were quite intertwined so that would've taken quite some effort.
2022-07-19 16:14:42 +02:00
|
|
|
if (lookup_item.matches_single(*iter_item)) {
|
2021-09-23 18:56:29 +02:00
|
|
|
/* We have a matching item! */
|
|
|
|
|
return iter_item.get();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-05 16:01:01 +02:00
|
|
|
void AbstractTreeView::change_state_delayed()
|
|
|
|
|
{
|
|
|
|
|
BLI_assert_msg(
|
|
|
|
|
is_reconstructed(),
|
|
|
|
|
"These state changes are supposed to be delayed until reconstruction is completed");
|
|
|
|
|
foreach_item([](AbstractTreeViewItem &item) { item.change_state_delayed(); });
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-23 18:56:29 +02:00
|
|
|
/* ---------------------------------------------------------------------- */
|
|
|
|
|
|
2021-10-06 14:18:12 +02:00
|
|
|
void AbstractTreeViewItem::tree_row_click_fn(struct bContext * /*C*/,
|
|
|
|
|
void *but_arg1,
|
|
|
|
|
void * /*arg2*/)
|
|
|
|
|
{
|
UI: Port view item features to base class, merge view item button types
No user visible changes expected.
Merges the tree row and grid tile button types, which were mostly doing
the same things. The idea is that there is a button type for
highlighting, as well as supporting general view item features (e.g.
renaming, drag/drop, etc.). So instead there is a view item button type
now. Also ports view item features like renaming, custom context menus,
drag controllers and drop controllers to `ui::AbstractViewItem` (the new
base class for all view items).
This should be quite an improvement because:
- Merges code that was duplicated over view items.
- Mentioned features (renaming, drag & drop, ...) are much easier to
implement in new view types now. Most of it comes "for free".
- Further features will immediately become availalbe to all views (e.g.
selection).
- Simplifies APIs, there don't have to be functions for individual view
item types anymore.
- View item classes are split and thus less overwhelming visually.
- View item buttons now share all code (drawing, handling, etc.)
- We're soon running out of available button types, this commit merges
two into one.
I was hoping I could do this in multiple smaller commits, but things
were quite intertwined so that would've taken quite some effort.
2022-07-19 16:14:42 +02:00
|
|
|
uiButViewItem *item_but = (uiButViewItem *)but_arg1;
|
|
|
|
|
AbstractTreeViewItem &tree_item = reinterpret_cast<AbstractTreeViewItem &>(*item_but->view_item);
|
2021-10-06 14:18:12 +02:00
|
|
|
|
|
|
|
|
tree_item.activate();
|
2021-12-02 19:40:36 +01:00
|
|
|
/* Not only activate the item, also show its children. Maybe this should be optional, or
|
|
|
|
|
* controlled by the specific tree-view. */
|
|
|
|
|
tree_item.set_collapsed(false);
|
2021-10-06 14:18:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AbstractTreeViewItem::add_treerow_button(uiBlock &block)
|
|
|
|
|
{
|
2021-10-07 14:59:43 +02:00
|
|
|
/* For some reason a width > (UI_UNIT_X * 2) make the layout system use all available width. */
|
UI: Port view item features to base class, merge view item button types
No user visible changes expected.
Merges the tree row and grid tile button types, which were mostly doing
the same things. The idea is that there is a button type for
highlighting, as well as supporting general view item features (e.g.
renaming, drag/drop, etc.). So instead there is a view item button type
now. Also ports view item features like renaming, custom context menus,
drag controllers and drop controllers to `ui::AbstractViewItem` (the new
base class for all view items).
This should be quite an improvement because:
- Merges code that was duplicated over view items.
- Mentioned features (renaming, drag & drop, ...) are much easier to
implement in new view types now. Most of it comes "for free".
- Further features will immediately become availalbe to all views (e.g.
selection).
- Simplifies APIs, there don't have to be functions for individual view
item types anymore.
- View item classes are split and thus less overwhelming visually.
- View item buttons now share all code (drawing, handling, etc.)
- We're soon running out of available button types, this commit merges
two into one.
I was hoping I could do this in multiple smaller commits, but things
were quite intertwined so that would've taken quite some effort.
2022-07-19 16:14:42 +02:00
|
|
|
view_item_but_ = (uiButViewItem *)uiDefBut(
|
|
|
|
|
&block, UI_BTYPE_VIEW_ITEM, 0, "", 0, 0, UI_UNIT_X * 10, UI_UNIT_Y, nullptr, 0, 0, 0, 0, "");
|
2021-10-06 14:18:12 +02:00
|
|
|
|
UI: Port view item features to base class, merge view item button types
No user visible changes expected.
Merges the tree row and grid tile button types, which were mostly doing
the same things. The idea is that there is a button type for
highlighting, as well as supporting general view item features (e.g.
renaming, drag/drop, etc.). So instead there is a view item button type
now. Also ports view item features like renaming, custom context menus,
drag controllers and drop controllers to `ui::AbstractViewItem` (the new
base class for all view items).
This should be quite an improvement because:
- Merges code that was duplicated over view items.
- Mentioned features (renaming, drag & drop, ...) are much easier to
implement in new view types now. Most of it comes "for free".
- Further features will immediately become availalbe to all views (e.g.
selection).
- Simplifies APIs, there don't have to be functions for individual view
item types anymore.
- View item classes are split and thus less overwhelming visually.
- View item buttons now share all code (drawing, handling, etc.)
- We're soon running out of available button types, this commit merges
two into one.
I was hoping I could do this in multiple smaller commits, but things
were quite intertwined so that would've taken quite some effort.
2022-07-19 16:14:42 +02:00
|
|
|
view_item_but_->view_item = reinterpret_cast<uiViewItemHandle *>(this);
|
|
|
|
|
UI_but_func_set(&view_item_but_->but, tree_row_click_fn, view_item_but_, nullptr);
|
2021-10-07 14:59:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AbstractTreeViewItem::add_indent(uiLayout &row) const
|
|
|
|
|
{
|
|
|
|
|
uiBlock *block = uiLayoutGetBlock(&row);
|
|
|
|
|
uiLayout *subrow = uiLayoutRow(&row, true);
|
|
|
|
|
uiLayoutSetFixedSize(subrow, true);
|
|
|
|
|
|
|
|
|
|
const float indent_size = count_parents() * UI_DPI_ICON_SIZE;
|
2021-10-08 01:24:12 +11:00
|
|
|
uiDefBut(block, UI_BTYPE_SEPR, 0, "", 0, 0, indent_size, 0, nullptr, 0.0, 0.0, 0, 0, "");
|
2021-10-07 14:59:43 +02:00
|
|
|
|
|
|
|
|
/* Indent items without collapsing icon some more within their parent. Makes it clear that they
|
|
|
|
|
* are actually nested and not just a row at the same level without a chevron. */
|
|
|
|
|
if (!is_collapsible() && parent_) {
|
2021-10-08 01:24:12 +11:00
|
|
|
uiDefBut(block, UI_BTYPE_SEPR, 0, "", 0, 0, 0.2f * UI_UNIT_X, 0, nullptr, 0.0, 0.0, 0, 0, "");
|
2021-10-07 14:59:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Restore. */
|
|
|
|
|
UI_block_layout_set_current(block, &row);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AbstractTreeViewItem::collapse_chevron_click_fn(struct bContext *C,
|
|
|
|
|
void * /*but_arg1*/,
|
|
|
|
|
void * /*arg2*/)
|
|
|
|
|
{
|
|
|
|
|
/* There's no data we could pass to this callback. It must be either the button itself or a
|
|
|
|
|
* consistent address to match buttons over redraws. So instead of passing it somehow, just
|
|
|
|
|
* lookup the hovered item via context here. */
|
|
|
|
|
|
|
|
|
|
const wmWindow *win = CTX_wm_window(C);
|
|
|
|
|
const ARegion *region = CTX_wm_region(C);
|
2022-07-21 17:45:36 +10:00
|
|
|
uiViewItemHandle *hovered_item_handle = UI_region_views_find_item_at(region,
|
|
|
|
|
win->eventstate->xy);
|
UI: Port view item features to base class, merge view item button types
No user visible changes expected.
Merges the tree row and grid tile button types, which were mostly doing
the same things. The idea is that there is a button type for
highlighting, as well as supporting general view item features (e.g.
renaming, drag/drop, etc.). So instead there is a view item button type
now. Also ports view item features like renaming, custom context menus,
drag controllers and drop controllers to `ui::AbstractViewItem` (the new
base class for all view items).
This should be quite an improvement because:
- Merges code that was duplicated over view items.
- Mentioned features (renaming, drag & drop, ...) are much easier to
implement in new view types now. Most of it comes "for free".
- Further features will immediately become availalbe to all views (e.g.
selection).
- Simplifies APIs, there don't have to be functions for individual view
item types anymore.
- View item classes are split and thus less overwhelming visually.
- View item buttons now share all code (drawing, handling, etc.)
- We're soon running out of available button types, this commit merges
two into one.
I was hoping I could do this in multiple smaller commits, but things
were quite intertwined so that would've taken quite some effort.
2022-07-19 16:14:42 +02:00
|
|
|
|
|
|
|
|
AbstractTreeViewItem *hovered_item = from_item_handle<AbstractTreeViewItem>(hovered_item_handle);
|
2021-10-07 14:59:43 +02:00
|
|
|
BLI_assert(hovered_item != nullptr);
|
|
|
|
|
|
|
|
|
|
hovered_item->toggle_collapsed();
|
2021-10-20 11:49:33 +02:00
|
|
|
/* 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();
|
|
|
|
|
}
|
2021-10-07 14:59:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AbstractTreeViewItem::is_collapse_chevron_but(const uiBut *but)
|
|
|
|
|
{
|
|
|
|
|
return but->type == UI_BTYPE_BUT_TOGGLE && ELEM(but->icon, ICON_TRIA_RIGHT, ICON_TRIA_DOWN) &&
|
|
|
|
|
(but->func == collapse_chevron_click_fn);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AbstractTreeViewItem::add_collapse_chevron(uiBlock &block) const
|
|
|
|
|
{
|
|
|
|
|
if (!is_collapsible()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const BIFIconID icon = is_collapsed() ? ICON_TRIA_RIGHT : ICON_TRIA_DOWN;
|
|
|
|
|
uiBut *but = uiDefIconBut(
|
|
|
|
|
&block, UI_BTYPE_BUT_TOGGLE, 0, icon, 0, 0, UI_UNIT_X, UI_UNIT_Y, nullptr, 0, 0, 0, 0, "");
|
|
|
|
|
/* Note that we're passing the tree-row button here, not the chevron one. */
|
|
|
|
|
UI_but_func_set(but, collapse_chevron_click_fn, nullptr, nullptr);
|
2021-10-08 12:27:46 +02:00
|
|
|
UI_but_flag_disable(but, UI_BUT_UNDO);
|
2021-10-07 14:59:43 +02:00
|
|
|
|
|
|
|
|
/* Check if the query for the button matches the created button. */
|
|
|
|
|
BLI_assert(is_collapse_chevron_but(but));
|
2021-10-06 14:18:12 +02:00
|
|
|
}
|
|
|
|
|
|
2021-10-07 14:59:43 +02:00
|
|
|
void AbstractTreeViewItem::add_rename_button(uiLayout &row)
|
2021-10-06 14:18:12 +02:00
|
|
|
{
|
2021-10-07 14:59:43 +02:00
|
|
|
uiBlock *block = uiLayoutGetBlock(&row);
|
|
|
|
|
eUIEmbossType previous_emboss = UI_block_emboss_get(block);
|
|
|
|
|
|
|
|
|
|
uiLayoutRow(&row, false);
|
|
|
|
|
/* Enable emboss for the text button. */
|
|
|
|
|
UI_block_emboss_set(block, UI_EMBOSS);
|
|
|
|
|
|
UI: Port view item features to base class, merge view item button types
No user visible changes expected.
Merges the tree row and grid tile button types, which were mostly doing
the same things. The idea is that there is a button type for
highlighting, as well as supporting general view item features (e.g.
renaming, drag/drop, etc.). So instead there is a view item button type
now. Also ports view item features like renaming, custom context menus,
drag controllers and drop controllers to `ui::AbstractViewItem` (the new
base class for all view items).
This should be quite an improvement because:
- Merges code that was duplicated over view items.
- Mentioned features (renaming, drag & drop, ...) are much easier to
implement in new view types now. Most of it comes "for free".
- Further features will immediately become availalbe to all views (e.g.
selection).
- Simplifies APIs, there don't have to be functions for individual view
item types anymore.
- View item classes are split and thus less overwhelming visually.
- View item buttons now share all code (drawing, handling, etc.)
- We're soon running out of available button types, this commit merges
two into one.
I was hoping I could do this in multiple smaller commits, but things
were quite intertwined so that would've taken quite some effort.
2022-07-19 16:14:42 +02:00
|
|
|
AbstractViewItem::add_rename_button(*block);
|
2021-10-07 14:59:43 +02:00
|
|
|
|
|
|
|
|
UI_block_emboss_set(block, previous_emboss);
|
|
|
|
|
UI_block_layout_set_current(block, &row);
|
2021-10-06 14:18:12 +02:00
|
|
|
}
|
|
|
|
|
|
2021-10-20 11:49:33 +02:00
|
|
|
bool AbstractTreeViewItem::has_active_child() const
|
|
|
|
|
{
|
|
|
|
|
bool found = false;
|
|
|
|
|
foreach_item_recursive([&found](const AbstractTreeViewItem &item) {
|
|
|
|
|
if (item.is_active()) {
|
|
|
|
|
found = true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return found;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-23 18:56:29 +02:00
|
|
|
void AbstractTreeViewItem::on_activate()
|
|
|
|
|
{
|
|
|
|
|
/* Do nothing by default. */
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-19 17:36:11 -05:00
|
|
|
std::optional<bool> AbstractTreeViewItem::should_be_active() const
|
2021-10-05 16:01:01 +02:00
|
|
|
{
|
2021-11-19 17:36:11 -05:00
|
|
|
return std::nullopt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AbstractTreeViewItem::supports_collapsing() const
|
|
|
|
|
{
|
|
|
|
|
return true;
|
2021-10-05 16:01:01 +02:00
|
|
|
}
|
|
|
|
|
|
UI: Port view item features to base class, merge view item button types
No user visible changes expected.
Merges the tree row and grid tile button types, which were mostly doing
the same things. The idea is that there is a button type for
highlighting, as well as supporting general view item features (e.g.
renaming, drag/drop, etc.). So instead there is a view item button type
now. Also ports view item features like renaming, custom context menus,
drag controllers and drop controllers to `ui::AbstractViewItem` (the new
base class for all view items).
This should be quite an improvement because:
- Merges code that was duplicated over view items.
- Mentioned features (renaming, drag & drop, ...) are much easier to
implement in new view types now. Most of it comes "for free".
- Further features will immediately become availalbe to all views (e.g.
selection).
- Simplifies APIs, there don't have to be functions for individual view
item types anymore.
- View item classes are split and thus less overwhelming visually.
- View item buttons now share all code (drawing, handling, etc.)
- We're soon running out of available button types, this commit merges
two into one.
I was hoping I could do this in multiple smaller commits, but things
were quite intertwined so that would've taken quite some effort.
2022-07-19 16:14:42 +02:00
|
|
|
StringRef AbstractTreeViewItem::get_rename_string() const
|
2021-10-06 14:18:12 +02:00
|
|
|
{
|
UI: Port view item features to base class, merge view item button types
No user visible changes expected.
Merges the tree row and grid tile button types, which were mostly doing
the same things. The idea is that there is a button type for
highlighting, as well as supporting general view item features (e.g.
renaming, drag/drop, etc.). So instead there is a view item button type
now. Also ports view item features like renaming, custom context menus,
drag controllers and drop controllers to `ui::AbstractViewItem` (the new
base class for all view items).
This should be quite an improvement because:
- Merges code that was duplicated over view items.
- Mentioned features (renaming, drag & drop, ...) are much easier to
implement in new view types now. Most of it comes "for free".
- Further features will immediately become availalbe to all views (e.g.
selection).
- Simplifies APIs, there don't have to be functions for individual view
item types anymore.
- View item classes are split and thus less overwhelming visually.
- View item buttons now share all code (drawing, handling, etc.)
- We're soon running out of available button types, this commit merges
two into one.
I was hoping I could do this in multiple smaller commits, but things
were quite intertwined so that would've taken quite some effort.
2022-07-19 16:14:42 +02:00
|
|
|
return label_;
|
2021-10-06 14:18:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AbstractTreeViewItem::rename(StringRefNull new_name)
|
|
|
|
|
{
|
UI: Port view item features to base class, merge view item button types
No user visible changes expected.
Merges the tree row and grid tile button types, which were mostly doing
the same things. The idea is that there is a button type for
highlighting, as well as supporting general view item features (e.g.
renaming, drag/drop, etc.). So instead there is a view item button type
now. Also ports view item features like renaming, custom context menus,
drag controllers and drop controllers to `ui::AbstractViewItem` (the new
base class for all view items).
This should be quite an improvement because:
- Merges code that was duplicated over view items.
- Mentioned features (renaming, drag & drop, ...) are much easier to
implement in new view types now. Most of it comes "for free".
- Further features will immediately become availalbe to all views (e.g.
selection).
- Simplifies APIs, there don't have to be functions for individual view
item types anymore.
- View item classes are split and thus less overwhelming visually.
- View item buttons now share all code (drawing, handling, etc.)
- We're soon running out of available button types, this commit merges
two into one.
I was hoping I could do this in multiple smaller commits, but things
were quite intertwined so that would've taken quite some effort.
2022-07-19 16:14:42 +02:00
|
|
|
/* It is important to update the label after renaming, so #AbstractTreeViewItem::matches_single()
|
2021-10-06 14:18:12 +02:00
|
|
|
* recognizes the item. (It only compares labels by default.) */
|
|
|
|
|
label_ = new_name;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-18 16:51:57 +02:00
|
|
|
void AbstractTreeViewItem::update_from_old(const AbstractViewItem &old)
|
2021-09-23 18:56:29 +02:00
|
|
|
{
|
2022-07-18 16:51:57 +02:00
|
|
|
AbstractViewItem::update_from_old(old);
|
|
|
|
|
|
|
|
|
|
const AbstractTreeViewItem &old_tree_item = dynamic_cast<const AbstractTreeViewItem &>(old);
|
|
|
|
|
is_open_ = old_tree_item.is_open_;
|
2021-09-23 18:56:29 +02:00
|
|
|
}
|
|
|
|
|
|
UI: Port view item features to base class, merge view item button types
No user visible changes expected.
Merges the tree row and grid tile button types, which were mostly doing
the same things. The idea is that there is a button type for
highlighting, as well as supporting general view item features (e.g.
renaming, drag/drop, etc.). So instead there is a view item button type
now. Also ports view item features like renaming, custom context menus,
drag controllers and drop controllers to `ui::AbstractViewItem` (the new
base class for all view items).
This should be quite an improvement because:
- Merges code that was duplicated over view items.
- Mentioned features (renaming, drag & drop, ...) are much easier to
implement in new view types now. Most of it comes "for free".
- Further features will immediately become availalbe to all views (e.g.
selection).
- Simplifies APIs, there don't have to be functions for individual view
item types anymore.
- View item classes are split and thus less overwhelming visually.
- View item buttons now share all code (drawing, handling, etc.)
- We're soon running out of available button types, this commit merges
two into one.
I was hoping I could do this in multiple smaller commits, but things
were quite intertwined so that would've taken quite some effort.
2022-07-19 16:14:42 +02:00
|
|
|
bool AbstractTreeViewItem::matches_single(const AbstractTreeViewItem &other) const
|
2021-09-29 17:01:13 +02:00
|
|
|
{
|
|
|
|
|
return label_ == other.label_;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-07 14:59:43 +02:00
|
|
|
AbstractTreeView &AbstractTreeViewItem::get_tree_view() const
|
2021-10-06 14:18:12 +02:00
|
|
|
{
|
UI: Port view item features to base class, merge view item button types
No user visible changes expected.
Merges the tree row and grid tile button types, which were mostly doing
the same things. The idea is that there is a button type for
highlighting, as well as supporting general view item features (e.g.
renaming, drag/drop, etc.). So instead there is a view item button type
now. Also ports view item features like renaming, custom context menus,
drag controllers and drop controllers to `ui::AbstractViewItem` (the new
base class for all view items).
This should be quite an improvement because:
- Merges code that was duplicated over view items.
- Mentioned features (renaming, drag & drop, ...) are much easier to
implement in new view types now. Most of it comes "for free".
- Further features will immediately become availalbe to all views (e.g.
selection).
- Simplifies APIs, there don't have to be functions for individual view
item types anymore.
- View item classes are split and thus less overwhelming visually.
- View item buttons now share all code (drawing, handling, etc.)
- We're soon running out of available button types, this commit merges
two into one.
I was hoping I could do this in multiple smaller commits, but things
were quite intertwined so that would've taken quite some effort.
2022-07-19 16:14:42 +02:00
|
|
|
return dynamic_cast<AbstractTreeView &>(get_view());
|
2021-10-06 14:18:12 +02:00
|
|
|
}
|
|
|
|
|
|
2021-09-23 18:56:29 +02:00
|
|
|
int AbstractTreeViewItem::count_parents() const
|
|
|
|
|
{
|
|
|
|
|
int i = 0;
|
2021-12-09 12:07:34 +01:00
|
|
|
for (AbstractTreeViewItem *parent = parent_; parent; parent = parent->parent_) {
|
2021-09-23 18:56:29 +02:00
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-04 16:17:59 +02:00
|
|
|
void AbstractTreeViewItem::activate()
|
2021-09-23 18:56:29 +02:00
|
|
|
{
|
2021-10-05 16:01:01 +02:00
|
|
|
BLI_assert_msg(get_tree_view().is_reconstructed(),
|
|
|
|
|
"Item activation can't be done until reconstruction is completed");
|
|
|
|
|
|
2021-10-04 16:17:59 +02:00
|
|
|
if (is_active()) {
|
|
|
|
|
return;
|
2021-09-23 18:56:29 +02:00
|
|
|
}
|
2021-10-04 16:17:59 +02:00
|
|
|
|
|
|
|
|
/* 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;
|
2021-09-23 18:56:29 +02:00
|
|
|
}
|
|
|
|
|
|
2021-10-06 16:29:10 +02:00
|
|
|
bool AbstractTreeViewItem::is_hovered() const
|
|
|
|
|
{
|
|
|
|
|
BLI_assert_msg(get_tree_view().is_reconstructed(),
|
|
|
|
|
"State can't be queried until reconstruction is completed");
|
UI: Port view item features to base class, merge view item button types
No user visible changes expected.
Merges the tree row and grid tile button types, which were mostly doing
the same things. The idea is that there is a button type for
highlighting, as well as supporting general view item features (e.g.
renaming, drag/drop, etc.). So instead there is a view item button type
now. Also ports view item features like renaming, custom context menus,
drag controllers and drop controllers to `ui::AbstractViewItem` (the new
base class for all view items).
This should be quite an improvement because:
- Merges code that was duplicated over view items.
- Mentioned features (renaming, drag & drop, ...) are much easier to
implement in new view types now. Most of it comes "for free".
- Further features will immediately become availalbe to all views (e.g.
selection).
- Simplifies APIs, there don't have to be functions for individual view
item types anymore.
- View item classes are split and thus less overwhelming visually.
- View item buttons now share all code (drawing, handling, etc.)
- We're soon running out of available button types, this commit merges
two into one.
I was hoping I could do this in multiple smaller commits, but things
were quite intertwined so that would've taken quite some effort.
2022-07-19 16:14:42 +02:00
|
|
|
BLI_assert_msg(view_item_but_ != nullptr,
|
2021-10-06 16:29:10 +02:00
|
|
|
"Hovered state can't be queried before the tree row is being built");
|
|
|
|
|
|
UI: Port view item features to base class, merge view item button types
No user visible changes expected.
Merges the tree row and grid tile button types, which were mostly doing
the same things. The idea is that there is a button type for
highlighting, as well as supporting general view item features (e.g.
renaming, drag/drop, etc.). So instead there is a view item button type
now. Also ports view item features like renaming, custom context menus,
drag controllers and drop controllers to `ui::AbstractViewItem` (the new
base class for all view items).
This should be quite an improvement because:
- Merges code that was duplicated over view items.
- Mentioned features (renaming, drag & drop, ...) are much easier to
implement in new view types now. Most of it comes "for free".
- Further features will immediately become availalbe to all views (e.g.
selection).
- Simplifies APIs, there don't have to be functions for individual view
item types anymore.
- View item classes are split and thus less overwhelming visually.
- View item buttons now share all code (drawing, handling, etc.)
- We're soon running out of available button types, this commit merges
two into one.
I was hoping I could do this in multiple smaller commits, but things
were quite intertwined so that would've taken quite some effort.
2022-07-19 16:14:42 +02:00
|
|
|
const uiViewItemHandle *this_item_handle = reinterpret_cast<const uiViewItemHandle *>(this);
|
2021-10-06 16:29:10 +02:00
|
|
|
/* The new layout hasn't finished construction yet, so the final state of the button is unknown.
|
|
|
|
|
* Get the matching button from the previous redraw instead. */
|
UI: Port view item features to base class, merge view item button types
No user visible changes expected.
Merges the tree row and grid tile button types, which were mostly doing
the same things. The idea is that there is a button type for
highlighting, as well as supporting general view item features (e.g.
renaming, drag/drop, etc.). So instead there is a view item button type
now. Also ports view item features like renaming, custom context menus,
drag controllers and drop controllers to `ui::AbstractViewItem` (the new
base class for all view items).
This should be quite an improvement because:
- Merges code that was duplicated over view items.
- Mentioned features (renaming, drag & drop, ...) are much easier to
implement in new view types now. Most of it comes "for free".
- Further features will immediately become availalbe to all views (e.g.
selection).
- Simplifies APIs, there don't have to be functions for individual view
item types anymore.
- View item classes are split and thus less overwhelming visually.
- View item buttons now share all code (drawing, handling, etc.)
- We're soon running out of available button types, this commit merges
two into one.
I was hoping I could do this in multiple smaller commits, but things
were quite intertwined so that would've taken quite some effort.
2022-07-19 16:14:42 +02:00
|
|
|
uiButViewItem *old_item_but = ui_block_view_find_matching_view_item_but_in_old_block(
|
|
|
|
|
view_item_but_->but.block, this_item_handle);
|
|
|
|
|
return old_item_but && (old_item_but->but.flag & UI_ACTIVE);
|
2021-10-06 16:29:10 +02:00
|
|
|
}
|
|
|
|
|
|
2021-09-23 18:56:29 +02:00
|
|
|
bool AbstractTreeViewItem::is_collapsed() const
|
|
|
|
|
{
|
2021-10-05 16:01:01 +02:00
|
|
|
BLI_assert_msg(get_tree_view().is_reconstructed(),
|
|
|
|
|
"State can't be queried until reconstruction is completed");
|
2021-09-23 18:56:29 +02:00
|
|
|
return is_collapsible() && !is_open_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AbstractTreeViewItem::toggle_collapsed()
|
|
|
|
|
{
|
|
|
|
|
is_open_ = !is_open_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AbstractTreeViewItem::set_collapsed(bool collapsed)
|
|
|
|
|
{
|
|
|
|
|
is_open_ = !collapsed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AbstractTreeViewItem::is_collapsible() const
|
|
|
|
|
{
|
2021-11-19 17:36:11 -05:00
|
|
|
if (children_.is_empty()) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return this->supports_collapsing();
|
2021-09-23 18:56:29 +02:00
|
|
|
}
|
|
|
|
|
|
2021-10-04 16:17:59 +02:00
|
|
|
void AbstractTreeViewItem::ensure_parents_uncollapsed()
|
|
|
|
|
{
|
|
|
|
|
for (AbstractTreeViewItem *parent = parent_; parent; parent = parent->parent_) {
|
|
|
|
|
parent->set_collapsed(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
UI: Port view item features to base class, merge view item button types
No user visible changes expected.
Merges the tree row and grid tile button types, which were mostly doing
the same things. The idea is that there is a button type for
highlighting, as well as supporting general view item features (e.g.
renaming, drag/drop, etc.). So instead there is a view item button type
now. Also ports view item features like renaming, custom context menus,
drag controllers and drop controllers to `ui::AbstractViewItem` (the new
base class for all view items).
This should be quite an improvement because:
- Merges code that was duplicated over view items.
- Mentioned features (renaming, drag & drop, ...) are much easier to
implement in new view types now. Most of it comes "for free".
- Further features will immediately become availalbe to all views (e.g.
selection).
- Simplifies APIs, there don't have to be functions for individual view
item types anymore.
- View item classes are split and thus less overwhelming visually.
- View item buttons now share all code (drawing, handling, etc.)
- We're soon running out of available button types, this commit merges
two into one.
I was hoping I could do this in multiple smaller commits, but things
were quite intertwined so that would've taken quite some effort.
2022-07-19 16:14:42 +02:00
|
|
|
bool AbstractTreeViewItem::matches(const AbstractViewItem &other) const
|
2021-10-06 16:15:12 +02:00
|
|
|
{
|
UI: Port view item features to base class, merge view item button types
No user visible changes expected.
Merges the tree row and grid tile button types, which were mostly doing
the same things. The idea is that there is a button type for
highlighting, as well as supporting general view item features (e.g.
renaming, drag/drop, etc.). So instead there is a view item button type
now. Also ports view item features like renaming, custom context menus,
drag controllers and drop controllers to `ui::AbstractViewItem` (the new
base class for all view items).
This should be quite an improvement because:
- Merges code that was duplicated over view items.
- Mentioned features (renaming, drag & drop, ...) are much easier to
implement in new view types now. Most of it comes "for free".
- Further features will immediately become availalbe to all views (e.g.
selection).
- Simplifies APIs, there don't have to be functions for individual view
item types anymore.
- View item classes are split and thus less overwhelming visually.
- View item buttons now share all code (drawing, handling, etc.)
- We're soon running out of available button types, this commit merges
two into one.
I was hoping I could do this in multiple smaller commits, but things
were quite intertwined so that would've taken quite some effort.
2022-07-19 16:14:42 +02:00
|
|
|
const AbstractTreeViewItem &other_tree_item = dynamic_cast<const AbstractTreeViewItem &>(other);
|
|
|
|
|
|
|
|
|
|
if (!matches_single(other_tree_item)) {
|
2021-10-06 16:15:12 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
UI: Port view item features to base class, merge view item button types
No user visible changes expected.
Merges the tree row and grid tile button types, which were mostly doing
the same things. The idea is that there is a button type for
highlighting, as well as supporting general view item features (e.g.
renaming, drag/drop, etc.). So instead there is a view item button type
now. Also ports view item features like renaming, custom context menus,
drag controllers and drop controllers to `ui::AbstractViewItem` (the new
base class for all view items).
This should be quite an improvement because:
- Merges code that was duplicated over view items.
- Mentioned features (renaming, drag & drop, ...) are much easier to
implement in new view types now. Most of it comes "for free".
- Further features will immediately become availalbe to all views (e.g.
selection).
- Simplifies APIs, there don't have to be functions for individual view
item types anymore.
- View item classes are split and thus less overwhelming visually.
- View item buttons now share all code (drawing, handling, etc.)
- We're soon running out of available button types, this commit merges
two into one.
I was hoping I could do this in multiple smaller commits, but things
were quite intertwined so that would've taken quite some effort.
2022-07-19 16:14:42 +02:00
|
|
|
if (count_parents() != other_tree_item.count_parents()) {
|
2021-10-06 16:52:16 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
2021-10-06 16:15:12 +02:00
|
|
|
|
UI: Port view item features to base class, merge view item button types
No user visible changes expected.
Merges the tree row and grid tile button types, which were mostly doing
the same things. The idea is that there is a button type for
highlighting, as well as supporting general view item features (e.g.
renaming, drag/drop, etc.). So instead there is a view item button type
now. Also ports view item features like renaming, custom context menus,
drag controllers and drop controllers to `ui::AbstractViewItem` (the new
base class for all view items).
This should be quite an improvement because:
- Merges code that was duplicated over view items.
- Mentioned features (renaming, drag & drop, ...) are much easier to
implement in new view types now. Most of it comes "for free".
- Further features will immediately become availalbe to all views (e.g.
selection).
- Simplifies APIs, there don't have to be functions for individual view
item types anymore.
- View item classes are split and thus less overwhelming visually.
- View item buttons now share all code (drawing, handling, etc.)
- We're soon running out of available button types, this commit merges
two into one.
I was hoping I could do this in multiple smaller commits, but things
were quite intertwined so that would've taken quite some effort.
2022-07-19 16:14:42 +02:00
|
|
|
for (AbstractTreeViewItem *parent = parent_, *other_parent = other_tree_item.parent_;
|
2021-10-06 16:15:12 +02:00
|
|
|
parent && other_parent;
|
|
|
|
|
parent = parent->parent_, other_parent = other_parent->parent_) {
|
UI: Port view item features to base class, merge view item button types
No user visible changes expected.
Merges the tree row and grid tile button types, which were mostly doing
the same things. The idea is that there is a button type for
highlighting, as well as supporting general view item features (e.g.
renaming, drag/drop, etc.). So instead there is a view item button type
now. Also ports view item features like renaming, custom context menus,
drag controllers and drop controllers to `ui::AbstractViewItem` (the new
base class for all view items).
This should be quite an improvement because:
- Merges code that was duplicated over view items.
- Mentioned features (renaming, drag & drop, ...) are much easier to
implement in new view types now. Most of it comes "for free".
- Further features will immediately become availalbe to all views (e.g.
selection).
- Simplifies APIs, there don't have to be functions for individual view
item types anymore.
- View item classes are split and thus less overwhelming visually.
- View item buttons now share all code (drawing, handling, etc.)
- We're soon running out of available button types, this commit merges
two into one.
I was hoping I could do this in multiple smaller commits, but things
were quite intertwined so that would've taken quite some effort.
2022-07-19 16:14:42 +02:00
|
|
|
if (!parent->matches_single(*other_parent)) {
|
2021-10-06 16:15:12 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
UI: Port view item features to base class, merge view item button types
No user visible changes expected.
Merges the tree row and grid tile button types, which were mostly doing
the same things. The idea is that there is a button type for
highlighting, as well as supporting general view item features (e.g.
renaming, drag/drop, etc.). So instead there is a view item button type
now. Also ports view item features like renaming, custom context menus,
drag controllers and drop controllers to `ui::AbstractViewItem` (the new
base class for all view items).
This should be quite an improvement because:
- Merges code that was duplicated over view items.
- Mentioned features (renaming, drag & drop, ...) are much easier to
implement in new view types now. Most of it comes "for free".
- Further features will immediately become availalbe to all views (e.g.
selection).
- Simplifies APIs, there don't have to be functions for individual view
item types anymore.
- View item classes are split and thus less overwhelming visually.
- View item buttons now share all code (drawing, handling, etc.)
- We're soon running out of available button types, this commit merges
two into one.
I was hoping I could do this in multiple smaller commits, but things
were quite intertwined so that would've taken quite some effort.
2022-07-19 16:14:42 +02:00
|
|
|
uiButViewItem *AbstractTreeViewItem::view_item_button()
|
2021-10-07 14:59:43 +02:00
|
|
|
{
|
UI: Port view item features to base class, merge view item button types
No user visible changes expected.
Merges the tree row and grid tile button types, which were mostly doing
the same things. The idea is that there is a button type for
highlighting, as well as supporting general view item features (e.g.
renaming, drag/drop, etc.). So instead there is a view item button type
now. Also ports view item features like renaming, custom context menus,
drag controllers and drop controllers to `ui::AbstractViewItem` (the new
base class for all view items).
This should be quite an improvement because:
- Merges code that was duplicated over view items.
- Mentioned features (renaming, drag & drop, ...) are much easier to
implement in new view types now. Most of it comes "for free".
- Further features will immediately become availalbe to all views (e.g.
selection).
- Simplifies APIs, there don't have to be functions for individual view
item types anymore.
- View item classes are split and thus less overwhelming visually.
- View item buttons now share all code (drawing, handling, etc.)
- We're soon running out of available button types, this commit merges
two into one.
I was hoping I could do this in multiple smaller commits, but things
were quite intertwined so that would've taken quite some effort.
2022-07-19 16:14:42 +02:00
|
|
|
return view_item_but_;
|
2021-10-07 14:59:43 +02:00
|
|
|
}
|
|
|
|
|
|
2021-10-05 16:01:01 +02:00
|
|
|
void AbstractTreeViewItem::change_state_delayed()
|
|
|
|
|
{
|
2021-11-19 17:36:11 -05:00
|
|
|
const std::optional<bool> should_be_active = this->should_be_active();
|
|
|
|
|
if (should_be_active.has_value() && *should_be_active) {
|
2021-10-05 16:01:01 +02:00
|
|
|
activate();
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-11-24 18:02:56 +01:00
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------- */
|
|
|
|
|
|
2021-12-09 12:07:34 +01:00
|
|
|
class TreeViewLayoutBuilder {
|
|
|
|
|
uiBlock &block_;
|
|
|
|
|
|
|
|
|
|
friend TreeViewBuilder;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
void build_from_tree(const AbstractTreeView &tree_view);
|
|
|
|
|
void build_row(AbstractTreeViewItem &item) const;
|
|
|
|
|
|
|
|
|
|
uiBlock &block() const;
|
|
|
|
|
uiLayout *current_layout() const;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
/* Created through #TreeViewBuilder. */
|
|
|
|
|
TreeViewLayoutBuilder(uiBlock &block);
|
|
|
|
|
|
|
|
|
|
static void polish_layout(const uiBlock &block);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TreeViewLayoutBuilder::TreeViewLayoutBuilder(uiBlock &block) : block_(block)
|
2021-09-23 18:56:29 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-09 12:07:34 +01:00
|
|
|
void TreeViewLayoutBuilder::build_from_tree(const AbstractTreeView &tree_view)
|
2021-09-23 18:56:29 +02:00
|
|
|
{
|
2021-12-09 12:07:34 +01:00
|
|
|
uiLayout *prev_layout = current_layout();
|
2021-09-23 18:56:29 +02:00
|
|
|
|
2021-12-09 12:07:34 +01:00
|
|
|
uiLayout *box = uiLayoutBox(prev_layout);
|
|
|
|
|
uiLayoutColumn(box, false);
|
2021-09-23 18:56:29 +02:00
|
|
|
|
2021-12-09 12:07:34 +01:00
|
|
|
tree_view.foreach_item([this](AbstractTreeViewItem &item) { build_row(item); },
|
|
|
|
|
AbstractTreeView::IterOptions::SkipCollapsed);
|
|
|
|
|
|
|
|
|
|
UI_block_layout_set_current(&block(), prev_layout);
|
2021-09-23 18:56:29 +02:00
|
|
|
}
|
|
|
|
|
|
2021-10-07 14:59:43 +02:00
|
|
|
void TreeViewLayoutBuilder::polish_layout(const uiBlock &block)
|
2021-09-23 18:56:29 +02:00
|
|
|
{
|
2021-10-07 14:59:43 +02:00
|
|
|
LISTBASE_FOREACH_BACKWARD (uiBut *, but, &block.buttons) {
|
|
|
|
|
if (AbstractTreeViewItem::is_collapse_chevron_but(but) && but->next &&
|
|
|
|
|
/* Embossed buttons with padding-less text padding look weird, so don't touch them. */
|
|
|
|
|
ELEM(but->next->emboss, UI_EMBOSS_NONE, UI_EMBOSS_NONE_OR_STATUS)) {
|
|
|
|
|
UI_but_drawflag_enable(static_cast<uiBut *>(but->next), UI_BUT_NO_TEXT_PADDING);
|
|
|
|
|
}
|
2021-09-23 18:56:29 +02:00
|
|
|
|
UI: Port view item features to base class, merge view item button types
No user visible changes expected.
Merges the tree row and grid tile button types, which were mostly doing
the same things. The idea is that there is a button type for
highlighting, as well as supporting general view item features (e.g.
renaming, drag/drop, etc.). So instead there is a view item button type
now. Also ports view item features like renaming, custom context menus,
drag controllers and drop controllers to `ui::AbstractViewItem` (the new
base class for all view items).
This should be quite an improvement because:
- Merges code that was duplicated over view items.
- Mentioned features (renaming, drag & drop, ...) are much easier to
implement in new view types now. Most of it comes "for free".
- Further features will immediately become availalbe to all views (e.g.
selection).
- Simplifies APIs, there don't have to be functions for individual view
item types anymore.
- View item classes are split and thus less overwhelming visually.
- View item buttons now share all code (drawing, handling, etc.)
- We're soon running out of available button types, this commit merges
two into one.
I was hoping I could do this in multiple smaller commits, but things
were quite intertwined so that would've taken quite some effort.
2022-07-19 16:14:42 +02:00
|
|
|
if (but->type == UI_BTYPE_VIEW_ITEM) {
|
2021-10-07 14:59:43 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-10-06 14:18:12 +02:00
|
|
|
|
2021-10-07 14:59:43 +02:00
|
|
|
void TreeViewLayoutBuilder::build_row(AbstractTreeViewItem &item) const
|
|
|
|
|
{
|
2021-10-06 14:18:12 +02:00
|
|
|
uiBlock &block_ = block();
|
|
|
|
|
|
2021-10-07 14:59:43 +02:00
|
|
|
uiLayout *prev_layout = current_layout();
|
|
|
|
|
eUIEmbossType previous_emboss = UI_block_emboss_get(&block_);
|
|
|
|
|
|
|
|
|
|
uiLayout *overlap = uiLayoutOverlap(prev_layout);
|
|
|
|
|
|
|
|
|
|
uiLayoutRow(overlap, false);
|
2021-10-06 14:18:12 +02:00
|
|
|
/* Every item gets one! Other buttons can be overlapped on top. */
|
|
|
|
|
item.add_treerow_button(block_);
|
|
|
|
|
|
2021-10-07 14:59:43 +02:00
|
|
|
/* After adding tree-row button (would disable hover highlighting). */
|
|
|
|
|
UI_block_emboss_set(&block_, UI_EMBOSS_NONE);
|
|
|
|
|
|
|
|
|
|
uiLayout *row = uiLayoutRow(overlap, true);
|
|
|
|
|
item.add_indent(*row);
|
|
|
|
|
item.add_collapse_chevron(block_);
|
|
|
|
|
|
2021-10-06 14:18:12 +02:00
|
|
|
if (item.is_renaming()) {
|
2021-10-07 14:59:43 +02:00
|
|
|
item.add_rename_button(*row);
|
2021-10-06 14:18:12 +02:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
item.build_row(*row);
|
|
|
|
|
}
|
2021-10-07 14:59:43 +02:00
|
|
|
polish_layout(block_);
|
2021-09-23 18:56:29 +02:00
|
|
|
|
2021-10-07 14:59:43 +02:00
|
|
|
UI_block_emboss_set(&block_, previous_emboss);
|
2021-10-06 14:18:12 +02:00
|
|
|
UI_block_layout_set_current(&block_, prev_layout);
|
2021-09-23 18:56:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uiBlock &TreeViewLayoutBuilder::block() const
|
|
|
|
|
{
|
|
|
|
|
return block_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uiLayout *TreeViewLayoutBuilder::current_layout() const
|
|
|
|
|
{
|
|
|
|
|
return block().curlayout;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------- */
|
|
|
|
|
|
2021-12-09 12:07:34 +01:00
|
|
|
TreeViewBuilder::TreeViewBuilder(uiBlock &block) : block_(block)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TreeViewBuilder::build_tree_view(AbstractTreeView &tree_view)
|
|
|
|
|
{
|
|
|
|
|
tree_view.build_tree();
|
|
|
|
|
tree_view.update_from_old(block_);
|
|
|
|
|
tree_view.change_state_delayed();
|
|
|
|
|
|
|
|
|
|
TreeViewLayoutBuilder builder(block_);
|
|
|
|
|
builder.build_from_tree(tree_view);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------- */
|
|
|
|
|
|
2021-10-05 14:25:40 +02:00
|
|
|
BasicTreeViewItem::BasicTreeViewItem(StringRef label, BIFIconID icon_) : icon(icon_)
|
2021-09-23 18:56:29 +02:00
|
|
|
{
|
|
|
|
|
label_ = label;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-07 14:59:43 +02:00
|
|
|
void BasicTreeViewItem::build_row(uiLayout &row)
|
2021-09-23 18:56:29 +02:00
|
|
|
{
|
2021-10-27 12:06:31 +02:00
|
|
|
add_label(row);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BasicTreeViewItem::add_label(uiLayout &layout, StringRefNull label_override)
|
|
|
|
|
{
|
|
|
|
|
const StringRefNull label = label_override.is_empty() ? StringRefNull(label_) : label_override;
|
|
|
|
|
|
|
|
|
|
/* Some padding for labels without collapse chevron and no icon. Looks weird without. */
|
|
|
|
|
if (icon == ICON_NONE && !is_collapsible()) {
|
|
|
|
|
uiItemS_ex(&layout, 0.8f);
|
|
|
|
|
}
|
2021-11-02 17:50:18 +01:00
|
|
|
uiItemL(&layout, IFACE_(label.c_str()), icon);
|
2021-09-23 18:56:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BasicTreeViewItem::on_activate()
|
|
|
|
|
{
|
|
|
|
|
if (activate_fn_) {
|
|
|
|
|
activate_fn_(*this);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-19 17:36:11 -05:00
|
|
|
void BasicTreeViewItem::set_on_activate_fn(ActivateFn fn)
|
2021-10-05 14:25:40 +02:00
|
|
|
{
|
|
|
|
|
activate_fn_ = fn;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-19 17:36:11 -05:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-23 18:56:29 +02:00
|
|
|
} // namespace blender::ui
|