mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-16 08:51:26 -06:00
Simplify property tree if a tree node only has a single child and no scenegraph nodes
This commit is contained in:
@@ -107,6 +107,23 @@ namespace {
|
||||
);
|
||||
};
|
||||
|
||||
void simplifyTree(TreeNode& node) {
|
||||
// Merging consecutive nodes if they only have a single child
|
||||
|
||||
for (const std::unique_ptr<TreeNode>& 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<std::unique_ptr<TreeNode>> cld = std::move(
|
||||
node.children[0]->children
|
||||
);
|
||||
node.children = std::move(cld);
|
||||
}
|
||||
}
|
||||
|
||||
void renderTree(const TreeNode& node, const std::function<void (openspace::properties::PropertyOwner*)>& renderFunc) {
|
||||
if (node.path.empty() || ImGui::TreeNode(node.path.c_str())) {
|
||||
for (const std::unique_ptr<TreeNode>& 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);
|
||||
|
||||
Reference in New Issue
Block a user