32 std::unique_ptr<AbstractTreeViewItem> item)
37 if (
root_ ==
nullptr) {
62 child->foreach_item_recursive(iter_fn,
options);
73 void AbstractTreeView::update_children_from_old(
const AbstractView &old_view)
77 update_children_from_old_recursive(*
this, old_tree_view);
80 void AbstractTreeView::update_children_from_old_recursive(
const TreeViewOrItem &new_items,
83 for (
const auto &new_item : new_items.children_) {
85 if (!matching_old_item) {
89 new_item->update_from_old(*matching_old_item);
92 update_children_from_old_recursive(*new_item, *matching_old_item);
96 AbstractTreeViewItem *AbstractTreeView::find_matching_child(
97 const AbstractTreeViewItem &lookup_item,
const TreeViewOrItem &items)
99 for (
const auto &iter_item : items.children_) {
100 if (lookup_item.matches_single(*iter_item)) {
102 return iter_item.get();
109 void AbstractTreeView::change_state_delayed()
113 "These state changes are supposed to be delayed until reconstruction is completed");
119 void AbstractTreeViewItem::tree_row_click_fn(
struct bContext * ,
126 tree_item.activate();
129 tree_item.set_collapsed(
false);
132 void AbstractTreeViewItem::add_treerow_button(
uiBlock &block)
136 &block,
UI_BTYPE_VIEW_ITEM, 0,
"", 0, 0,
UI_UNIT_X * 10,
UI_UNIT_Y,
nullptr, 0, 0, 0, 0,
"");
142 void AbstractTreeViewItem::add_indent(
uiLayout &row)
const
149 uiDefBut(block,
UI_BTYPE_SEPR, 0,
"", 0, 0, indent_size, 0,
nullptr, 0.0, 0.0, 0, 0,
"");
154 uiDefBut(block,
UI_BTYPE_SEPR, 0,
"", 0, 0, 0.2f *
UI_UNIT_X, 0,
nullptr, 0.0, 0.0, 0, 0,
"");
161 void AbstractTreeViewItem::collapse_chevron_click_fn(
struct bContext *C,
174 AbstractTreeViewItem *hovered_item = from_item_handle<AbstractTreeViewItem>(hovered_item_handle);
177 hovered_item->toggle_collapsed();
180 if (hovered_item->has_active_child()) {
181 hovered_item->activate();
185 bool AbstractTreeViewItem::is_collapse_chevron_but(
const uiBut *but)
188 (but->
func == collapse_chevron_click_fn);
191 void AbstractTreeViewItem::add_collapse_chevron(
uiBlock &block)
const
199 &block,
UI_BTYPE_BUT_TOGGLE, 0, icon, 0, 0,
UI_UNIT_X,
UI_UNIT_Y,
nullptr, 0, 0, 0, 0,
"");
208 void AbstractTreeViewItem::add_rename_button(
uiLayout &row)
223 bool AbstractTreeViewItem::has_active_child()
const
227 if (item.is_active()) {
268 is_open_ = old_tree_item.is_open_;
281 int AbstractTreeViewItem::count_parents()
const
293 "Item activation can't be done until reconstruction is completed");
317 "State can't be queried until reconstruction is completed");
319 "Hovered state can't be queried before the tree row is being built");
332 "State can't be queried until reconstruction is completed");
338 is_open_ = !is_open_;
343 is_open_ = !collapsed;
357 parent->set_collapsed(
false);
368 if (count_parents() != other_tree_item.count_parents()) {
373 parent && other_parent;
375 if (!parent->matches_single(*other_parent)) {
388 void AbstractTreeViewItem::change_state_delayed()
417 TreeViewLayoutBuilder::TreeViewLayoutBuilder(
uiBlock &block) : block_(block)
434 void TreeViewLayoutBuilder::polish_layout(
const uiBlock &block)
437 if (AbstractTreeViewItem::is_collapse_chevron_but(but) && but->
next &&
460 item.add_treerow_button(block_);
466 item.add_indent(*row);
467 item.add_collapse_chevron(block_);
470 item.add_rename_button(*row);
475 polish_layout(block_);
501 tree_view.change_state_delayed();
530 void BasicTreeViewItem::on_activate()
547 std::optional<bool> BasicTreeViewItem::should_be_active()
const
struct ARegion * CTX_wm_region(const bContext *C)
struct wmWindow * CTX_wm_window(const bContext *C)
#define BLI_assert_msg(a, msg)
#define LISTBASE_FOREACH_BACKWARD(type, var, list)
void uiItemS_ex(uiLayout *layout, float factor)
void UI_but_flag_disable(uiBut *but, int flag)
eUIEmbossType UI_block_emboss_get(uiBlock *block)
uiBlock * uiLayoutGetBlock(uiLayout *layout)
@ UI_EMBOSS_NONE_OR_STATUS
uiBut * uiDefIconBut(uiBlock *block, int type, int retval, int icon, int x, int y, short width, short height, void *poin, float min, float max, float a1, float a2, const char *tip)
uiLayout * uiLayoutColumn(uiLayout *layout, bool align)
uiLayout * uiLayoutOverlap(uiLayout *layout)
void uiLayoutSetFixedSize(uiLayout *layout, bool fixed_size)
uiBut * uiDefBut(uiBlock *block, int type, int retval, const char *str, int x, int y, short width, short height, void *poin, float min, float max, float a1, float a2, const char *tip)
void uiItemL(uiLayout *layout, const char *name, int icon)
uiViewItemHandle * UI_region_views_find_item_at(const struct ARegion *region, const int xy[2]) ATTR_NONNULL()
void UI_but_drawflag_enable(uiBut *but, int flag)
uiLayout * uiLayoutBox(uiLayout *layout)
uiLayout * uiLayoutRow(uiLayout *layout, bool align)
void UI_block_emboss_set(uiBlock *block, eUIEmbossType emboss)
void UI_but_func_set(uiBut *but, uiButHandleFunc func, void *arg1, void *arg2)
void UI_block_layout_set_current(uiBlock *block, uiLayout *layout)
struct uiViewItemHandle uiViewItemHandle
constexpr bool is_empty() const
Abstract base class for defining a customizable tree-view item.
virtual void update_from_old(const AbstractViewItem &old) override
bool is_collapsed() const
uiButViewItem * view_item_button()
uiButViewItem * view_item_but_
AbstractTreeView & get_tree_view() const
bool is_collapsible() const
virtual StringRef get_rename_string() const override
virtual void build_row(uiLayout &row)=0
virtual bool matches(const AbstractViewItem &other) const override
virtual void on_activate()
virtual bool matches_single(const AbstractTreeViewItem &other) const
virtual std::optional< bool > should_be_active() const
virtual bool supports_collapsing() const
virtual bool rename(StringRefNull new_name) override
void ensure_parents_uncollapsed()
void set_collapsed(bool collapsed)
friend class AbstractTreeViewItem
virtual void build_tree()=0
void foreach_item(ItemIterFn iter_fn, IterOptions options=IterOptions::None) const
virtual void update_from_old(const AbstractViewItem &old)
void add_rename_button(uiBlock &block)
AbstractView & get_view() const
bool is_reconstructed() const
void update_from_old(uiBlock &new_block)
void register_item(AbstractViewItem &item)
void set_is_active_fn(IsActiveFn fn)
BasicTreeViewItem(StringRef label, BIFIconID icon=ICON_NONE)
void build_row(uiLayout &row) override
std::function< bool()> IsActiveFn
std::function< void(BasicTreeViewItem &new_active)> ActivateFn
void add_label(uiLayout &layout, StringRefNull label_override="")
void set_on_activate_fn(ActivateFn fn)
TreeViewBuilder(uiBlock &block)
void build_tree_view(AbstractTreeView &tree_view)
ItemT & add_tree_item(Args &&...args)
friend class AbstractTreeViewItem
AbstractTreeViewItem * parent_
TreeViewItemContainer * root_
void foreach_item_recursive(ItemIterFn iter_fn, IterOptions options=IterOptions::None) const
Vector< std::unique_ptr< AbstractTreeViewItem > > children_
void build_from_tree(const AbstractTreeView &tree_view)
uiLayout * current_layout() const
void build_row(AbstractTreeViewItem &item) const
CCL_NAMESPACE_BEGIN struct Options options
uiButViewItem * ui_block_view_find_matching_view_item_but_in_old_block(const uiBlock *new_block, const uiViewItemHandle *new_item_handle)
TreeViewItemContainer TreeViewOrItem
struct uiLayout * curlayout
uiViewItemHandle * view_item
struct wmEvent * eventstate