Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Hazelnut/src/Panels/ContentBrowserPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -44,7 +53,16 @@ namespace Hazel {
std::string filenameString = path.filename().string();

ImGui::PushID(filenameString.c_str());

Ref<Texture2D> 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 });

Expand Down
2 changes: 2 additions & 0 deletions Hazelnut/src/Panels/ContentBrowserPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "Hazel/Renderer/Texture.h"

#include <filesystem>
#include <unordered_map>

namespace Hazel {

Expand All @@ -17,6 +18,7 @@ namespace Hazel {

Ref<Texture2D> m_DirectoryIcon;
Ref<Texture2D> m_FileIcon;
std::unordered_map<std::string, Ref<Texture2D>> m_ImageIcons;
};

}