Drag and Drop: Clear state on EndDragDropTarget() with delivery + fixed handling of overlapping targets when smaller one is submitted before and can accept the same data type. (#6183, #5817)

This commit is contained in:
ocornut 2023-02-21 21:22:15 +01:00
parent 2ee77aa6be
commit e9743d85dd
3 changed files with 18 additions and 9 deletions

View File

@ -47,6 +47,10 @@ Breaking Changes:
Other changes: Other changes:
- Drag and Drop: Fixed handling of overlapping targets when smaller one is submitted
before and can accept the same data type. (#6183).
- Drag and Drop: Clear drag and drop state as soon as delivery is accepted in order to
avoid inteferences. (#5817, #6183) [@DimaKoltun]
- Backends: Win32: Use WM_NCMOUSEMOVE / WM_NCMOUSELEAVE to track mouse positions over - Backends: Win32: Use WM_NCMOUSEMOVE / WM_NCMOUSELEAVE to track mouse positions over
non-client area (e.g. OS decorations) when app is not focused. (#6045, #6162) non-client area (e.g. OS decorations) when app is not focused. (#6045, #6162)

View File

@ -12171,12 +12171,13 @@ const ImGuiPayload* ImGui::AcceptDragDropPayload(const char* type, ImGuiDragDrop
const bool was_accepted_previously = (g.DragDropAcceptIdPrev == g.DragDropTargetId); const bool was_accepted_previously = (g.DragDropAcceptIdPrev == g.DragDropTargetId);
ImRect r = g.DragDropTargetRect; ImRect r = g.DragDropTargetRect;
float r_surface = r.GetWidth() * r.GetHeight(); float r_surface = r.GetWidth() * r.GetHeight();
if (r_surface <= g.DragDropAcceptIdCurrRectSurface) if (r_surface > g.DragDropAcceptIdCurrRectSurface)
{ return NULL;
g.DragDropAcceptFlags = flags;
g.DragDropAcceptIdCurr = g.DragDropTargetId; g.DragDropAcceptFlags = flags;
g.DragDropAcceptIdCurrRectSurface = r_surface; g.DragDropAcceptIdCurr = g.DragDropTargetId;
} g.DragDropAcceptIdCurrRectSurface = r_surface;
//IMGUI_DEBUG_LOG("AcceptDragDropPayload(): %08X: accept\n", g.DragDropTargetId);
// Render default drop visuals // Render default drop visuals
payload.Preview = was_accepted_previously; payload.Preview = was_accepted_previously;
@ -12185,10 +12186,11 @@ const ImGuiPayload* ImGui::AcceptDragDropPayload(const char* type, ImGuiDragDrop
window->DrawList->AddRect(r.Min - ImVec2(3.5f,3.5f), r.Max + ImVec2(3.5f, 3.5f), GetColorU32(ImGuiCol_DragDropTarget), 0.0f, 0, 2.0f); window->DrawList->AddRect(r.Min - ImVec2(3.5f,3.5f), r.Max + ImVec2(3.5f, 3.5f), GetColorU32(ImGuiCol_DragDropTarget), 0.0f, 0, 2.0f);
g.DragDropAcceptFrameCount = g.FrameCount; g.DragDropAcceptFrameCount = g.FrameCount;
payload.Delivery = was_accepted_previously && !IsMouseDown(g.DragDropMouseButton); // For extern drag sources affecting os window focus, it's easier to just test !IsMouseDown() instead of IsMouseReleased() payload.Delivery = was_accepted_previously && !IsMouseDown(g.DragDropMouseButton); // For extern drag sources affecting OS window focus, it's easier to just test !IsMouseDown() instead of IsMouseReleased()
if (!payload.Delivery && !(flags & ImGuiDragDropFlags_AcceptBeforeDelivery)) if (!payload.Delivery && !(flags & ImGuiDragDropFlags_AcceptBeforeDelivery))
return NULL; return NULL;
//IMGUI_DEBUG_LOG("AcceptDragDropPayload(): %08X: return payload\n", g.DragDropTargetId);
return &payload; return &payload;
} }
@ -12204,13 +12206,16 @@ const ImGuiPayload* ImGui::GetDragDropPayload()
return (g.DragDropActive && g.DragDropPayload.DataFrameCount != -1) ? &g.DragDropPayload : NULL; return (g.DragDropActive && g.DragDropPayload.DataFrameCount != -1) ? &g.DragDropPayload : NULL;
} }
// We don't really use/need this now, but added it for the sake of consistency and because we might need it later.
void ImGui::EndDragDropTarget() void ImGui::EndDragDropTarget()
{ {
ImGuiContext& g = *GImGui; ImGuiContext& g = *GImGui;
IM_ASSERT(g.DragDropActive); IM_ASSERT(g.DragDropActive);
IM_ASSERT(g.DragDropWithinTarget); IM_ASSERT(g.DragDropWithinTarget);
g.DragDropWithinTarget = false; g.DragDropWithinTarget = false;
// Clear drag and drop state payload right after delivery
if (g.DragDropPayload.Delivery)
ClearDragDrop();
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View File

@ -23,7 +23,7 @@
// Library Version // Library Version
// (Integer encoded as XYYZZ for use in #if preprocessor conditionals, e.g. '#if IMGUI_VERSION_NUM > 12345') // (Integer encoded as XYYZZ for use in #if preprocessor conditionals, e.g. '#if IMGUI_VERSION_NUM > 12345')
#define IMGUI_VERSION "1.89.4 WIP" #define IMGUI_VERSION "1.89.4 WIP"
#define IMGUI_VERSION_NUM 18932 #define IMGUI_VERSION_NUM 18933
#define IMGUI_HAS_TABLE #define IMGUI_HAS_TABLE
/* /*