diff --git a/modules/imgui/src/guipropertycomponent.cpp b/modules/imgui/src/guipropertycomponent.cpp index bcc31d9ac5..416830d85b 100644 --- a/modules/imgui/src/guipropertycomponent.cpp +++ b/modules/imgui/src/guipropertycomponent.cpp @@ -107,6 +107,23 @@ namespace { ); }; + void simplifyTree(TreeNode& node) { + // Merging consecutive nodes if they only have a single child + + for (const std::unique_ptr& c : node.children) { + simplifyTree(*c); + } + + if ((node.children.size() == 1) && (node.nodes.empty())) { + node.path = node.path + "/" + node.children[0]->path; + node.nodes = std::move(node.children[0]->nodes); + std::vector> cld = std::move( + node.children[0]->children + ); + node.children = std::move(cld); + } + } + void renderTree(const TreeNode& node, const std::function& renderFunc) { if (node.path.empty() || ImGui::TreeNode(node.path.c_str())) { for (const std::unique_ptr& c : node.children) { @@ -326,6 +343,8 @@ void GuiPropertyComponent::render() { addPathToTree(root, paths, nOwner); } + simplifyTree(root); + renderTree(root, renderProp); ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 20.f);