Merge pull request #110759 from precup/scene-tree-dock-optimizations

Optimize tree size computation and the scene tree dock filter
This commit is contained in:
Thaddeus Crews
2026-01-28 12:27:06 -06:00
4 changed files with 27 additions and 6 deletions

View File

@@ -984,6 +984,17 @@ void SceneTreeEditor::_update_tree(bool p_scroll_to_selected) {
}
bool SceneTreeEditor::_update_filter(TreeItem *p_parent, bool p_scroll_to_selected) {
TreeItem *last_selected = nullptr;
bool result = _update_filter_helper(p_parent, p_scroll_to_selected, last_selected);
if (p_scroll_to_selected && last_selected) {
// Scrolling to the first selected in the _update_filter call above followed by the last
// selected here is enough to frame all selected items as well as possible.
callable_mp(tree, &Tree::scroll_to_item).call_deferred(last_selected, false);
}
return result;
}
bool SceneTreeEditor::_update_filter_helper(TreeItem *p_parent, bool p_scroll_to_selected, TreeItem *&r_last_selected) {
if (!p_parent) {
p_parent = tree->get_root();
filter_term_warning.clear();
@@ -1038,7 +1049,8 @@ bool SceneTreeEditor::_update_filter(TreeItem *p_parent, bool p_scroll_to_select
bool keep_for_children = false;
for (TreeItem *child = p_parent->get_first_child(); child; child = child->get_next()) {
// Always keep if at least one of the children are kept.
keep_for_children = _update_filter(child, p_scroll_to_selected) || keep_for_children;
// Only scroll if we haven't already found a child to scroll to.
keep_for_children = _update_filter_helper(child, p_scroll_to_selected && !keep_for_children, r_last_selected) || keep_for_children;
}
if (!is_root) {
@@ -1110,9 +1122,13 @@ bool SceneTreeEditor::_update_filter(TreeItem *p_parent, bool p_scroll_to_select
if (editor_selection) {
Node *n = get_node(p_parent->get_metadata(0));
if (selectable) {
if (p_scroll_to_selected && n && editor_selection->is_selected(n)) {
// Needs to be deferred to account for possible root visibility change.
callable_mp(tree, &Tree::scroll_to_item).call_deferred(p_parent, false);
if (n && editor_selection->is_selected(n)) {
if (p_scroll_to_selected) {
// Needs to be deferred to account for possible root visibility change.
callable_mp(tree, &Tree::scroll_to_item).call_deferred(p_parent, false);
} else {
r_last_selected = p_parent;
}
}
}
}

View File

@@ -145,6 +145,7 @@ class SceneTreeEditor : public Control {
void _test_update_tree();
bool _update_filter(TreeItem *p_parent = nullptr, bool p_scroll_to_selected = false);
bool _update_filter_helper(TreeItem *p_parent, bool p_scroll_to_selected, TreeItem *&r_last_selected);
bool _node_matches_class_term(const Node *p_item_node, const String &p_term);
bool _item_matches_all_terms(TreeItem *p_item, const PackedStringArray &p_terms);
void _tree_changed();

View File

@@ -2052,7 +2052,8 @@ int Tree::compute_item_height(TreeItem *p_item) const {
for (int i = 0; i < columns.size(); i++) {
height = MAX(height, p_item->get_minimum_size(i).y);
}
int item_min_height = MAX(theme_cache.font->get_height(theme_cache.font_size), p_item->get_custom_minimum_height());
int font_height = cache.font_height != -1 ? cache.font_height : theme_cache.font->get_height(theme_cache.font_size);
int item_min_height = MAX(font_height, p_item->get_custom_minimum_height());
if (height < item_min_height) {
height = item_min_height;
}
@@ -5118,7 +5119,8 @@ void Tree::_notification(int p_what) {
} break;
case NOTIFICATION_DRAW: {
v_scroll->set_custom_step(theme_cache.font->get_height(theme_cache.font_size));
int font_height = cache.font_height != -1 ? cache.font_height : theme_cache.font->get_height(theme_cache.font_size);
v_scroll->set_custom_step(font_height);
update_scrollbars();
RID ci = get_canvas_item();
@@ -5264,6 +5266,7 @@ void Tree::set_self_modulate(const Color &p_self_modulate) {
}
void Tree::_update_all() {
cache.font_height = theme_cache.font->get_height(theme_cache.font_size);
for (int i = 0; i < columns.size(); i++) {
update_column(i);
}

View File

@@ -709,6 +709,7 @@ private:
int hover_button_index_in_column = -1;
bool rtl = false;
int font_height = -1;
} cache;
int _get_title_button_height() const;