0xc3 1 месяц назад
Родитель
Сommit
e5e72beddb
2 измененных файлов с 51 добавлено и 25 удалено
  1. 1 0
      src/saura/cmd/sandbox/folder/folder.hpp
  2. 50 25
      src/saura/cmd/sandbox/sandbox.cpp

+ 1 - 0
src/saura/cmd/sandbox/folder/folder.hpp

@@ -12,6 +12,7 @@ public:
   std::vector<Folder> children;
 
   Folder() = default;
+  ~Folder() = default;
   Folder(std::string name) : name(name) {}
 
   Folder *add(std::string name);

+ 50 - 25
src/saura/cmd/sandbox/sandbox.cpp

@@ -1,3 +1,4 @@
+#include <cstring>
 #include <fmt/format.h>
 #include <saura/core/app_base/app_base.hpp>
 
@@ -12,6 +13,10 @@
 #include "server/server.hpp"
 
 namespace saura {
+static bool req_open_ppm = false;
+static bool is_add_node = false;
+static int32_t selected_node = -1;
+
 struct SandboxApp : AppBase {
   std::shared_ptr<ServerAPI> server_api_ctx;
   std::vector<ClientInfo> clients;
@@ -24,12 +29,49 @@ struct SandboxApp : AppBase {
     this->clients = server_api_ctx->fetch_clients(10, 0);
 
     category_root = Folder("root");
-    category_root.add("A");
+    category_root.add("A")->add("B");
+    category_root.add("A")->add("B");
     category_root.add("B");
     category_root.add("C");
     category_root.print();
   }
 
+  void test(Folder *folder) {
+    static uint32_t dep = 0;
+
+    if (folder != nullptr) {
+      spdlog::info("folder: {}", folder->name);
+
+      // for (auto &child : folder->children) {
+      // }
+
+      dep += 1;
+      for (int i = 0; i < folder->children.size(); i++) {
+        auto &f = folder->children[i];
+
+        ImGuiTreeNodeFlags node_flags =
+            ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_SpanAvailWidth;
+        bool open = ImGui::TreeNodeEx(fmt::format("{}#{}", f.name.c_str(), i).c_str(), node_flags, "%s",
+                                      f.name.c_str());
+
+        if (ImGui::IsItemClicked(ImGuiMouseButton_Right)) {
+          spdlog::info("Clieked: {}", i);
+
+          req_open_ppm = true;
+          selected_node = i;
+        }
+
+        test(&f);
+
+        if (open) {
+          ImGui::TreePop();
+        }
+      }
+    }
+
+    dep = 0;
+  }
+
   void update(double dt) override {
     ImGui::SetNextWindowPos({0.0f, 0.0f});
     ImGui::SetNextWindowSize(ImGui::GetIO().DisplaySize);
@@ -48,9 +90,6 @@ struct SandboxApp : AppBase {
       }
 
       if (ImGui::BeginTabItem("Категории")) {
-        static bool req_open_ppm = false;
-        static bool is_add_node = false;
-        static int32_t selected_node = -1;
 
         if (ImGui::TreeNodeEx("Root Node", 0)) {
           if (ImGui::IsItemClicked(ImGuiMouseButton_Right)) {
@@ -58,25 +97,8 @@ struct SandboxApp : AppBase {
             selected_node = -1;
           }
 
-          for (int i = 0; i < category_root.children.size(); i++) {
-            auto &category = category_root.children[i];
-
-            ImGuiTreeNodeFlags node_flags = ImGuiTreeNodeFlags_OpenOnArrow |
-                                            ImGuiTreeNodeFlags_SpanAvailWidth;
-            bool open = ImGui::TreeNodeEx((void *)(intptr_t)(i), node_flags,
-                                          "%s", category.name.c_str());
+          test(&category_root);
 
-            if (ImGui::IsItemClicked(ImGuiMouseButton_Right)) {
-              spdlog::info("Clieked: {}", i);
-
-              req_open_ppm = true;
-              selected_node = i;
-            }
-
-            if (open) {
-              ImGui::TreePop();
-            }
-          }
           ImGui::TreePop();
         }
 
@@ -110,9 +132,12 @@ struct SandboxApp : AppBase {
             ImGui::InputText("Name", buf, sizeof(buf));
 
             if (ImGui::Button("Создать", ImVec2(120, 0))) {
-              category_root.add(std::string(buf));
-              is_add_node = false;
-              ImGui::CloseCurrentPopup();
+              if (buf[0] != 0) {
+                category_root.children[selected_node].add(std::string(buf));
+                is_add_node = false;
+                memset(buf, 0, sizeof(buf));
+                ImGui::CloseCurrentPopup();
+              }
             }
           }