Add clickable path navigation in Project panel

This commit is contained in:
2026-03-12 20:33:04 +08:00
parent de9d9dfa1c
commit 7d3b05573d
3 changed files with 35 additions and 1 deletions

View File

@@ -33,6 +33,14 @@ void ProjectManager::NavigateBack() {
}
}
void ProjectManager::NavigateToIndex(size_t index) {
if (index >= m_path.size()) return;
while (m_path.size() > index + 1) {
m_path.pop_back();
}
m_selectedIndex = -1;
}
std::string ProjectManager::GetCurrentPath() const {
if (m_path.empty()) return "Assets";
std::string result = "Assets";
@@ -43,6 +51,11 @@ std::string ProjectManager::GetCurrentPath() const {
return result;
}
std::string ProjectManager::GetPathName(size_t index) const {
if (index >= m_path.size()) return "";
return m_path[index]->name;
}
static std::wstring Utf8ToWstring(const std::string& str) {
if (str.empty()) return L"";
int len = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, nullptr, 0);

View File

@@ -17,9 +17,12 @@ public:
void NavigateToFolder(const AssetItemPtr& folder);
void NavigateBack();
void NavigateToIndex(size_t index);
bool CanNavigateBack() const { return m_path.size() > 1; }
std::string GetCurrentPath() const;
size_t GetPathDepth() const { return m_path.size(); }
std::string GetPathName(size_t index) const;
void Initialize(const std::string& projectPath);
void RefreshCurrentFolder();

View File

@@ -37,7 +37,25 @@ void ProjectPanel::Render() {
ImGui::EndDisabled();
ImGui::SameLine();
ImGui::Text("%s", manager.GetCurrentPath().c_str());
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0, 0, 0, 0));
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0, 0, 0, 0));
size_t pathDepth = manager.GetPathDepth();
for (size_t i = 0; i < pathDepth; i++) {
if (i > 0) {
ImGui::SameLine();
ImGui::Text("/");
ImGui::SameLine();
}
std::string name = manager.GetPathName(i);
if (i < pathDepth - 1) {
if (ImGui::Button(name.c_str())) {
manager.NavigateToIndex(i);
}
} else {
ImGui::Text("%s", name.c_str());
}
}
ImGui::PopStyleColor(2);
ImGui::SameLine();
ImGui::SetCursorPosX(ImGui::GetWindowWidth() - 80.0f);