From 856c6314ec33c3dc463ca17ad68b8e42a7dce06d Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 23 Nov 2022 17:58:14 +0100 Subject: [PATCH] Drag and Drop: fixed GetDragDropPayload() returning a non-NULL value before payload is submitted. (#5910, #143) + Added test "widgets_dragdrop_new_payloads" in Test Suite. --- docs/CHANGELOG.txt | 3 +++ imgui.cpp | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 1dd5df4be63c..ed6ff97e6ba7 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -42,6 +42,9 @@ HOW TO UPDATE? inside a collapsed/culled window and IMGUI_DISABLE_OBSOLETE_FUNCTIONS is enabled. (#5548, #5911) - ColorEdit: fixed label overlapping when using style.ColorButtonPosition == ImGuiDir_Left to move the color button on the left side (regression introduced in 1.88 WIP 2022/02/28). (#5912) +- Drag and Drop: fixed GetDragDropPayload() returning a non-NULL value if a drag source is + active but a payload hasn't been submitted yet. This is convenient to detect new payload + from within a drag source handler. (#5910, #143) - Backends: GLFW: cancel out errors emitted by glfwGetKeyName() when a name is missing. (#5908) diff --git a/imgui.cpp b/imgui.cpp index 9d463dc11386..89ba21944191 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -12023,7 +12023,7 @@ void ImGui::RenderDragDropTargetRect(const ImRect& bb) const ImGuiPayload* ImGui::GetDragDropPayload() { ImGuiContext& g = *GImGui; - return g.DragDropActive ? &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.