1
0
mirror of https://github.com/ocornut/imgui.git synced 2024-09-24 19:48:34 +02:00

Drag and Drop: Drop target infer a fallback ID from the rectangle. Avoid Preview being accepted on drop frame when drop target has no ID. (#143)

This commit is contained in:
omar 2017-12-12 18:17:18 +01:00
parent e98df91dc4
commit d561a43a4d

View File

@ -11292,7 +11292,8 @@ bool ImGui::BeginDragDropTargetCustom(const ImRect& bb, ImGuiID id)
ImGuiWindow* window = g.CurrentWindow;
if (g.HoveredWindow == NULL || window->RootWindow != g.HoveredWindow->RootWindow)
return false;
if (!IsMouseHoveringRect(bb.Min, bb.Max) || (id && id == g.DragDropPayload.SourceId))
IM_ASSERT(id != 0);
if (!IsMouseHoveringRect(bb.Min, bb.Max) || (id == g.DragDropPayload.SourceId))
return false;
g.DragDropTargetRect = bb;
@ -11301,7 +11302,7 @@ bool ImGui::BeginDragDropTargetCustom(const ImRect& bb, ImGuiID id)
}
// We don't use BeginDragDropTargetCustom() and duplicate its code because:
// 1) LastItemRectHoveredRect which handles items that pushes a temporarily clip rectangle in their code. Calling BeginDragDropTargetCustom(LastItemRect) would not handle it.
// 1) we use LastItemRectHoveredRect which handles items that pushes a temporarily clip rectangle in their code. Calling BeginDragDropTargetCustom(LastItemRect) would not handle them.
// 2) and it's faster. as this code may be very frequently called, we want to early out as fast as we can.
// Also note how the HoveredWindow test is positioned differently in both functions (in both functions we optimize for the cheapest early out case)
bool ImGui::BeginDragDropTarget()
@ -11311,13 +11312,19 @@ bool ImGui::BeginDragDropTarget()
return false;
ImGuiWindow* window = g.CurrentWindow;
if (!window->DC.LastItemRectHoveredRect || (window->DC.LastItemId && window->DC.LastItemId == g.DragDropPayload.SourceId))
if (!window->DC.LastItemRectHoveredRect)
return false;
if (g.HoveredWindow == NULL || window->RootWindow != g.HoveredWindow->RootWindow)
return false;
ImGuiID id = window->DC.LastItemId;
if (id == 0)
id = window->GetIDFromRectangle(window->DC.LastItemRect);
if (g.DragDropPayload.SourceId == id)
return false;
g.DragDropTargetRect = window->DC.LastItemRect;
g.DragDropTargetId = window->DC.LastItemId;
g.DragDropTargetId = id;
return true;
}