mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 21:01:52 +00:00
Spread empty space between directory entries, better parent directory handling, fixed id collision
This commit is contained in:
@@ -673,29 +673,22 @@ namespace GlitchyEditor.EditWindows
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
directoryEntries = currentDirectoryNode.Children;
|
directoryEntries = scope:: List<TreeNode<AssetNode>>();
|
||||||
|
currentDirectoryNode.Children.CopyTo(directoryEntries);
|
||||||
|
|
||||||
// show back button (".."-File)
|
|
||||||
if (currentDirectoryNode.Parent != _manager.AssetHierarchy.RootNode)
|
if (currentDirectoryNode.Parent != _manager.AssetHierarchy.RootNode)
|
||||||
{
|
{
|
||||||
ImGui.PushID("Back");
|
directoryEntries.Add(currentDirectoryNode.Parent);
|
||||||
|
|
||||||
DrawDirectoryEntry(currentDirectoryNode.Parent, .ParentDirectory);
|
|
||||||
|
|
||||||
// X-Coordinate of the right side of the current entry.
|
|
||||||
float currentButtonRight = ImGui.GetItemRectMax().x;
|
|
||||||
// Expected right-Coordinate if next entry was on the same line.
|
|
||||||
float expectedButtonRight = currentButtonRight + style.ItemSpacing.x + DirectoryItemSize.X;
|
|
||||||
|
|
||||||
// If the next button won't fit on the same line we start a new line.
|
|
||||||
if (expectedButtonRight < window_visible_x2)
|
|
||||||
ImGui.SameLine();
|
|
||||||
|
|
||||||
ImGui.PopID();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
directoryEntries.Sort((entry1, entry2) => {
|
directoryEntries.Sort((entry1, entry2) => {
|
||||||
|
// Place parent directory at front
|
||||||
|
if (entry1 == currentDirectoryNode.Parent)
|
||||||
|
return -1;
|
||||||
|
if (entry2 == currentDirectoryNode.Parent)
|
||||||
|
return 1;
|
||||||
|
|
||||||
// Try to sort so that directories are before files.
|
// Try to sort so that directories are before files.
|
||||||
int score = entry2->IsDirectory <=> entry1->IsDirectory;
|
int score = entry2->IsDirectory <=> entry1->IsDirectory;
|
||||||
|
|
||||||
@@ -708,23 +701,31 @@ namespace GlitchyEditor.EditWindows
|
|||||||
return score;
|
return score;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ImGui.PushStyleVar(.ItemSpacing, float2(0, 0));
|
||||||
|
defer ImGui.PopStyleVar();
|
||||||
|
|
||||||
|
float buttonsPerRow = ImGui.GetContentRegionAvail().x / (DirectoryItemSize.X + ImGui.GetStyle().ItemSpacing.x);
|
||||||
|
int actualButtonsPerRow = (int)buttonsPerRow;
|
||||||
|
|
||||||
|
float actualSpace = (ImGui.GetContentRegionAvail().x - actualButtonsPerRow * DirectoryItemSize.X) / (actualButtonsPerRow + 1);
|
||||||
|
|
||||||
|
int column = 0;
|
||||||
|
|
||||||
for (var entry in directoryEntries)
|
for (var entry in directoryEntries)
|
||||||
{
|
{
|
||||||
if (!entry->Name.Contains(searchFilter, true))
|
if (!entry->Name.Contains(searchFilter, true))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
ImGui.PushID(entry->Name);
|
ImGui.PushID(entry->Path);
|
||||||
|
|
||||||
DrawDirectoryEntry(entry, .Default);
|
DrawDirectoryEntry(entry, entry == currentDirectoryNode.Parent ? .ParentDirectory : .Default);
|
||||||
|
|
||||||
// X-Coordinate of the right side of the current entry.
|
column++;
|
||||||
float currentButtonRight = ImGui.GetItemRectMax().x;
|
|
||||||
// Expected right-Coordinate if next entry was on the same line.
|
|
||||||
float expectedButtonRight = currentButtonRight + style.ItemSpacing.x + DirectoryItemSize.X;
|
|
||||||
|
|
||||||
// If we aren't the last entry and the next button won't fit on the same line we start a new line.
|
if (column < actualButtonsPerRow)
|
||||||
if ((entry != directoryEntries.Back || _showNewFile) && expectedButtonRight < window_visible_x2)
|
ImGui.SameLine((DirectoryItemSize.X + actualSpace) * column);
|
||||||
ImGui.SameLine();
|
else
|
||||||
|
column = 0;
|
||||||
|
|
||||||
ImGui.PopID();
|
ImGui.PopID();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user