mirror of
https://github.com/godotengine/godot.git
synced 2025-10-19 07:53:26 +00:00
Add method to check if any cell is selected and fix relationship line conditional
This commit is contained in:
parent
b7c5fcaf1e
commit
1a77567029
2 changed files with 13 additions and 5 deletions
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue