qstbak/QuestionableCompanion/QuestionableCompanion.Helpers/ImGuiDragDrop.cs
2025-12-04 04:39:08 +10:00

22 lines
784 B
C#

using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Dalamud.Bindings.ImGui;
namespace QuestionableCompanion.Helpers;
public static class ImGuiDragDrop
{
public static void SetDragDropPayload<T>(string type, T data, ImGuiCond cond = ImGuiCond.None) where T : struct
{
ReadOnlySpan<byte> span = MemoryMarshal.AsBytes(MemoryMarshal.CreateReadOnlySpan(in data, 1));
ImGui.SetDragDropPayload(type, span, cond);
}
public unsafe static bool AcceptDragDropPayload<T>(string type, out T payload, ImGuiDragDropFlags flags = ImGuiDragDropFlags.None) where T : struct
{
ImGuiPayload* pload = ImGui.AcceptDragDropPayload(type, flags);
payload = ((pload != null) ? Unsafe.Read<T>(pload->Data) : default(T));
return pload != null;
}
}