mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 21:01:52 +00:00
Search in Content Browser (and added ForEach in TreeNode)
This commit is contained in:
@@ -48,18 +48,38 @@ namespace GlitchyEditor.EditWindows
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui.Columns(2);
|
ImGui.PushStyleVar(.CellPadding, .(0, 0));
|
||||||
|
|
||||||
ImGui.BeginChild("Sidebar");
|
bool alt_pressed = ImGui.GetIO().KeyAlt;
|
||||||
|
|
||||||
|
if (ImGui.BeginTable("table", 2, .BordersInnerV | .Resizable | .Reorderable | .NoPadOuterX))
|
||||||
|
{
|
||||||
|
if (alt_pressed)
|
||||||
|
{
|
||||||
|
// Header anzeigen, damit sie neu angeordnet werden können
|
||||||
|
ImGui.TableSetupColumn("Folder Hierarchy");
|
||||||
|
ImGui.TableSetupColumn("Files");
|
||||||
|
ImGui.TableHeadersRow();
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui.TableNextRow();
|
||||||
|
ImGui.TableSetColumnIndex(0);
|
||||||
|
|
||||||
|
if (ImGui.BeginChild("Sidebar"))
|
||||||
|
{
|
||||||
DrawDirectorySideBar();
|
DrawDirectorySideBar();
|
||||||
|
|
||||||
ImGui.EndChild();
|
ImGui.EndChild();
|
||||||
|
}
|
||||||
|
|
||||||
ImGui.NextColumn();
|
ImGui.TableNextColumn();
|
||||||
|
|
||||||
ImGui.BeginChild("Files");
|
DrawSearchBar();
|
||||||
|
|
||||||
|
ImGui.Separator();
|
||||||
|
|
||||||
|
if (ImGui.BeginChild("Files"))
|
||||||
|
{
|
||||||
DrawCurrentDirectory();
|
DrawCurrentDirectory();
|
||||||
|
|
||||||
// Context menu when clicking on the background.
|
// Context menu when clicking on the background.
|
||||||
@@ -70,12 +90,28 @@ namespace GlitchyEditor.EditWindows
|
|||||||
}
|
}
|
||||||
|
|
||||||
ImGui.EndChild();
|
ImGui.EndChild();
|
||||||
|
}
|
||||||
|
|
||||||
ImGui.Columns(1);
|
ImGui.EndTable();
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui.PopStyleVar(1);
|
||||||
|
|
||||||
ImGui.End();
|
ImGui.End();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char8[256] _filesFilter = .();
|
||||||
|
bool _searchEverywhere;
|
||||||
|
|
||||||
|
private void DrawSearchBar()
|
||||||
|
{
|
||||||
|
ImGui.TextUnformatted("Search:");
|
||||||
|
ImGui.SameLine();
|
||||||
|
ImGui.InputText("##search", &_filesFilter, _filesFilter.Count);
|
||||||
|
ImGui.SameLine();
|
||||||
|
ImGui.Checkbox("Search everywhere", &_searchEverywhere);
|
||||||
|
}
|
||||||
|
|
||||||
/// Renders the context menu that is shown when the user right clicks on the background of the file browser.
|
/// Renders the context menu that is shown when the user right clicks on the background of the file browser.
|
||||||
private void ShowCurrentFolderContextMenu()
|
private void ShowCurrentFolderContextMenu()
|
||||||
{
|
{
|
||||||
@@ -139,13 +175,30 @@ namespace GlitchyEditor.EditWindows
|
|||||||
/// Renders the contents of _currentDirectory.
|
/// Renders the contents of _currentDirectory.
|
||||||
private void DrawCurrentDirectory()
|
private void DrawCurrentDirectory()
|
||||||
{
|
{
|
||||||
if (_currentDirectory.IsEmpty)
|
List<TreeNode<AssetNode>> files = null;
|
||||||
return;
|
|
||||||
|
|
||||||
ImGui.Style* style = ImGui.GetStyle();
|
ImGui.Style* style = ImGui.GetStyle();
|
||||||
|
|
||||||
float window_visible_x2 = ImGui.GetWindowPos().x + ImGui.GetWindowContentRegionMax().x;
|
float window_visible_x2 = ImGui.GetWindowPos().x + ImGui.GetWindowContentRegionMax().x;
|
||||||
|
|
||||||
|
StringView searchFilter = StringView(&_filesFilter);
|
||||||
|
|
||||||
|
if (_searchEverywhere && searchFilter.Length > 0)
|
||||||
|
{
|
||||||
|
files = scope:: List<TreeNode<AssetNode>>();
|
||||||
|
_manager.AssetHierarchy.[Friend]_assetHierarchy.ForEach(scope (node) =>
|
||||||
|
{
|
||||||
|
if (node->Name.Contains(searchFilter, true))
|
||||||
|
{
|
||||||
|
files.Add(node);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (_currentDirectory.IsEmpty)
|
||||||
|
return;
|
||||||
|
|
||||||
// Get the node of the current directory.
|
// Get the node of the current directory.
|
||||||
var currentDirectoryNode = _manager.AssetHierarchy.GetNodeFromPath(_currentDirectory);
|
var currentDirectoryNode = _manager.AssetHierarchy.GetNodeFromPath(_currentDirectory);
|
||||||
|
|
||||||
@@ -156,6 +209,9 @@ namespace GlitchyEditor.EditWindows
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
files = currentDirectoryNode->Children;
|
||||||
|
|
||||||
|
// show back button (".."-File)
|
||||||
if (currentDirectoryNode->Parent != null)
|
if (currentDirectoryNode->Parent != null)
|
||||||
{
|
{
|
||||||
ImGui.PushID("Back");
|
ImGui.PushID("Back");
|
||||||
@@ -173,9 +229,13 @@ namespace GlitchyEditor.EditWindows
|
|||||||
|
|
||||||
ImGui.PopID();
|
ImGui.PopID();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (var entry in currentDirectoryNode->Children)
|
for (var entry in files)
|
||||||
{
|
{
|
||||||
|
if (!entry->Name.Contains(searchFilter, true))
|
||||||
|
continue;
|
||||||
|
|
||||||
ImGui.PushID(entry->Name);
|
ImGui.PushID(entry->Name);
|
||||||
|
|
||||||
DrawDirectoryItem(entry);
|
DrawDirectoryItem(entry);
|
||||||
@@ -186,7 +246,7 @@ namespace GlitchyEditor.EditWindows
|
|||||||
float expectedButtonRight = currentButtonRight + style.ItemSpacing.x + DirectoryItemSize.X;
|
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 we aren't the last entry and the next button won't fit on the same line we start a new line.
|
||||||
if (entry != currentDirectoryNode->Children.Back && expectedButtonRight < window_visible_x2)
|
if (entry != files.Back && expectedButtonRight < window_visible_x2)
|
||||||
ImGui.SameLine();
|
ImGui.SameLine();
|
||||||
|
|
||||||
ImGui.PopID();
|
ImGui.PopID();
|
||||||
|
|||||||
@@ -56,6 +56,62 @@ namespace GlitchyEngine.Collections
|
|||||||
{
|
{
|
||||||
return ref node.Value;
|
return ref node.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public delegate void ElementFunc(TreeNode<T> currentNode);
|
||||||
|
|
||||||
|
public enum IterationMode
|
||||||
|
{
|
||||||
|
BreadthFirst,
|
||||||
|
DepthFirst
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ForEach(ElementFunc func, IterationMode iterationMode = .DepthFirst)
|
||||||
|
{
|
||||||
|
if (iterationMode == .BreadthFirst)
|
||||||
|
{
|
||||||
|
ForEach_BreadthFirst(func);
|
||||||
|
}
|
||||||
|
else if (iterationMode == .DepthFirst)
|
||||||
|
{
|
||||||
|
ForEach_DepthFirst(func);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ForEach_BreadthFirst(ElementFunc func)
|
||||||
|
{
|
||||||
|
Queue<TreeNode<T>> nodes = scope .();
|
||||||
|
nodes.Add(this);
|
||||||
|
|
||||||
|
while (!nodes.IsEmpty)
|
||||||
|
{
|
||||||
|
TreeNode<T> node = nodes.PopFront();
|
||||||
|
|
||||||
|
func(node);
|
||||||
|
|
||||||
|
for (var child in node.Children)
|
||||||
|
{
|
||||||
|
nodes.Add(child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ForEach_DepthFirst(ElementFunc func)
|
||||||
|
{
|
||||||
|
List<TreeNode<T>> nodes = scope .();
|
||||||
|
nodes.Add(this);
|
||||||
|
|
||||||
|
while (!nodes.IsEmpty)
|
||||||
|
{
|
||||||
|
TreeNode<T> node = nodes.PopBack();
|
||||||
|
|
||||||
|
func(node);
|
||||||
|
|
||||||
|
for (var child in node.Children)
|
||||||
|
{
|
||||||
|
nodes.Add(child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
|
|||||||
Reference in New Issue
Block a user