1
0
Fork 0
mirror of https://github.com/ocornut/imgui.git synced 2026-01-09 23:54:20 +00:00

Drag and Drop: prev/curr storage for DragDropAcceptFlags. ImGuiDragDropFlags_AcceptNoPreviewTooltip test uses DragDropAcceptFlagsPrev for consistency. (#143)

I don't think this would have materialized as a visible bug.
This commit is contained in:
ocornut 2025-11-06 17:59:01 +01:00
parent dacd080639
commit b0d3c3a674
2 changed files with 8 additions and 5 deletions

View file

@ -4190,7 +4190,7 @@ ImGuiContext::ImGuiContext(ImFontAtlas* shared_font_atlas)
DragDropMouseButton = -1;
DragDropTargetId = 0;
DragDropTargetFullViewport = 0;
DragDropAcceptFlags = ImGuiDragDropFlags_None;
DragDropAcceptFlagsCurr = DragDropAcceptFlagsPrev = ImGuiDragDropFlags_None;
DragDropAcceptIdCurrRectSurface = 0.0f;
DragDropAcceptIdPrev = DragDropAcceptIdCurr = 0;
DragDropAcceptFrameCount = -1;
@ -5528,6 +5528,8 @@ void ImGui::NewFrame()
// Drag and drop
g.DragDropAcceptIdPrev = g.DragDropAcceptIdCurr;
g.DragDropAcceptIdCurr = 0;
g.DragDropAcceptFlagsPrev = g.DragDropAcceptFlagsCurr;
g.DragDropAcceptFlagsCurr = ImGuiDragDropFlags_None;
g.DragDropAcceptIdCurrRectSurface = FLT_MAX;
g.DragDropWithinSource = false;
g.DragDropWithinTarget = false;
@ -14552,7 +14554,7 @@ void ImGui::ClearDragDrop()
IMGUI_DEBUG_LOG_ACTIVEID("[dragdrop] ClearDragDrop()\n");
g.DragDropActive = false;
g.DragDropPayload.Clear();
g.DragDropAcceptFlags = ImGuiDragDropFlags_None;
g.DragDropAcceptFlagsCurr = ImGuiDragDropFlags_None;
g.DragDropAcceptIdCurr = g.DragDropAcceptIdPrev = 0;
g.DragDropAcceptIdCurrRectSurface = FLT_MAX;
g.DragDropAcceptFrameCount = -1;
@ -14681,7 +14683,7 @@ bool ImGui::BeginDragDropSource(ImGuiDragDropFlags flags)
// Target can request the Source to not display its tooltip (we use a dedicated flag to make this request explicit)
// We unfortunately can't just modify the source flags and skip the call to BeginTooltip, as caller may be emitting contents.
bool ret;
if (g.DragDropAcceptIdPrev && (g.DragDropAcceptFlags & ImGuiDragDropFlags_AcceptNoPreviewTooltip))
if (g.DragDropAcceptIdPrev && (g.DragDropAcceptFlagsPrev & ImGuiDragDropFlags_AcceptNoPreviewTooltip))
ret = BeginTooltipHidden();
else
ret = BeginTooltip();
@ -14862,7 +14864,7 @@ const ImGuiPayload* ImGui::AcceptDragDropPayload(const char* type, ImGuiDragDrop
if (r_surface > g.DragDropAcceptIdCurrRectSurface)
return NULL;
g.DragDropAcceptFlags = flags;
g.DragDropAcceptFlagsCurr = flags;
g.DragDropAcceptIdCurr = g.DragDropTargetId;
g.DragDropAcceptIdCurrRectSurface = r_surface;
//IMGUI_DEBUG_LOG("AcceptDragDropPayload(): %08X: accept\n", g.DragDropTargetId);

View file

@ -2380,7 +2380,8 @@ struct ImGuiContext
ImRect DragDropTargetClipRect; // Store ClipRect at the time of item's drawing
ImGuiID DragDropTargetId;
ImGuiID DragDropTargetFullViewport;
ImGuiDragDropFlags DragDropAcceptFlags;
ImGuiDragDropFlags DragDropAcceptFlagsCurr;
ImGuiDragDropFlags DragDropAcceptFlagsPrev;
float DragDropAcceptIdCurrRectSurface; // Target item surface (we resolve overlapping targets by prioritizing the smaller surface)
ImGuiID DragDropAcceptIdCurr; // Target item id (set at the time of accepting the payload)
ImGuiID DragDropAcceptIdPrev; // Target item id from previous frame (we need to store this to allow for overlapping drag and drop targets)