diff --git a/Hazelnut/src/Panels/ContentBrowserPanel.cpp b/Hazelnut/src/Panels/ContentBrowserPanel.cpp index 201a458bc..d84daa09d 100644 --- a/Hazelnut/src/Panels/ContentBrowserPanel.cpp +++ b/Hazelnut/src/Panels/ContentBrowserPanel.cpp @@ -27,6 +27,15 @@ namespace Hazel { } } + // Make sure cached texture icons exist, if they dont remove them from cache + for (auto it = m_ImageIcons.cbegin(), next_it = it; it != m_ImageIcons.cend(); it = next_it) + { + ++next_it; + + if (!std::filesystem::exists((*it).first)) + m_ImageIcons.erase(it); + } + static float padding = 16.0f; static float thumbnailSize = 128.0f; float cellSize = thumbnailSize + padding; @@ -44,7 +53,16 @@ namespace Hazel { std::string filenameString = path.filename().string(); ImGui::PushID(filenameString.c_str()); + Ref icon = directoryEntry.is_directory() ? m_DirectoryIcon : m_FileIcon; + if (path.extension().string() == ".png") + { + if (m_ImageIcons.find(path.string()) == m_ImageIcons.end()) + m_ImageIcons[path.string()] = Texture2D::Create(path.string()); + + icon = m_ImageIcons[path.string()]; + } + ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0, 0, 0, 0)); ImGui::ImageButton((ImTextureID)icon->GetRendererID(), { thumbnailSize, thumbnailSize }, { 0, 1 }, { 1, 0 }); diff --git a/Hazelnut/src/Panels/ContentBrowserPanel.h b/Hazelnut/src/Panels/ContentBrowserPanel.h index 0aa71c14c..3cec3451c 100644 --- a/Hazelnut/src/Panels/ContentBrowserPanel.h +++ b/Hazelnut/src/Panels/ContentBrowserPanel.h @@ -3,6 +3,7 @@ #include "Hazel/Renderer/Texture.h" #include +#include namespace Hazel { @@ -17,6 +18,7 @@ namespace Hazel { Ref m_DirectoryIcon; Ref m_FileIcon; + std::unordered_map> m_ImageIcons; }; }