| 248 | } |
| 249 | |
| 250 | void Inspector::drawTreeRecursive(Node* node, int index) |
| 251 | { |
| 252 | std::string str = fmt::format("[{}] {}", index, getNodeTypeName(node)); |
| 253 | |
| 254 | if (node->getTag() != -1) |
| 255 | { |
| 256 | fmt::format_to(std::back_inserter(str), " ({})", node->getTag()); |
| 257 | } |
| 258 | |
| 259 | const auto nodeName = node->getName(); |
| 260 | if (!nodeName.empty()) |
| 261 | { |
| 262 | fmt::format_to(std::back_inserter(str), " \"{}\"", nodeName); |
| 263 | } |
| 264 | |
| 265 | const auto childrenCount = node->getChildrenCount(); |
| 266 | if (childrenCount != 0) |
| 267 | { |
| 268 | fmt::format_to(std::back_inserter(str), " {{{}}}", childrenCount); |
| 269 | } |
| 270 | |
| 271 | auto flags = ImGuiTreeNodeFlags_SpanAvailWidth | ImGuiTreeNodeFlags_SpanFullWidth; |
| 272 | if (_selected_node == node) |
| 273 | { |
| 274 | flags |= ImGuiTreeNodeFlags_Selected; |
| 275 | } |
| 276 | if (node->getChildrenCount() == 0) |
| 277 | { |
| 278 | flags |= ImGuiTreeNodeFlags_Leaf; |
| 279 | } |
| 280 | |
| 281 | const bool is_open = ImGui::TreeNodeEx(node, flags, "%s", str.c_str()); |
| 282 | |
| 283 | if (ImGui::IsItemClicked()) |
| 284 | { |
| 285 | if (node == _selected_node && ImGui::GetIO().KeyAlt) |
| 286 | { |
| 287 | _selected_node = nullptr; |
| 288 | } |
| 289 | else |
| 290 | { |
| 291 | _selected_node = node; |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | if (is_open) |
| 296 | { |
| 297 | const auto &children = node->getChildren(); |
| 298 | for (int i = 0; auto* child : children) |
| 299 | { |
| 300 | if(!child) |
| 301 | { |
| 302 | continue; |
| 303 | } |
| 304 | |
| 305 | drawTreeRecursive(child, i); |
| 306 | i++; |
| 307 | } |