UI: Add function to query debug name of view items

No user visible change expected.

There's no good way to identify items from their base class which is
annoying for development/debugging. I ended up adding a helper like this
a few times, so makes sense to just add this to the API.
This commit is contained in:
Julian Eisel
2024-06-28 11:50:17 +02:00
parent 42e66f2912
commit b59e009acc
6 changed files with 26 additions and 0 deletions

View File

@@ -212,6 +212,13 @@ class AbstractViewItem {
*/
virtual std::unique_ptr<DropTargetInterface> create_item_drop_target();
/**
* View types should implement this to return some name or identifier of the item, which is
* helpful for debugging (there's nothing to identify the item just from the #AbstractViewItem
* otherwise).
*/
virtual std::optional<std::string> debug_name() const;
/** Return the result of #is_filtered_visible(), but ensure the result is cached so it's only
* queried once per redraw. */
bool is_filtered_visible_cached() const;

View File

@@ -47,6 +47,8 @@ class AbstractGridViewItem : public AbstractViewItem {
virtual void build_grid_tile(uiLayout &layout) const = 0;
/* virtual */ std::optional<std::string> debug_name() const override;
AbstractGridView &get_view() const;
protected:

View File

@@ -187,6 +187,8 @@ class AbstractTreeViewItem : public AbstractViewItem, public TreeViewItemContain
virtual void build_row(uiLayout &row) = 0;
/* virtual */ std::optional<std::string> debug_name() const override;
std::unique_ptr<DropTargetInterface> create_item_drop_target() final;
virtual std::unique_ptr<TreeViewItemDropTarget> create_drop_target();

View File

@@ -269,6 +269,11 @@ std::unique_ptr<DropTargetInterface> AbstractViewItem::create_item_drop_target()
return nullptr;
}
std::optional<std::string> AbstractViewItem::debug_name() const
{
return {};
}
AbstractViewItemDragController::AbstractViewItemDragController(AbstractView &view) : view_(view) {}
void AbstractViewItemDragController::on_drag_start()

View File

@@ -163,6 +163,11 @@ void AbstractGridViewItem::add_grid_tile_button(uiBlock &block)
UI_but_func_set(view_item_but_, grid_tile_click_fn, view_item_but_, nullptr);
}
std::optional<std::string> AbstractGridViewItem::debug_name() const
{
return identifier_;
}
AbstractGridView &AbstractGridViewItem::get_view() const
{
if (UNLIKELY(!view_)) {

View File

@@ -456,6 +456,11 @@ std::unique_ptr<TreeViewItemDropTarget> AbstractTreeViewItem::create_drop_target
return nullptr;
}
std::optional<std::string> AbstractTreeViewItem::debug_name() const
{
return label_;
}
AbstractTreeView &AbstractTreeViewItem::get_tree_view() const
{
return dynamic_cast<AbstractTreeView &>(get_view());