diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index 00f2f13930..58b8cbb7d0 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -1288,6 +1288,15 @@ bool TreeItem::is_selected(int p_column) { return cells[p_column].selectable && cells[p_column].selected; } +bool TreeItem::is_any_column_selected() const { + for (const Cell &cell : cells) { + if (cell.selectable && cell.selected) { + return true; + } + } + return false; +} + void TreeItem::set_as_cursor(int p_column) { ERR_FAIL_INDEX(p_column, cells.size()); if (!tree) { @@ -2787,7 +2796,7 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 more_prev_ofs = theme_cache.parent_hl_line_margin; prev_hl_ofs = parent_bottom_y; has_sibling_selection = _is_sibling_branch_selected(c); - } else if (p_item->is_selected(0)) { + } else if (p_item->is_any_column_selected()) { // If parent item is selected (but this item is not), we draw the line using children highlight style. // Siblings of the selected branch can be drawn with a slight offset and their vertical line must appear as highlighted. if (has_sibling_selection) { @@ -2872,10 +2881,8 @@ int Tree::_count_selected_items(TreeItem *p_from) const { } bool Tree::_is_branch_selected(TreeItem *p_from) const { - for (int i = 0; i < columns.size(); i++) { - if (p_from->is_selected(i)) { - return true; - } + if (p_from->is_any_column_selected()) { + return true; } TreeItem *child_item = p_from->get_first_child(); diff --git a/scene/gui/tree.h b/scene/gui/tree.h index 7e41f39261..7ec71b7121 100644 --- a/scene/gui/tree.h +++ b/scene/gui/tree.h @@ -362,6 +362,7 @@ public: bool is_selectable(int p_column) const; bool is_selected(int p_column); + bool is_any_column_selected() const; void select(int p_column); void deselect(int p_column); void set_as_cursor(int p_column);