Skip to content

Commit

Permalink
Fix right click menu populating with incorrect items
Browse files Browse the repository at this point in the history
Closes #80
  • Loading branch information
Minmoose committed Aug 24, 2024
1 parent de0a8fd commit 0305cc3
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions Brio/UI/Entitites/EntityHierarchyView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private void DrawEntity(Entity entity, EntityId? selectedEntityId, float lastOff
{
bool isSelected = false;
bool hasChildren = false;

if(entity.Children.Count > 0)
hasChildren = true;
if(selectedEntityId != null && entity.Id.Equals(selectedEntityId))
Expand All @@ -52,20 +52,18 @@ private void DrawEntity(Entity entity, EntityId? selectedEntityId, float lastOff
{
using(ImRaii.PushColor(ImGuiCol.Button, 0))
{
{
var invsButtonPos = ImGui.GetCursorPos();

if(ImGui.Button($"###{entity.Id}_invs_button", new(buttonWidth, 0)))
{
Select(entity);
}
if(ImGui.IsItemClicked(ImGuiMouseButton.Right))
{
ImGui.OpenPopup($"context_popup");
}
var invsButtonPos = ImGui.GetCursorPos();

ImGui.SetCursorPos(invsButtonPos);
if(ImGui.Button($"###{entity.Id}_invs_button", new(buttonWidth, 0)))
{
Select(entity);
}
if(ImGui.IsItemClicked(ImGuiMouseButton.Right))
{
ImGui.OpenPopup($"context_popup{entity.Id}");
}

ImGui.SetCursorPos(invsButtonPos);
}

if(lastOffset > 0)
Expand All @@ -80,30 +78,32 @@ private void DrawEntity(Entity entity, EntityId? selectedEntityId, float lastOff
{
using(ImRaii.Disabled(true))
{
ImGui.Button($"###{entity.Id}");
ImGui.Button($"###tab_{entity.Id}");
}
}
}

DrawNode(entity);

if(hasChildren)
using(var popup = ImRaii.Popup($"context_popup{entity.Id}"))
{
foreach(var child in entity.Children)
DrawEntity(child, selectedEntityId, lastOffset == 0 ? 3 : lastOffset);
}

using var popup = ImRaii.Popup("context_popup");
if(popup.Success)
{
foreach(var v in entity.Capabilities)
if(popup.Success)
{
if(v.Widget is not null && v.Widget.Flags.HasFlag(WidgetFlags.DrawPopup))
foreach(var v in entity.Capabilities)
{
v.Widget.DrawPopup();
if(v.Widget is not null && v.Widget.Flags.HasFlag(WidgetFlags.DrawPopup))
{
v.Widget.DrawPopup();
}
}
}
}

if(hasChildren)
{
foreach(var child in entity.Children)
DrawEntity(child, selectedEntityId, lastOffset == 0 ? 3 : lastOffset);
}
}

private static void DrawNode(Entity entity)
Expand Down

0 comments on commit 0305cc3

Please sign in to comment.