| 4143 | //----------------------------------------------------------------------------- |
| 4144 | |
| 4145 | static void DemoWindowWidgetsTreeNodes() |
| 4146 | { |
| 4147 | if (ImGui::TreeNode("Tree Nodes")) |
| 4148 | { |
| 4149 | IMGUI_DEMO_MARKER("Widgets/Tree Nodes"); |
| 4150 | // See see "Examples -> Property Editor" (ShowExampleAppPropertyEditor() function) for a fancier, data-driven tree. |
| 4151 | if (ImGui::TreeNode("Basic trees")) |
| 4152 | { |
| 4153 | IMGUI_DEMO_MARKER("Widgets/Tree Nodes/Basic trees"); |
| 4154 | for (int i = 0; i < 5; i++) |
| 4155 | { |
| 4156 | // Use SetNextItemOpen() so set the default state of a node to be open. We could |
| 4157 | // also use TreeNodeEx() with the ImGuiTreeNodeFlags_DefaultOpen flag to achieve the same thing! |
| 4158 | if (i == 0) |
| 4159 | ImGui::SetNextItemOpen(true, ImGuiCond_Once); |
| 4160 | |
| 4161 | // Here we use PushID() to generate a unique base ID, and then the "" used as TreeNode id won't conflict. |
| 4162 | // An alternative to using 'PushID() + TreeNode("", ...)' to generate a unique ID is to use 'TreeNode((void*)(intptr_t)i, ...)', |
| 4163 | // aka generate a dummy pointer-sized value to be hashed. The demo below uses that technique. Both are fine. |
| 4164 | ImGui::PushID(i); |
| 4165 | if (ImGui::TreeNode("", "Child %d", i)) |
| 4166 | { |
| 4167 | ImGui::Text("blah blah"); |
| 4168 | ImGui::SameLine(); |
| 4169 | if (ImGui::SmallButton("button")) {} |
| 4170 | ImGui::TreePop(); |
| 4171 | } |
| 4172 | ImGui::PopID(); |
| 4173 | } |
| 4174 | ImGui::TreePop(); |
| 4175 | } |
| 4176 | |
| 4177 | if (ImGui::TreeNode("Hierarchy lines")) |
| 4178 | { |
| 4179 | IMGUI_DEMO_MARKER("Widgets/Tree Nodes/Hierarchy lines"); |
| 4180 | static ImGuiTreeNodeFlags base_flags = ImGuiTreeNodeFlags_DrawLinesFull | ImGuiTreeNodeFlags_DefaultOpen; |
| 4181 | HelpMarker("Default option for DrawLinesXXX is stored in style.TreeLinesFlags"); |
| 4182 | ImGui::CheckboxFlags("ImGuiTreeNodeFlags_DrawLinesNone", &base_flags, ImGuiTreeNodeFlags_DrawLinesNone); |
| 4183 | ImGui::CheckboxFlags("ImGuiTreeNodeFlags_DrawLinesFull", &base_flags, ImGuiTreeNodeFlags_DrawLinesFull); |
| 4184 | ImGui::CheckboxFlags("ImGuiTreeNodeFlags_DrawLinesToNodes", &base_flags, ImGuiTreeNodeFlags_DrawLinesToNodes); |
| 4185 | |
| 4186 | if (ImGui::TreeNodeEx("Parent", base_flags)) |
| 4187 | { |
| 4188 | if (ImGui::TreeNodeEx("Child 1", base_flags)) |
| 4189 | { |
| 4190 | ImGui::Button("Button for Child 1"); |
| 4191 | ImGui::TreePop(); |
| 4192 | } |
| 4193 | if (ImGui::TreeNodeEx("Child 2", base_flags)) |
| 4194 | { |
| 4195 | ImGui::Button("Button for Child 2"); |
| 4196 | ImGui::TreePop(); |
| 4197 | } |
| 4198 | ImGui::Text("Remaining contents"); |
| 4199 | ImGui::Text("Remaining contents"); |
| 4200 | ImGui::TreePop(); |
| 4201 | } |
| 4202 |
no test coverage detected