Use 'cond' to choose to submit payload on drag start or every frame
| 13177 | |
| 13178 | // Use 'cond' to choose to submit payload on drag start or every frame |
| 13179 | bool ImGui::SetDragDropPayload(const char* type, const void* data, size_t data_size, ImGuiCond cond) |
| 13180 | { |
| 13181 | ImGuiContext& g = *GImGui; |
| 13182 | ImGuiPayload& payload = g.DragDropPayload; |
| 13183 | if (cond == 0) |
| 13184 | cond = ImGuiCond_Always; |
| 13185 | |
| 13186 | IM_ASSERT(type != NULL); |
| 13187 | IM_ASSERT(strlen(type) < IM_ARRAYSIZE(payload.DataType) && "Payload type can be at most 12 characters long"); |
| 13188 | IM_ASSERT((data != NULL && data_size > 0) || (data == NULL && data_size == 0)); |
| 13189 | IM_ASSERT(cond == ImGuiCond_Always || cond == ImGuiCond_Once); |
| 13190 | IM_ASSERT(payload.SourceId != 0); // Not called between BeginDragDropSource() and EndDragDropSource() |
| 13191 | |
| 13192 | if (cond == ImGuiCond_Always || payload.DataFrameCount == -1) |
| 13193 | { |
| 13194 | // Copy payload |
| 13195 | ImStrncpy(payload.DataType, type, IM_ARRAYSIZE(payload.DataType)); |
| 13196 | g.DragDropPayloadBufHeap.resize(0); |
| 13197 | if (data_size > sizeof(g.DragDropPayloadBufLocal)) |
| 13198 | { |
| 13199 | // Store in heap |
| 13200 | g.DragDropPayloadBufHeap.resize((int)data_size); |
| 13201 | payload.Data = g.DragDropPayloadBufHeap.Data; |
| 13202 | memcpy((void*)payload.Data, data, data_size); |
| 13203 | } |
| 13204 | else if (data_size > 0) |
| 13205 | { |
| 13206 | // Store locally |
| 13207 | memset(&g.DragDropPayloadBufLocal, 0, sizeof(g.DragDropPayloadBufLocal)); |
| 13208 | payload.Data = g.DragDropPayloadBufLocal; |
| 13209 | memcpy((void*)payload.Data, data, data_size); |
| 13210 | } |
| 13211 | else |
| 13212 | { |
| 13213 | payload.Data = NULL; |
| 13214 | } |
| 13215 | payload.DataSize = (int)data_size; |
| 13216 | } |
| 13217 | payload.DataFrameCount = g.FrameCount; |
| 13218 | |
| 13219 | return (g.DragDropAcceptFrameCount == g.FrameCount) || (g.DragDropAcceptFrameCount == g.FrameCount - 1); |
| 13220 | } |
| 13221 | |
| 13222 | bool ImGui::BeginDragDropTargetCustom(const ImRect& bb, ImGuiID id) |
| 13223 | { |