MCPcopy Create free account
hub / github.com/Joe1sn/S-inject / TreeGetNextNodeInVisibleOrder

Method TreeGetNextNodeInVisibleOrder

extern/ImGui/imgui_demo.cpp:3102–3120  ·  view source on GitHub ↗

Interpolate in *user-visible order* AND only *over opened nodes*. If you have a sequential mapping tables (e.g. generated after a filter/search pass) this would be simpler. Here the tricks are that: - we store/maintain ExampleTreeNode::IndexInParent which allows implementing a linear iterator easily, without searches, without recursion. this could be replaced by a search in parent, aka 'int index_

Source from the content-addressed store, hash-verified

3100 // - we call SetNextItemStorageID() before our TreeNode() calls with an ID which doesn't relate to UI stack,
3101 // making it easier to call TreeNodeGetOpen()/TreeNodeSetOpen() from any location.
3102 static ExampleTreeNode* TreeGetNextNodeInVisibleOrder(ExampleTreeNode* curr_node, ExampleTreeNode* last_node)
3103 {
3104 // Reached last node
3105 if (curr_node == last_node)
3106 return NULL;
3107
3108 // Recurse into childs. Query storage to tell if the node is open.
3109 if (curr_node->Childs.Size > 0 && TreeNodeGetOpen(curr_node))
3110 return curr_node->Childs[0];
3111
3112 // Next sibling, then into our own parent
3113 while (curr_node->Parent != NULL)
3114 {
3115 if (curr_node->IndexInParent + 1 < curr_node->Parent->Childs.Size)
3116 return curr_node->Parent->Childs[curr_node->IndexInParent + 1];
3117 curr_node = curr_node->Parent;
3118 }
3119 return NULL;
3120 }
3121
3122 }; // ExampleTreeFuncs
3123

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected