mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 21:01:52 +00:00
Fixed list of struct drag and drop, added context menu to remove list entries
This commit is contained in:
@@ -405,7 +405,11 @@ internal class EntityEditor
|
|||||||
|
|
||||||
// The buttons should always be visible -> save whether the node is open
|
// The buttons should always be visible -> save whether the node is open
|
||||||
// If we have no instance, the user shouldn't be able to open the list
|
// If we have no instance, the user shouldn't be able to open the list
|
||||||
bool listOpen = ImGui.TreeNodeEx(fieldName, myList == null ? ImGuiTreeNodeFlags.Leaf : ImGuiTreeNodeFlags.None);
|
bool listOpen = ImGui.TreeNodeEx(fieldName,
|
||||||
|
myList == null ? ImGuiTreeNodeFlags.Leaf | ImGuiTreeNodeFlags.NoTreePushOnOpen : ImGuiTreeNodeFlags.Framed);
|
||||||
|
|
||||||
|
if (myList == null)
|
||||||
|
listOpen = false;
|
||||||
|
|
||||||
var addButtonWidth = ImGui.CalcTextSize("+").X + 2 * ImGui.GetStyle().FramePadding.X;
|
var addButtonWidth = ImGui.CalcTextSize("+").X + 2 * ImGui.GetStyle().FramePadding.X;
|
||||||
var removeButtonWidth = ImGui.CalcTextSize("-").X + 2 * ImGui.GetStyle().FramePadding.X;
|
var removeButtonWidth = ImGui.CalcTextSize("-").X + 2 * ImGui.GetStyle().FramePadding.X;
|
||||||
@@ -441,11 +445,15 @@ internal class EntityEditor
|
|||||||
|
|
||||||
ImGui.EndDisabled();
|
ImGui.EndDisabled();
|
||||||
|
|
||||||
|
if (listOpen)
|
||||||
|
{
|
||||||
|
Debug.Assert(myList != null, "Opened tree node even though it should have been a leaf!");
|
||||||
|
|
||||||
if (listOpen && myList != null)
|
/// Returns true if something was dropped into the droptarget
|
||||||
{
|
bool DropTarget(int insertIndex, string tooltip)
|
||||||
void DropTarget(int insertIndex, string tooltip)
|
|
||||||
{
|
{
|
||||||
|
bool dropped = false;
|
||||||
|
|
||||||
if (ImGui.BeginDragDropTarget())
|
if (ImGui.BeginDragDropTarget())
|
||||||
{
|
{
|
||||||
ImGui.SetTooltip(tooltip);
|
ImGui.SetTooltip(tooltip);
|
||||||
@@ -471,20 +479,28 @@ internal class EntityEditor
|
|||||||
// If the original index is before the insert index, the insert index will be moved after removing the element
|
// If the original index is before the insert index, the insert index will be moved after removing the element
|
||||||
// thus we have to subtract one.
|
// thus we have to subtract one.
|
||||||
myList.Insert(insertIndex - 1, item);
|
myList.Insert(insertIndex - 1, item);
|
||||||
|
|
||||||
|
dropped = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui.EndDragDropTarget();
|
ImGui.EndDragDropTarget();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return dropped;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Drop at index 0
|
// Drop at index 0
|
||||||
ImGui.Separator();
|
ImGui.Separator();
|
||||||
DropTarget(0, "Drop before Element 0.");
|
DropTarget(0, "Drop before Element 0.");
|
||||||
|
|
||||||
for (int i = 0; i < myList.Count; i++)
|
bool orderChanged = false;
|
||||||
|
|
||||||
|
for (int i = 0, id = 0; i < myList.Count; i++, id++)
|
||||||
{
|
{
|
||||||
|
ImGui.PushID(id);
|
||||||
|
|
||||||
object element = myList[i];
|
object element = myList[i];
|
||||||
|
|
||||||
// A Bullet point to grab the element
|
// A Bullet point to grab the element
|
||||||
@@ -503,20 +519,38 @@ internal class EntityEditor
|
|||||||
ImGui.EndDragDropSource();
|
ImGui.EndDragDropSource();
|
||||||
}
|
}
|
||||||
|
|
||||||
DropTarget(i, $"Drop before Element {i}.");
|
orderChanged |= DropTarget(i, $"Drop before Element {i}.");
|
||||||
|
|
||||||
|
if (ImGui.BeginPopupContextWindow($"ListElementContext{i}"))
|
||||||
|
{
|
||||||
|
if (ImGui.MenuItem($"Remove Element {i}"))
|
||||||
|
{
|
||||||
|
myList.RemoveAt(i);
|
||||||
|
i--;
|
||||||
|
ImGui.EndPopup();
|
||||||
|
ImGui.PopID();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui.EndPopup();
|
||||||
|
}
|
||||||
|
|
||||||
ImGui.SameLine();
|
ImGui.SameLine();
|
||||||
|
|
||||||
object newValue = ShowFieldEditor(element, element.GetType(), $"Element {i}");
|
object newValue = ShowFieldEditor(element, element.GetType(), $"Element {i}");
|
||||||
|
|
||||||
if (newValue != DidNotChange)
|
// Don't apply changes, when the order changed
|
||||||
|
if (newValue != DidNotChange && !orderChanged)
|
||||||
{
|
{
|
||||||
myList[i] = newValue;
|
myList[i] = newValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Drop after current element
|
// Drop after current element
|
||||||
ImGui.Separator();
|
ImGui.Separator();
|
||||||
DropTarget(i + 1, $"Drop after Element {i}.");
|
|
||||||
|
orderChanged |= DropTarget(i + 1, $"Drop after Element {i}.");
|
||||||
|
|
||||||
|
ImGui.PopID();
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui.TreePop();
|
ImGui.TreePop();
|
||||||
|
|||||||
Reference in New Issue
Block a user