MCPcopy Create free account
hub / github.com/Open-GD/OpenGD / generateTree

Function generateTree

Source/CocosExplorer.cpp:303–359  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

301}
302
303static void generateTree(Node* node, unsigned int i = 0)
304{
305 std::string str = fmt::format("[{}] {} : {}", i, getNodeName(node), node->getName());
306
307 if (dynamic_cast<GameObject*>(node) != nullptr)
308 {
309 auto gm = dynamic_cast<GameObject*>(node);
310 str += fmt::format(" id {} uid {}", gm->getID(), gm->_uniqueID);
311 }
312
313 if (node->getTag() != -1)
314 str += fmt::format(" ({})", node->getTag());
315 const auto childrenCount = node->getChildrenCount();
316 if (childrenCount)
317 str += fmt::format(" {{{}}}", childrenCount);
318
319 auto flags = ImGuiTreeNodeFlags_SpanAvailWidth | ImGuiTreeNodeFlags_SpanFullWidth;
320 if (selected_node == node)
321 {
322 flags |= ImGuiTreeNodeFlags_Selected;
323 reached_selected_node = true;
324 }
325 if (node->getChildrenCount() == 0)
326 flags |= ImGuiTreeNodeFlags_Leaf;
327
328 const bool is_open = ImGui::TreeNodeEx(node, flags, "%s", str.c_str());
329
330 if (ImGui::IsItemClicked())
331 {
332 if (node == selected_node && ImGui::GetIO().KeyAlt)
333 {
334 selected_node = nullptr;
335 reached_selected_node = false;
336 }
337 else
338 {
339 selected_node = node;
340 reached_selected_node = true;
341 }
342 }
343
344 const auto children_count = node->getChildrenCount();
345
346 if (ImGui::IsItemHovered())
347 hovered_node = node;
348
349 if (is_open)
350 {
351 auto children = node->getChildren();
352 for (unsigned int i = 0; i < children_count; ++i)
353 {
354 auto child = children.at(i);
355 generateTree(static_cast<ax::Node*>(child), i);
356 }
357 ImGui::TreePop();
358 }
359}
360

Callers 1

drawFunction · 0.85

Calls 2

getIDMethod · 0.80
getNodeNameFunction · 0.70

Tested by

no test coverage detected