MCPcopy Create free account
hub / github.com/Aegel5/SimpleSwitcher / BeginDragDropTarget

Method BeginDragDropTarget

imgui_tiny_app/imgui/imgui.cpp:15760–15789  ·  view source on GitHub ↗

We don't use BeginDragDropTargetCustom() and duplicate its code because: 1) we use LastItemData's ImGuiItemStatusFlags_HoveredRect which handles items that push 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 Ho

Source from the content-addressed store, hash-verified

15758// 2) and it's faster. as this code may be very frequently called, we want to early out as fast as we can.
15759// Also note how the HoveredWindow test is positioned differently in both functions (in both functions we optimize for the cheapest early out case)
15760bool ImGui::BeginDragDropTarget()
15761{
15762 ImGuiContext& g = *GImGui;
15763 if (!g.DragDropActive)
15764 return false;
15765
15766 ImGuiWindow* window = g.CurrentWindow;
15767 if (!(g.LastItemData.StatusFlags & ImGuiItemStatusFlags_HoveredRect))
15768 return false;
15769 ImGuiWindow* hovered_window = g.HoveredWindowUnderMovingWindow;
15770 if (hovered_window == NULL || window->RootWindowDockTree != hovered_window->RootWindowDockTree || window->SkipItems)
15771 return false;
15772
15773 const ImRect& display_rect = (g.LastItemData.StatusFlags & ImGuiItemStatusFlags_HasDisplayRect) ? g.LastItemData.DisplayRect : g.LastItemData.Rect;
15774 ImGuiID id = g.LastItemData.ID;
15775 if (id == 0)
15776 {
15777 id = window->GetIDFromRectangle(display_rect);
15778 KeepAliveID(id);
15779 }
15780 if (g.DragDropPayload.SourceId == id)
15781 return false;
15782
15783 IM_ASSERT(g.DragDropWithinTarget == false && g.DragDropWithinSource == false); // Can't nest BeginDragDropSource() and BeginDragDropTarget()
15784 g.DragDropTargetRect = display_rect;
15785 g.DragDropTargetClipRect = (g.LastItemData.StatusFlags & ImGuiItemStatusFlags_HasClipRect) ? g.LastItemData.ClipRect : window->ClipRect;
15786 g.DragDropTargetId = id;
15787 g.DragDropWithinTarget = true;
15788 return true;
15789}
15790
15791bool ImGui::IsDragDropPayloadBeingAccepted()
15792{

Callers

nothing calls this directly

Calls 1

GetIDFromRectangleMethod · 0.80

Tested by

no test coverage detected