diff options
author | Julian Eisel <julian@blender.org> | 2022-08-04 16:18:29 +0300 |
---|---|---|
committer | Julian Eisel <julian@blender.org> | 2022-08-04 16:57:08 +0300 |
commit | 2a3e4d8bcd3447ca307108c95b0eeb9ee8bf7323 (patch) | |
tree | 1fd4a9ba6c5894dbe546429f14fe771607b1e637 /source/blender/editors/space_outliner/tree | |
parent | 791bfae1d64b8969a7edbc6b020f7fba873f77ee (diff) |
Outliner: Add generic label element type
No user visible changes expected.
We have a bunch of "base" element types, just to show a label element
for grouping together other elements. There is no reason to have these
tied to a case, just have a generic label type for this. It requires a
string to display, and can display an icon too. The new element type
isn't used yet, but will be in one of the following commits. Would be
nice if the existing base elements can be replaced by this.
Part of D15606.
Diffstat (limited to 'source/blender/editors/space_outliner/tree')
4 files changed, 91 insertions, 0 deletions
diff --git a/source/blender/editors/space_outliner/tree/tree_element.cc b/source/blender/editors/space_outliner/tree/tree_element.cc index 7808c4a3c0f..5ad8ae0220a 100644 --- a/source/blender/editors/space_outliner/tree/tree_element.cc +++ b/source/blender/editors/space_outliner/tree/tree_element.cc @@ -17,6 +17,7 @@ #include "tree_element_driver.hh" #include "tree_element_gpencil_layer.hh" #include "tree_element_id.hh" +#include "tree_element_label.hh" #include "tree_element_nla.hh" #include "tree_element_overrides.hh" #include "tree_element_rna.hh" @@ -52,6 +53,8 @@ std::unique_ptr<AbstractTreeElement> AbstractTreeElement::createFromType(const i switch (type) { case TSE_SOME_ID: return TreeElementID::createFromID(legacy_te, *static_cast<ID *>(idv)); + case TSE_GENERIC_LABEL: + return std::make_unique<TreeElementLabel>(legacy_te, static_cast<const char *>(idv)); case TSE_ANIM_DATA: return std::make_unique<TreeElementAnimData>(legacy_te, *static_cast<IdAdtTemplate *>(idv)->adt); @@ -103,6 +106,11 @@ StringRefNull AbstractTreeElement::getWarning() const return ""; } +std::optional<BIFIconID> AbstractTreeElement::getIcon() const +{ + return {}; +} + void AbstractTreeElement::uncollapse_by_default(TreeElement *legacy_te) { if (!TREESTORE(legacy_te)->used) { diff --git a/source/blender/editors/space_outliner/tree/tree_element.hh b/source/blender/editors/space_outliner/tree/tree_element.hh index 1098068d628..a3598e7740b 100644 --- a/source/blender/editors/space_outliner/tree/tree_element.hh +++ b/source/blender/editors/space_outliner/tree/tree_element.hh @@ -7,8 +7,10 @@ #pragma once #include <memory> +#include <optional> #include "BLI_string_ref.hh" +#include "UI_resources.h" struct ListBase; struct SpaceOutliner; @@ -64,6 +66,15 @@ class AbstractTreeElement { virtual StringRefNull getWarning() const; /** + * Define the icon to be displayed for this element. If this returns an icon, this will be + * displayed. Otherwise, #tree_element_get_icon() may still determine an icon. By default no + * value is returned (#std::nullopt). + * + * All elements should be ported to use this over #tree_element_get_icon(). + */ + virtual std::optional<BIFIconID> getIcon() const; + + /** * Expand this tree element if it is displayed for the first time (as identified by its * tree-store element). * diff --git a/source/blender/editors/space_outliner/tree/tree_element_label.cc b/source/blender/editors/space_outliner/tree/tree_element_label.cc new file mode 100644 index 00000000000..32fa62c5f5e --- /dev/null +++ b/source/blender/editors/space_outliner/tree/tree_element_label.cc @@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +/** \file + * \ingroup spoutliner + */ + +#include "DNA_listBase.h" + +#include "DNA_outliner_types.h" + +#include "../outliner_intern.hh" + +#include "tree_element_label.hh" + +namespace blender::ed::outliner { + +TreeElementLabel::TreeElementLabel(TreeElement &legacy_te, const char *label) + : AbstractTreeElement(legacy_te), label_(label) +{ + BLI_assert(legacy_te_.store_elem->type == TSE_GENERIC_LABEL); + /* The draw string is actually accessed via #TreeElement.name, so make sure this always points to + * our string. */ + legacy_te_.name = label_.c_str(); +} + +void TreeElementLabel::setIcon(const BIFIconID icon) +{ + icon_ = icon; +} + +std::optional<BIFIconID> TreeElementLabel::getIcon() const +{ + return icon_; +} + +} // namespace blender::ed::outliner diff --git a/source/blender/editors/space_outliner/tree/tree_element_label.hh b/source/blender/editors/space_outliner/tree/tree_element_label.hh new file mode 100644 index 00000000000..fc730c7b8f4 --- /dev/null +++ b/source/blender/editors/space_outliner/tree/tree_element_label.hh @@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +/** \file + * \ingroup spoutliner + */ + +#pragma once + +#include <string> + +#include "UI_resources.h" + +#include "tree_element.hh" + +namespace blender::ed::outliner { + +/** + * A basic, general purpose tree element to just display a label and an icon. Can be used to group + * together items underneath as well of course. + * + * Make sure to give this a unique index, so the element can be identified uniquely. Otherwise + * glitches like multiple highlighted elements happen, that share all state (e.g. collapsed, + * selected, etc.). + */ +class TreeElementLabel final : public AbstractTreeElement { + const std::string label_; + BIFIconID icon_ = ICON_NONE; + + public: + TreeElementLabel(TreeElement &legacy_te, const char *label); + + void setIcon(BIFIconID icon); + std::optional<BIFIconID> getIcon() const override; +}; + +} // namespace blender::ed::outliner |