MCPcopy Create free account
hub / github.com/KebsCS/KBotExt / SetDragDropPayload

Method SetDragDropPayload

KBotExt/imgui/imgui.cpp:12447–12489  ·  view source on GitHub ↗

Use 'cond' to choose to submit payload on drag start or every frame

Source from the content-addressed store, hash-verified

12445
12446// Use 'cond' to choose to submit payload on drag start or every frame
12447bool ImGui::SetDragDropPayload(const char* type, const void* data, size_t data_size, ImGuiCond cond)
12448{
12449 ImGuiContext& g = *GImGui;
12450 ImGuiPayload& payload = g.DragDropPayload;
12451 if (cond == 0)
12452 cond = ImGuiCond_Always;
12453
12454 IM_ASSERT(type != NULL);
12455 IM_ASSERT(strlen(type) < IM_ARRAYSIZE(payload.DataType) && "Payload type can be at most 32 characters long");
12456 IM_ASSERT((data != NULL && data_size > 0) || (data == NULL && data_size == 0));
12457 IM_ASSERT(cond == ImGuiCond_Always || cond == ImGuiCond_Once);
12458 IM_ASSERT(payload.SourceId != 0); // Not called between BeginDragDropSource() and EndDragDropSource()
12459
12460 if (cond == ImGuiCond_Always || payload.DataFrameCount == -1)
12461 {
12462 // Copy payload
12463 ImStrncpy(payload.DataType, type, IM_ARRAYSIZE(payload.DataType));
12464 g.DragDropPayloadBufHeap.resize(0);
12465 if (data_size > sizeof(g.DragDropPayloadBufLocal))
12466 {
12467 // Store in heap
12468 g.DragDropPayloadBufHeap.resize((int)data_size);
12469 payload.Data = g.DragDropPayloadBufHeap.Data;
12470 memcpy(payload.Data, data, data_size);
12471 }
12472 else if (data_size > 0)
12473 {
12474 // Store locally
12475 memset(&g.DragDropPayloadBufLocal, 0, sizeof(g.DragDropPayloadBufLocal));
12476 payload.Data = g.DragDropPayloadBufLocal;
12477 memcpy(payload.Data, data, data_size);
12478 }
12479 else
12480 {
12481 payload.Data = NULL;
12482 }
12483 payload.DataSize = (int)data_size;
12484 }
12485 payload.DataFrameCount = g.FrameCount;
12486
12487 // Return whether the payload has been accepted
12488 return (g.DragDropAcceptFrameCount == g.FrameCount) || (g.DragDropAcceptFrameCount == g.FrameCount - 1);
12489}
12490
12491bool ImGui::BeginDragDropTargetCustom(const ImRect& bb, ImGuiID id)
12492{

Callers

nothing calls this directly

Calls 1

ImStrncpyFunction · 0.85

Tested by

no test coverage detected