Add folding to the Visual Profiler tree

This commit is contained in:
German
2026-04-02 17:23:41 +03:00
parent ee713ccb7c
commit 0d08515a5b
4 changed files with 30 additions and 5 deletions
+20 -1
View File
@@ -114,6 +114,7 @@ void EditorVisualProfiler::clear() {
last_metric = -1;
variables->clear();
//activate->set_pressed(false);
category_folding.clear();
graph_limit = 1000.0f / CLAMP(int(EDITOR_GET("debugger/profiler_target_fps")), 1, 1000);
@@ -161,6 +162,11 @@ void EditorVisualProfiler::_item_selected() {
_update_plot();
}
void EditorVisualProfiler::_item_collapsed(TreeItem *p_item) {
StringName fullpath = p_item->get_metadata(0);
category_folding[fullpath] = p_item->is_collapsed();
}
void EditorVisualProfiler::_update_plot() {
const int w = graph->get_size().width + 1; // `+1` is to prevent from crashing when visual profiler is auto started.
const int h = graph->get_size().height + 1;
@@ -370,9 +376,14 @@ void EditorVisualProfiler::_update_frame(bool p_focus_selected) {
name = name.substr(1);
category->set_metadata(0, m.areas[i].fullpath_cache);
category->set_text(0, name);
category->set_metadata(1, cpu_time);
category->set_metadata(2, gpu_time);
if (category_folding.has(m.areas[i].fullpath_cache)) {
category->set_collapsed(category_folding[m.areas[i].fullpath_cache]);
}
continue;
}
@@ -417,6 +428,14 @@ void EditorVisualProfiler::_update_frame(bool p_focus_selected) {
}
if (ensure_selected) {
// Make visible when it's collapsed.
TreeItem *node = ensure_selected->get_parent();
while (node) {
node->set_collapsed(false);
node = node->get_parent();
}
ensure_selected->select(0);
ensure_selected->set_as_cursor(0);
variables->ensure_cursor_is_visible();
}
updating_frame = false;
@@ -823,7 +842,6 @@ EditorVisualProfiler::EditorVisualProfiler() {
variables = memnew(Tree);
variables->set_custom_minimum_size(Size2(300, 0) * EDSCALE);
variables->set_hide_folding(true);
h_split->add_child(variables);
variables->set_hide_root(true);
variables->set_columns(3);
@@ -842,6 +860,7 @@ EditorVisualProfiler::EditorVisualProfiler() {
variables->set_column_custom_minimum_width(2, 75 * EDSCALE);
variables->set_theme_type_variation("TreeSecondary");
variables->connect("cell_selected", callable_mp(this, &EditorVisualProfiler::_item_selected));
variables->connect("item_collapsed", callable_mp(this, &EditorVisualProfiler::_item_collapsed));
graph = memnew(TextureRect);
graph->set_custom_minimum_size(Size2(250 * EDSCALE, 0));