-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFolderTree.cpp
More file actions
134 lines (107 loc) · 6.35 KB
/
FolderTree.cpp
File metadata and controls
134 lines (107 loc) · 6.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
//// FolderTree.cpp ///////////////////////////////////////////////////////////////
//
// ⢀⢀⢀⣤⣤⣤⡀⢀⢀⢀⢀⢀⢀⢠⣤⡄⢀⢀⢀⢀⣠⣤⣤⣤⣤⣤⣤⣤⣤⣤⡀⢀⢀⢀⢠⣤⣄⢀⢀⢀⢀⢀⢀⢀⣤⣤⢀⢀⢀⢀⢀⢀⢀⢀⣀⣄⢀⢀⢠⣄⣀⢀⢀⢀⢀⢀⢀⢀
// ⢀⢀⢀⣿⣿⣿⣷⡀⢀⢀⢀⢀⢀⢸⣿⡇⢀⢀⢀⢀⣿⣿⡟⡛⡛⡛⡛⡛⡛⡛⢁⢀⢀⢀⢀⢻⣿⣦⢀⢀⢀⢀⢠⣾⡿⢃⢀⢀⢀⢀⢀⣠⣾⣿⢿⡟⢀⢀⡙⢿⢿⣿⣦⡀⢀⢀⢀⢀
// ⢀⢀⢀⣿⣿⡛⣿⣷⡀⢀⢀⢀⢀⢸⣿⡇⢀⢀⢀⢀⣿⣿⡇⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⡙⣿⡷⢀⢀⣰⣿⡟⢁⢀⢀⢀⢀⢀⣾⣿⡟⢁⢀⢀⢀⢀⢀⢀⢀⡙⢿⣿⡆⢀⢀⢀
// ⢀⢀⢀⣿⣿⢀⡈⢿⣷⡄⢀⢀⢀⢸⣿⡇⢀⢀⢀⢀⣿⣿⣇⣀⣀⣀⣀⣀⣀⣀⢀⢀⢀⢀⢀⢀⢀⡈⢀⢀⣼⣿⢏⢀⢀⢀⢀⢀⢀⣼⣿⡏⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⡘⣿⣿⢀⢀⢀
// ⢀⢀⢀⣿⣿⢀⢀⡈⢿⣿⡄⢀⢀⢸⣿⡇⢀⢀⢀⢀⣿⣿⣿⢿⢿⢿⢿⢿⢿⢿⢇⢀⢀⢀⢀⢀⢀⢀⢠⣾⣿⣧⡀⢀⢀⢀⢀⢀⢀⣿⣿⡇⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⣿⣿⢀⢀⢀
// ⢀⢀⢀⣿⣿⢀⢀⢀⡈⢿⣿⢀⢀⢸⣿⡇⢀⢀⢀⢀⣿⣿⡇⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⣰⣿⡟⡛⣿⣷⡄⢀⢀⢀⢀⢀⢿⣿⣇⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⣿⣿⢀⢀⢀
// ⢀⢀⢀⣿⣿⢀⢀⢀⢀⡈⢿⢀⢀⢸⣿⡇⢀⢀⢀⢀⡛⡟⢁⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⣼⣿⡟⢀⢀⡈⢿⣿⣄⢀⢀⢀⢀⡘⣿⣿⣄⢀⢀⢀⢀⢀⢀⢀⢀⢀⣼⣿⢏⢀⢀⢀
// ⢀⢀⢀⣿⣿⢀⢀⢀⢀⢀⢀⢀⢀⢸⣿⡇⢀⢀⢀⢀⢀⣀⣀⣀⣀⣀⣀⣀⣀⣀⡀⢀⢀⢀⣠⣾⡿⢃⢀⢀⢀⢀⢀⢻⣿⣧⡀⢀⢀⢀⡈⢻⣿⣷⣦⣄⢀⢀⣠⣤⣶⣿⡿⢋⢀⢀⢀⢀
// ⢀⢀⢀⢿⢿⢀⢀⢀⢀⢀⢀⢀⢀⢸⢿⢃⢀⢀⢀⢀⢻⢿⢿⢿⢿⢿⢿⢿⢿⢿⢃⢀⢀⢀⢿⡟⢁⢀⢀⢀⢀⢀⢀⢀⡙⢿⡗⢀⢀⢀⢀⢀⡈⡉⡛⡛⢀⢀⢹⡛⢋⢁⢀⢀⢀⢀⢀⢀
//
// Author: Mehdy MORVAN
// Date: 06/05/2025
// Description: Source file for the folder tree rendering
//
///////////////////////////////////////////////////////////////////////////////
#include <filesystem>
#include <imgui.h>
#include "AssetManagerWindow.hpp"
#include "IconsFontAwesome.h"
#include "assets/Asset.hpp"
#include "assets/AssetCatalog.hpp"
namespace nexo::editor {
struct FavoriteItem {
std::string_view icon;
std::string_view name;
assets::AssetType type;
[[nodiscard]] std::string getLabel(bool selected) const
{
return std::format("{} {}{}", icon, name, selected ? " " ICON_FA_CHECK : "");
}
};
static void drawFavorites(assets::AssetType& selectedType)
{
ImGuiTreeNodeFlags rootFlags = ImGuiTreeNodeFlags_DefaultOpen | ImGuiTreeNodeFlags_OpenOnDoubleClick;
if (!ImGui::TreeNodeEx(ICON_FA_STAR " Favorites", rootFlags)) return;
static constexpr FavoriteItem favorites[]{{ICON_FA_ADJUST, "Materials", assets::AssetType::MATERIAL},
{ICON_FA_CUBE, "Models", assets::AssetType::MODEL},
{ICON_FA_SQUARE, "Textures", assets::AssetType::TEXTURE}};
for (const auto& fav : favorites) {
const bool isSelected = (fav.type == selectedType);
ImGuiTreeNodeFlags itemFlags = ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_NoTreePushOnOpen;
if (isSelected) itemFlags |= ImGuiTreeNodeFlags_Selected;
const auto label = fav.getLabel(isSelected);
ImGui::TreeNodeEx(label.c_str(), itemFlags);
if (ImGui::IsItemClicked()) {
selectedType = isSelected ? assets::AssetType::UNKNOWN : fav.type;
}
}
ImGui::TreePop();
}
/**
* @brief Displays the context menu for the folder tree.
*
* This method provides options to create a new folder or import assets.
* It is triggered by a right-click on the folder tree.
*/
void AssetManagerWindow::rightClickOnAssetManagerMenu()
{
if (ImGui::MenuItem("New Folder")) m_popupManager.openPopup("Create Folder Popup");
if (ImGui::MenuItem("Import")) LOG(NEXO_INFO, "Importing assets is not implemented yet");
PopupManager::endPopup();
}
void AssetManagerWindow::drawFolderTreeItem(const std::string& name, const std::string& path)
{
ImGuiTreeNodeFlags flags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick;
if (path == m_currentFolder) flags |= ImGuiTreeNodeFlags_Selected;
auto children = m_folderManager.getChildren(path);
if (children.empty()) flags |= ImGuiTreeNodeFlags_Leaf;
ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(230, 180, 80, 255));
ImGui::Text(ICON_FA_FOLDER);
ImGui::PopStyleColor();
ImGui::SameLine();
bool opened = ImGui::TreeNodeEx(name.c_str(), flags);
if (ImGui::IsItemClicked(ImGuiMouseButton_Left) && !ImGui::IsItemToggledOpen()) m_currentFolder = path;
if (ImGui::IsItemClicked(ImGuiMouseButton_Right)) {
m_folderActionState.reset();
m_folderActionState.parentPath = path;
m_popupManager.openPopup("Right click on AssetManager");
}
if (!opened) return;
for (const auto& [childPath, childName] : children) {
drawFolderTreeItem(childName, childPath);
}
ImGui::TreePop();
}
void AssetManagerWindow::drawFolderTree()
{
drawSearchBar(); // Use our new search bar implementation
drawFavorites(m_selectedType);
ImGuiTreeNodeFlags headerFlags = ImGuiTreeNodeFlags_OpenOnDoubleClick;
if (m_currentFolder.empty()) headerFlags |= ImGuiTreeNodeFlags_Selected;
const bool assetsOpen = ImGui::TreeNodeEx(ICON_FA_FOLDER " Assets", headerFlags);
if (ImGui::IsMouseClicked(ImGuiMouseButton_Right) && ImGui::IsWindowHovered()) {
m_folderActionState.reset();
m_popupManager.openPopup("Right click on AssetManager");
}
if (ImGui::IsItemClicked() && !ImGui::IsItemToggledOpen()) m_currentFolder = "";
if (!assetsOpen) return;
auto rootChildren = m_folderManager.getChildren("");
for (const auto& [path, name] : rootChildren) {
drawFolderTreeItem(name, path);
}
ImGui::TreePop();
}
} // namespace nexo::editor