From 191289ec118b562e21f16903f8fb7ba9ddbb2af5 Mon Sep 17 00:00:00 2001 From: Michael Alexsander Date: Thu, 4 Dec 2025 17:59:49 -0300 Subject: [PATCH] Hide arrows when they go past the column titles on `Tree`s --- scene/gui/tree.cpp | 57 +++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index c254b51272f..e47c6753801 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -2708,41 +2708,42 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 } } - // Draw the folding arrow. - if (!p_item->disable_folding && !hide_folding && p_item->first_child && p_item->get_visible_child_count() != 0) { // Has visible children, draw the guide box. + if (p_pos.y + label_h - theme_cache.offset.y >= 0) { + // Draw the folding arrow. + if (!p_item->disable_folding && !hide_folding && p_item->first_child && p_item->get_visible_child_count() != 0) { // Has visible children, draw the guide box. + Ref arrow; - Ref arrow; - - if (p_item->collapsed) { - if (rtl) { - arrow = theme_cache.arrow_collapsed_mirrored; + if (p_item->collapsed) { + if (rtl) { + arrow = theme_cache.arrow_collapsed_mirrored; + } else { + arrow = theme_cache.arrow_collapsed; + } } else { - arrow = theme_cache.arrow_collapsed; + arrow = theme_cache.arrow; } - } else { - arrow = theme_cache.arrow; - } - Size2 arrow_full_size = arrow->get_size(); + Size2 arrow_full_size = arrow->get_size(); - Point2 apos = p_pos + Point2i(0, (label_h - arrow_full_size.height) / 2) - theme_cache.offset + p_draw_ofs; - apos.x += theme_cache.item_margin - arrow_full_size.width; + Point2 apos = p_pos + Point2i(0, (label_h - arrow_full_size.height) / 2) - theme_cache.offset + p_draw_ofs; + apos.x += theme_cache.item_margin - arrow_full_size.width; - Size2 arrow_draw_size = arrow_full_size; - int out_width = p_pos.x + theme_cache.item_margin - get_column_width(0); - if (out_width > 0) { - arrow_draw_size.width -= out_width; - } - - if (arrow_draw_size.width > 0) { - apos = convert_rtl_position(apos, arrow_draw_size.width); - Point2 src_pos = Point2(); - if (rtl) { - src_pos = Point2(arrow_full_size.width - arrow_draw_size.width, 0); + Size2 arrow_draw_size = arrow_full_size; + int out_width = p_pos.x + theme_cache.item_margin - get_column_width(0); + if (out_width > 0) { + arrow_draw_size.width -= out_width; + } + + if (arrow_draw_size.width > 0) { + apos = convert_rtl_position(apos, arrow_draw_size.width); + Point2 src_pos = Point2(); + if (rtl) { + src_pos = Point2(arrow_full_size.width - arrow_draw_size.width, 0); + } + Rect2 arrow_rect = Rect2(apos, arrow_draw_size); + Rect2 arrow_src_rect = Rect2(src_pos, arrow_draw_size); + arrow->draw_rect_region(ci, arrow_rect, arrow_src_rect); } - Rect2 arrow_rect = Rect2(apos, arrow_draw_size); - Rect2 arrow_src_rect = Rect2(src_pos, arrow_draw_size); - arrow->draw_rect_region(ci, arrow_rect, arrow_src_rect); } } }