How should I go about using methods that take an IntPtr in the .NET Dear ImGui wrapper, ImGui.NET?
For example, ImGui.SetDragDropPayload takes a type string, an IntPtr, and a size unint. When I ImGui.GetDragDropPayload() I don't seem to be able to just grab the type that I set (I can only query if it is a certain type)... And I'm not sure how to use IntPtr to represent an object in my game engine, which I presume is one of the use cases this parameter is intended for.
I feel like there is a fundamental paradigm that I'm not understanding here, as using IntPtr to hold game data seems like a common thing in ImGui.NET. I've done some looking into how to represent objects as IntPtr in .Net, but this seems to point me to creating IntPtr for use in WinApi functions and I haven't been able to get anything working yet or understand how I should be approaching this...
As you can probably tell, I'm also entirely unfamiliar with the C++ Dear ImGui, so this makes things even trickier for me to get my head around. Any thoughts would be appreciated!
Edit:
Here's an example of how I'm using it right now. As I mentioned, I don't know how to use the payload propertly, so I'm just using a separate static object to represent what's currently being dragged. Then checking to see if the payload's NativePtr is null or not. It seems to work, I think, but is obviously not ideal:
private static unsafe void SubmitTestWindow()
{
ImGui.Begin("Test");
string[] items = new string[] { "hello", "world", "how", "are", "you?" };
for (int i = 0; i < items.Length; i++)
{
ImGui.Button(items[i]);
if (ImGui.BeginDragDropSource())
{
ImGui.Text(items[i]);
ImGui.SetDragDropPayload(typeof(string).FullName, IntPtr.Zero, 0);
draggedItem = items[i];
ImGui.EndDragDropSource();
}
if (ImGui.BeginDragDropTarget())
{
var payload = ImGui.AcceptDragDropPayload(typeof(string).FullName);
if (payload.NativePtr != null)
{
Console.WriteLine("Dropped " + draggedItem + " onto " + items[i]);
draggedItem = null;
}
ImGui.EndDragDropTarget();
}
}
ImGui.End();
}