From 23bd697f053bd5cf24601ee3f29572c0a645bd8f Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 18 Nov 2025 19:17:20 +0100 Subject: [PATCH] Drag and Drop: Pressing Escape while carrying a payload automatically cancel the active drag and drop. (#9071) --- docs/CHANGELOG.txt | 2 ++ imgui.cpp | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 1a92b7f40..116e3760d 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -122,6 +122,8 @@ Other Changes: - Drag and Drop: - Added ImGuiDragDropFlags_AcceptDrawAsHovered to make accepting item render as hovered, which can allow using e.g. Button() as drop target. (#8632) + - Pressing Escape while carrying a payload automatically cancel the + active drag and drop. (#9071) - Style: added ImGuiCol_DragDropTargetBg, style.DragDropTargetRounding, style.DragDropTargetBorderSize and style.DragDropTargetPadding to configure the drop target highlight. (#9056) [@aaronkirkham] diff --git a/imgui.cpp b/imgui.cpp index 170bca0fd..c20e8dfa3 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -5534,6 +5534,11 @@ void ImGui::NewFrame() g.DragDropWithinSource = false; g.DragDropWithinTarget = false; g.DragDropHoldJustPressedId = 0; + if (g.DragDropActive && IsKeyPressed(ImGuiKey_Escape, ImGuiInputFlags_None, g.ActiveId)) // Also works when g.ActiveId==0 (aka leftover payload in progress, no active id) + { + ClearActiveID(); + ClearDragDrop(); + } g.TooltipPreviousWindow = NULL; // Close popups on focus lost (currently wip/opt-in)