Asset Browser: Navigation abstraction, show current path

This commit is contained in:
Simon Lübeß
2025-07-06 12:47:17 +02:00
parent 941cc8b767
commit 4b91116b51
@@ -74,6 +74,9 @@ namespace GlitchyEditor.EditWindows
public StringView CurrentDirectoryPath => _currentIndex >= 0 ? _history[_currentIndex] : ""; public StringView CurrentDirectoryPath => _currentIndex >= 0 ? _history[_currentIndex] : "";
public bool CanGoBack => _currentIndex > 0;
public bool CanGoForward => (_currentIndex + 1) < _history.Count;
public void Navigate(StringView nextPath) public void Navigate(StringView nextPath)
{ {
_currentIndex++; _currentIndex++;
@@ -107,7 +110,7 @@ namespace GlitchyEditor.EditWindows
public bool Back() public bool Back()
{ {
if (_currentIndex > 0) if (CanGoBack)
{ {
_currentIndex--; _currentIndex--;
return true; return true;
@@ -117,7 +120,7 @@ namespace GlitchyEditor.EditWindows
public bool Forward() public bool Forward()
{ {
if ((_currentIndex + 1) < _history.Count) if (CanGoForward)
{ {
_currentIndex++; _currentIndex++;
return true; return true;
@@ -130,6 +133,17 @@ namespace GlitchyEditor.EditWindows
private append History _directoryHistory = .(); private append History _directoryHistory = .();
public StringView CurrentDirectory => _directoryHistory.CurrentDirectoryPath; public StringView CurrentDirectory => _directoryHistory.CurrentDirectoryPath;
TreeNode<AssetNode> _currentDirectoryNode => {
Result<TreeNode<AssetNode>> currentDirectoryNode = _manager.AssetHierarchy.GetNodeFromPath(_directoryHistory.CurrentDirectoryPath);
if (currentDirectoryNode case .Ok(TreeNode<AssetNode> currentDirectory))
{
return currentDirectory;
}
null
};
private append List<String> _selectedFiles = .() ~ ClearAndDeleteItems!(_); private append List<String> _selectedFiles = .() ~ ClearAndDeleteItems!(_);
@@ -201,6 +215,38 @@ namespace GlitchyEditor.EditWindows
bool _wantsDelete = false; bool _wantsDelete = false;
private void NavigateForward()
{
if (_directoryHistory.Forward())
{
_selectedFiles.ClearAndDeleteItems();
}
}
private void NavigateBack()
{
if (_directoryHistory.Back())
{
_selectedFiles.ClearAndDeleteItems();
}
}
private void Navigate(TreeNode<AssetNode> node)
{
_directoryHistory.Navigate(node->Path);
_selectedFiles.ClearAndDeleteItems();
}
private bool CanNavigateUp => _currentDirectoryNode.Parent != _manager.AssetHierarchy.RootNode;
private void NavigateUp()
{
if (CanNavigateUp)
{
Navigate(_currentDirectoryNode.Parent);
}
}
protected override void InternalShow() protected override void InternalShow()
{ {
_manager.Update(); _manager.Update();
@@ -242,9 +288,9 @@ namespace GlitchyEditor.EditWindows
_directoryHistory.Replace(_manager.AssetDirectory); _directoryHistory.Replace(_manager.AssetDirectory);
} }
let originalWindowPadding = ImGui.GetStyle().WindowPadding; /*let originalWindowPadding = ImGui.GetStyle().WindowPadding;
ImGui.PushStyleVar(.WindowPadding, float2(0,0)); ImGui.PushStyleVar(.WindowPadding, float2(0,0));
defer ImGui.PopStyleVar(); defer ImGui.PopStyleVar();*/
if(!ImGui.Begin(s_WindowTitle, &_open, .None)) if(!ImGui.Begin(s_WindowTitle, &_open, .None))
{ {
@@ -252,7 +298,9 @@ namespace GlitchyEditor.EditWindows
return; return;
} }
ImGui.SetCursorPosY(ImGui.GetCursorPosY() + originalWindowPadding.y); //ImGui.SetCursorPosY(ImGui.GetCursorPosY() + originalWindowPadding.y);
DrawNavigationBar();
// Update selection modifies // Update selection modifies
{ {
@@ -657,11 +705,11 @@ namespace GlitchyEditor.EditWindows
if (Input.IsKeyPressing(.Left)) if (Input.IsKeyPressing(.Left))
{ {
_directoryHistory.Back(); NavigateBack();
} }
if (Input .IsKeyPressing(.Right)) if (Input .IsKeyPressing(.Right))
{ {
_directoryHistory.Forward(); NavigateForward();
} }
} }
@@ -1247,5 +1295,78 @@ namespace GlitchyEditor.EditWindows
Log.EngineLogger.Error("Failed to open file."); Log.EngineLogger.Error("Failed to open file.");
} }
} }
void DrawNavigationBar()
{
ImGui.BeginDisabled(!_directoryHistory.CanGoBack);
if (ImGui.Button("<"))
{
NavigateBack();
}
ImGui.AttachTooltip("Back (Alt + Left)");
ImGui.EndDisabled();
ImGui.SameLine();
ImGui.BeginDisabled(!_directoryHistory.CanGoForward);
if (ImGui.Button(">"))
{
NavigateForward();
}
ImGui.AttachTooltip("Forward (Alt + Right)");
ImGui.EndDisabled();
ImGui.SameLine();
ImGui.BeginDisabled(!CanNavigateUp);
if (ImGui.Button("/\\"))
{
NavigateUp();
}
ImGui.AttachTooltip("Up (Alt + Up)");
ImGui.EndDisabled();
List<TreeNode<AssetNode>> path = scope .();
TreeNode<AssetNode> walker = _currentDirectoryNode;
repeat
{
path.AddFront(walker);
walker = walker.Parent;
} while (walker != _manager.AssetHierarchy.RootNode);
ImGui.SameLine();
float2 spacing = (.)ImGui.GetStyle().ItemSpacing;
spacing.X = 0;
ImGui.PushScopedStyleVar!(ImGui.TypedStyleVar.ItemSpacing(spacing));
ImGui.PushScopedStyleVar!(ImGui.TypedStyleVar.FrameRounding(0));
for (TreeNode<AssetNode> node in path)
{
if (ImGui.Button(node->Name) && node != _currentDirectoryNode)
{
Navigate(node);
}
ImGui.SameLine();
ImGui.Text("/");
ImGui.SameLine();
}
ImGui.NewLine();
}
} }
} }