// // Created by spenc on 5/21/2025. // #include "FileBrowser.h" #include "systems/AssetManager.h" #include "imgui.h" #include namespace OX { static std::string s_CurrentPath = "res://"; static void DrawGrid(const std::shared_ptr& node) { const int columns = 4; int itemIndex = 0; ImGui::BeginChild("FileGrid", ImVec2(0, 0), false, ImGuiWindowFlags_AlwaysUseWindowPadding); ImGui::Columns(columns, nullptr, false); for (const auto& child : node->children) { std::string label = (child->isDirectory ? "[folder] " : "[file] ") + child->name; if (ImGui::Selectable(label.c_str(), false, ImGuiSelectableFlags_AllowDoubleClick, ImVec2(0, 64))) { if (child->isDirectory && ImGui::IsMouseDoubleClicked(0)) { s_CurrentPath = child->path; } } ImGui::NextColumn(); ++itemIndex; } ImGui::Columns(1); ImGui::EndChild(); } static std::shared_ptr FindNode(const std::shared_ptr& root, const std::string& targetPath) { if (root->path == targetPath) return root; for (const auto& child : root->children) { if (child->isDirectory) { auto found = FindNode(child, targetPath); if (found) return found; } } return nullptr; } void FileBrowser::Draw() { ImGui::Begin("File Browser"); ImGui::Text("Current Path: %s", s_CurrentPath.c_str()); ImGui::Separator(); auto root = AssetManager::GetFileTree(); auto currentNode = FindNode(root, s_CurrentPath); if (currentNode) { DrawGrid(currentNode); } else { ImGui::Text("Path not found: %s", s_CurrentPath.c_str()); } ImGui::End(); } } // namespace OX