Merge pull request #60282 from YeldhamDev/backwards_relationships_are_even_harder

This commit is contained in:
Rémi Verschelde 2022-05-02 09:49:09 +02:00 committed by GitHub
commit e61c4dd787
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 34 additions and 28 deletions

View File

@ -1422,14 +1422,15 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
}
if (!p_item->collapsed) { /* if not collapsed, check the children */
TreeItem *c = p_item->children;
int prev_ofs = children_pos.y - cache.offset.y + p_draw_ofs.y;
while (c) {
int child_h = -1;
if (htotal >= 0) {
int child_h = draw_item(children_pos, p_draw_ofs, p_draw_size, c);
child_h = draw_item(children_pos, p_draw_ofs, p_draw_size, c);
}
// Draw relationship lines.
if (cache.draw_relationship_lines > 0 && (!hide_root || c->parent != root)) {
@ -1450,7 +1451,9 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
if (root_pos.y + line_width >= 0) {
// Order of parts on this bend: the horizontal line first, then the vertical line.
if (htotal >= 0) {
VisualServer::get_singleton()->canvas_item_add_line(ci, root_pos, Point2i(parent_pos.x - Math::floor(line_width / 2), root_pos.y), cache.relationship_line_color, line_width);
}
VisualServer::get_singleton()->canvas_item_add_line(ci, Point2i(parent_pos.x, root_pos.y), Point2i(parent_pos.x, prev_ofs), cache.relationship_line_color, line_width);
}
@ -1458,17 +1461,20 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
}
if (child_h < 0) {
if (htotal == -1) {
break; // Last loop done, stop.
}
if (cache.draw_relationship_lines == 0) {
return -1; // break, stop drawing, no need to anymore
} else {
return -1; // No need to draw anymore, full stop.
}
htotal = -1;
children_pos.y = cache.offset.y + p_draw_size.height;
}
} else {
htotal += child_h;
children_pos.y += child_h;
}
}
c = c->next;
}