Use 'cond' to choose to submit payload on drag start or every frame
| 13358 | |
| 13359 | // Use 'cond' to choose to submit payload on drag start or every frame |
| 13360 | bool ImGui::SetDragDropPayload(const char* type, const void* data, size_t data_size, ImGuiCond cond) |
| 13361 | { |
| 13362 | ImGuiContext& g = *GImGui; |
| 13363 | ImGuiPayload& payload = g.DragDropPayload; |
| 13364 | if (cond == 0) |
| 13365 | cond = ImGuiCond_Always; |
| 13366 | |
| 13367 | IM_ASSERT(type != NULL); |
| 13368 | IM_ASSERT(strlen(type) < IM_ARRAYSIZE(payload.DataType) && "Payload type can be at most 32 characters long"); |
| 13369 | IM_ASSERT((data != NULL && data_size > 0) || (data == NULL && data_size == 0)); |
| 13370 | IM_ASSERT(cond == ImGuiCond_Always || cond == ImGuiCond_Once); |
| 13371 | IM_ASSERT(payload.SourceId != 0); // Not called between BeginDragDropSource() and EndDragDropSource() |
| 13372 | |
| 13373 | if (cond == ImGuiCond_Always || payload.DataFrameCount == -1) |
| 13374 | { |
| 13375 | // Copy payload |
| 13376 | ImStrncpy(payload.DataType, type, IM_ARRAYSIZE(payload.DataType)); |
| 13377 | g.DragDropPayloadBufHeap.resize(0); |
| 13378 | if (data_size > sizeof(g.DragDropPayloadBufLocal)) |
| 13379 | { |
| 13380 | // Store in heap |
| 13381 | g.DragDropPayloadBufHeap.resize((int)data_size); |
| 13382 | payload.Data = g.DragDropPayloadBufHeap.Data; |
| 13383 | memcpy(payload.Data, data, data_size); |
| 13384 | } |
| 13385 | else if (data_size > 0) |
| 13386 | { |
| 13387 | // Store locally |
| 13388 | memset(&g.DragDropPayloadBufLocal, 0, sizeof(g.DragDropPayloadBufLocal)); |
| 13389 | payload.Data = g.DragDropPayloadBufLocal; |
| 13390 | memcpy(payload.Data, data, data_size); |
| 13391 | } |
| 13392 | else |
| 13393 | { |
| 13394 | payload.Data = NULL; |
| 13395 | } |
| 13396 | payload.DataSize = (int)data_size; |
| 13397 | } |
| 13398 | payload.DataFrameCount = g.FrameCount; |
| 13399 | |
| 13400 | // Return whether the payload has been accepted |
| 13401 | return (g.DragDropAcceptFrameCount == g.FrameCount) || (g.DragDropAcceptFrameCount == g.FrameCount - 1); |
| 13402 | } |
| 13403 | |
| 13404 | bool ImGui::BeginDragDropTargetCustom(const ImRect& bb, ImGuiID id) |
| 13405 | { |