mirror of
https://github.com/ocornut/imgui.git
synced 2026-01-09 23:54:20 +00:00
Drag and Drop: rework cancel drag and drop logic to be overridable. (#9071)
This commit is contained in:
parent
db6b8e0fb3
commit
0faa0dba15
1 changed files with 11 additions and 3 deletions
14
imgui.cpp
14
imgui.cpp
|
|
@ -5546,10 +5546,18 @@ 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)
|
||||
if (g.DragDropActive)
|
||||
{
|
||||
ClearActiveID();
|
||||
ClearDragDrop();
|
||||
// Also works when g.ActiveId==0 (aka leftover payload in progress, no active id)
|
||||
// You may disable this externally by hijacking the input route:
|
||||
// 'if (GetDragDropPayload() != NULL) { Shortcut(ImGuiKey_Escape, ImGuiInputFlags_RouteGlobal | ImGuiInputFlags_RouteOverActive); }
|
||||
// but you will not get a return value from Shortcut() due to ActiveIdUsingAllKeyboardKeys logic. You can however poll IsKeyPressed(ImGuiKey_Escape) afterwards.
|
||||
ImGuiID owner_id = g.ActiveId ? g.ActiveId : ImHashStr("##DragDropCancelHandler");
|
||||
if (Shortcut(ImGuiKey_Escape, ImGuiInputFlags_RouteGlobal, owner_id))
|
||||
{
|
||||
ClearActiveID();
|
||||
ClearDragDrop();
|
||||
}
|
||||
}
|
||||
g.TooltipPreviousWindow = NULL;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue