Draw relationship lines for items offscreen

This commit is contained in:
Michael Alexsander 2022-04-15 16:31:15 -03:00
parent b6968ab060
commit b6c501f9b0
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 */ if (!p_item->collapsed) { /* if not collapsed, check the children */
TreeItem *c = p_item->children; TreeItem *c = p_item->children;
int prev_ofs = children_pos.y - cache.offset.y + p_draw_ofs.y; int prev_ofs = children_pos.y - cache.offset.y + p_draw_ofs.y;
while (c) { while (c) {
int child_h = -1;
if (htotal >= 0) { 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. // Draw relationship lines.
if (cache.draw_relationship_lines > 0 && (!hide_root || c->parent != root)) { 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) { if (root_pos.y + line_width >= 0) {
// Order of parts on this bend: the horizontal line first, then the vertical line. // 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, 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); 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 (child_h < 0) {
if (htotal == -1) {
break; // Last loop done, stop.
}
if (cache.draw_relationship_lines == 0) { if (cache.draw_relationship_lines == 0) {
return -1; // break, stop drawing, no need to anymore return -1; // No need to draw anymore, full stop.
} else { }
htotal = -1; htotal = -1;
children_pos.y = cache.offset.y + p_draw_size.height; children_pos.y = cache.offset.y + p_draw_size.height;
}
} else { } else {
htotal += child_h; htotal += child_h;
children_pos.y += child_h; children_pos.y += child_h;
} }
}
c = c->next; c = c->next;
} }