Skip to content

Commit

Permalink
Added prisma
Browse files Browse the repository at this point in the history
  • Loading branch information
denis authored and denis committed Nov 10, 2024
1 parent 2495703 commit 6bdeb55
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 22 deletions.
2 changes: 1 addition & 1 deletion GUI/include/FolderView.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Prisma
ImVec2 m_fontSize;
ImVec2 m_iconSize;

fs::path currentPath;
fs::path m_currentPath;
std::shared_ptr<Texture> m_folder;
std::shared_ptr<Texture> m_file;
std::shared_ptr<Texture> m_back;
Expand Down
49 changes: 28 additions & 21 deletions GUI/src/FolderView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void Prisma::FileBrowser::setPath(const fs::path& path)
{
if (exists(path) && is_directory(path))
{
currentPath = path;
m_currentPath = path;
}
}

Expand All @@ -38,7 +38,8 @@ void Prisma::FileBrowser::listDirectoryContents()
int numColumn = 10;

auto itemSize = ImVec2(windowSize.x / numColumn - 20, windowSize.x / numColumn - 20);

bool isDirectory = false;
fs::directory_entry entryPath;
for (const auto& entry : m_entries)
{
try
Expand All @@ -57,20 +58,8 @@ void Prisma::FileBrowser::listDirectoryContents()
ImGui::ImageButton((void*)m_folder->id(), itemSize);
if (ImGui::IsItemClicked())
{
currentPath = entry.path();
m_entries.clear();

for (const auto& entry : fs::directory_iterator(currentPath))
{
m_entries.push_back(entry);
}

// Custom sort function to ensure folders come first
std::sort(m_entries.begin(), m_entries.end(),
[](const fs::directory_entry& a, const fs::directory_entry& b)
{
return a.is_directory() > b.is_directory();
});
isDirectory = true;
entryPath = entry;
}
}
else
Expand Down Expand Up @@ -106,9 +95,27 @@ void Prisma::FileBrowser::listDirectoryContents()
{
}
}

if (isDirectory)
{
m_currentPath = entryPath.path();
m_entries.clear();

for (const auto& entry : fs::directory_iterator(m_currentPath))
{
m_entries.push_back(entry);
}

// Custom sort function to ensure folders come first
std::sort(m_entries.begin(), m_entries.end(),
[](const fs::directory_entry& a, const fs::directory_entry& b)
{
return a.is_directory() > b.is_directory();
});
}
}

Prisma::FileBrowser::FileBrowser() : currentPath(fs::current_path().parent_path().parent_path().parent_path())
Prisma::FileBrowser::FileBrowser() : m_currentPath(fs::current_path().parent_path().parent_path().parent_path())
{
m_folder = std::make_shared<Texture>();
m_folder->loadTexture({"../../../GUI/icons/folder.png", false, false, false});
Expand All @@ -121,7 +128,7 @@ Prisma::FileBrowser::FileBrowser() : currentPath(fs::current_path().parent_path(
m_iconSize = ImVec2(24, 24);
m_fontSize = m_iconSize;

for (const auto& entry : fs::directory_iterator(currentPath))
for (const auto& entry : fs::directory_iterator(m_currentPath))
{
m_entries.push_back(entry);
}
Expand Down Expand Up @@ -153,13 +160,13 @@ void Prisma::FileBrowser::show(unsigned int width, unsigned int height, float of

if (ImGui::BeginTabItem("Folders"))
{
if (ImGui::ImageButton((void*)m_back->id(), m_iconSize) && currentPath.has_parent_path())
if (ImGui::ImageButton((void*)m_back->id(), m_iconSize) && m_currentPath.has_parent_path())
{
currentPath = currentPath.parent_path();
m_currentPath = m_currentPath.parent_path();

m_entries.clear();

for (const auto& entry : fs::directory_iterator(currentPath))
for (const auto& entry : fs::directory_iterator(m_currentPath))
{
m_entries.push_back(entry);
}
Expand Down
Binary file modified Resources/DefaultScene/default.prisma
Binary file not shown.

0 comments on commit 6bdeb55

Please sign in to comment.