MCPcopy Create free account
hub / github.com/InteractiveComputerGraphics/SPlisHSPlasH / AcceptDragDropPayload

Method AcceptDragDropPayload

extern/imgui/imgui.cpp:12722–12756  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12720}
12721
12722const ImGuiPayload* ImGui::AcceptDragDropPayload(const char* type, ImGuiDragDropFlags flags)
12723{
12724 ImGuiContext& g = *GImGui;
12725 ImGuiWindow* window = g.CurrentWindow;
12726 ImGuiPayload& payload = g.DragDropPayload;
12727 IM_ASSERT(g.DragDropActive); // Not called between BeginDragDropTarget() and EndDragDropTarget() ?
12728 IM_ASSERT(payload.DataFrameCount != -1); // Forgot to call EndDragDropTarget() ?
12729 if (type != NULL && !payload.IsDataType(type))
12730 return NULL;
12731
12732 // Accept smallest drag target bounding box, this allows us to nest drag targets conveniently without ordering constraints.
12733 // NB: We currently accept NULL id as target. However, overlapping targets requires a unique ID to function!
12734 const bool was_accepted_previously = (g.DragDropAcceptIdPrev == g.DragDropTargetId);
12735 ImRect r = g.DragDropTargetRect;
12736 float r_surface = r.GetWidth() * r.GetHeight();
12737 if (r_surface <= g.DragDropAcceptIdCurrRectSurface)
12738 {
12739 g.DragDropAcceptFlags = flags;
12740 g.DragDropAcceptIdCurr = g.DragDropTargetId;
12741 g.DragDropAcceptIdCurrRectSurface = r_surface;
12742 }
12743
12744 // Render default drop visuals
12745 payload.Preview = was_accepted_previously;
12746 flags |= (g.DragDropSourceFlags & ImGuiDragDropFlags_AcceptNoDrawDefaultRect); // Source can also inhibit the preview (useful for external sources that live for 1 frame)
12747 if (!(flags & ImGuiDragDropFlags_AcceptNoDrawDefaultRect) && payload.Preview)
12748 window->DrawList->AddRect(r.Min - ImVec2(3.5f,3.5f), r.Max + ImVec2(3.5f, 3.5f), GetColorU32(ImGuiCol_DragDropTarget), 0.0f, 0, 2.0f);
12749
12750 g.DragDropAcceptFrameCount = g.FrameCount;
12751 payload.Delivery = was_accepted_previously && !IsMouseDown(g.DragDropMouseButton); // For extern drag sources affecting os window focus, it's easier to just test !IsMouseDown() instead of IsMouseReleased()
12752 if (!payload.Delivery && !(flags & ImGuiDragDropFlags_AcceptBeforeDelivery))
12753 return NULL;
12754
12755 return &payload;
12756}
12757
12758// FIXME-DRAGDROP: Settle on a proper default visuals for drop target.
12759void ImGui::RenderDragDropTargetRect(const ImRect& bb)

Callers

nothing calls this directly

Calls 3

ImVec2Function · 0.85
IsDataTypeMethod · 0.80
AddRectMethod · 0.80

Tested by

no test coverage detected