| 3154 | struct ExampleTreeFuncs |
| 3155 | { |
| 3156 | static void DrawNode(ExampleTreeNode* node, ImGuiSelectionBasicStorage* selection) |
| 3157 | { |
| 3158 | ImGuiTreeNodeFlags tree_node_flags = ImGuiTreeNodeFlags_SpanAvailWidth | ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick; |
| 3159 | tree_node_flags |= ImGuiTreeNodeFlags_NavLeftJumpsToParent; // Enable pressing left to jump to parent |
| 3160 | if (node->Childs.Size == 0) |
| 3161 | tree_node_flags |= ImGuiTreeNodeFlags_Bullet | ImGuiTreeNodeFlags_Leaf; |
| 3162 | if (selection->Contains((ImGuiID)node->UID)) |
| 3163 | tree_node_flags |= ImGuiTreeNodeFlags_Selected; |
| 3164 | |
| 3165 | // Using SetNextItemStorageID() to specify storage id, so we can easily peek into |
| 3166 | // the storage holding open/close stage, using our TreeNodeGetOpen/TreeNodeSetOpen() functions. |
| 3167 | ImGui::SetNextItemSelectionUserData((ImGuiSelectionUserData)(intptr_t)node); |
| 3168 | ImGui::SetNextItemStorageID((ImGuiID)node->UID); |
| 3169 | if (ImGui::TreeNodeEx(node->Name, tree_node_flags)) |
| 3170 | { |
| 3171 | for (ExampleTreeNode* child : node->Childs) |
| 3172 | DrawNode(child, selection); |
| 3173 | ImGui::TreePop(); |
| 3174 | } |
| 3175 | else if (ImGui::IsItemToggledOpen()) |
| 3176 | { |
| 3177 | TreeCloseAndUnselectChildNodes(node, selection); |
| 3178 | } |
| 3179 | } |
| 3180 | |
| 3181 | // When closing a node: 1) close and unselect all child nodes, 2) select parent if any child was selected. |
| 3182 | // FIXME: This is currently handled by user logic but I'm hoping to eventually provide tree node |