Use 'cond' to choose to submit payload on drag start or every frame
| 11877 | |
| 11878 | // Use 'cond' to choose to submit payload on drag start or every frame |
| 11879 | bool ImGui::SetDragDropPayload(const char* type, const void* data, size_t data_size, ImGuiCond cond) |
| 11880 | { |
| 11881 | ImGuiContext& g = *GImGui; |
| 11882 | ImGuiPayload& payload = g.DragDropPayload; |
| 11883 | if (cond == 0) |
| 11884 | cond = ImGuiCond_Always; |
| 11885 | |
| 11886 | IM_ASSERT(type != NULL); |
| 11887 | IM_ASSERT(strlen(type) < IM_ARRAYSIZE(payload.DataType) && "Payload type can be at most 32 characters long"); |
| 11888 | IM_ASSERT((data != NULL && data_size > 0) || (data == NULL && data_size == 0)); |
| 11889 | IM_ASSERT(cond == ImGuiCond_Always || cond == ImGuiCond_Once); |
| 11890 | IM_ASSERT(payload.SourceId != 0); // Not called between BeginDragDropSource() and EndDragDropSource() |
| 11891 | |
| 11892 | if (cond == ImGuiCond_Always || payload.DataFrameCount == -1) |
| 11893 | { |
| 11894 | // Copy payload |
| 11895 | ImStrncpy(payload.DataType, type, IM_ARRAYSIZE(payload.DataType)); |
| 11896 | g.DragDropPayloadBufHeap.resize(0); |
| 11897 | if (data_size > sizeof(g.DragDropPayloadBufLocal)) |
| 11898 | { |
| 11899 | // Store in heap |
| 11900 | g.DragDropPayloadBufHeap.resize((int)data_size); |
| 11901 | payload.Data = g.DragDropPayloadBufHeap.Data; |
| 11902 | memcpy(payload.Data, data, data_size); |
| 11903 | } |
| 11904 | else if (data_size > 0) |
| 11905 | { |
| 11906 | // Store locally |
| 11907 | memset(&g.DragDropPayloadBufLocal, 0, sizeof(g.DragDropPayloadBufLocal)); |
| 11908 | payload.Data = g.DragDropPayloadBufLocal; |
| 11909 | memcpy(payload.Data, data, data_size); |
| 11910 | } |
| 11911 | else |
| 11912 | { |
| 11913 | payload.Data = NULL; |
| 11914 | } |
| 11915 | payload.DataSize = (int)data_size; |
| 11916 | } |
| 11917 | payload.DataFrameCount = g.FrameCount; |
| 11918 | |
| 11919 | // Return whether the payload has been accepted |
| 11920 | return (g.DragDropAcceptFrameCount == g.FrameCount) || (g.DragDropAcceptFrameCount == g.FrameCount - 1); |
| 11921 | } |
| 11922 | |
| 11923 | bool ImGui::BeginDragDropTargetCustom(const ImRect& bb, ImGuiID id) |
| 11924 | { |