From 6ea744d8f42cd8b5bd89562126712ddd79700721 Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 30 Nov 2017 16:54:39 +0100 Subject: [PATCH] Drag and Drop: Added DragSource from color square. Added DragTarget on ColorEdit4 widget. (#143) --- imgui.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/imgui.cpp b/imgui.cpp index a21cba8b..280a2438 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -9671,6 +9671,16 @@ bool ImGui::ColorButton(const char* desc_id, const ImVec4& col, ImGuiColorEditFl else window->DrawList->AddRect(bb.Min, bb.Max, GetColorU32(ImGuiCol_FrameBg), rounding); // Color button are often in need of some sort of border + if (g.ActiveId == id && BeginDragDropSource()) // NB: The ActiveId test is merely an optional micro-optimization + { + SetDragDropPayload(IMGUI_PAYLOAD_TYPE_COLOR_4F, &col, sizeof(col), ImGuiCond_Once); + ColorButton(desc_id, col, flags); + SameLine(); + TextUnformatted("Color"); + EndDragDropSource(); + hovered = false; + } + if (!(flags & ImGuiColorEditFlags_NoTooltip) && hovered) ColorTooltip(desc_id, &col.x, flags & (ImGuiColorEditFlags_NoAlpha | ImGuiColorEditFlags_AlphaPreview | ImGuiColorEditFlags_AlphaPreviewHalf)); @@ -9947,6 +9957,17 @@ bool ImGui::ColorEdit4(const char* label, float col[4], ImGuiColorEditFlags flag PopID(); EndGroup(); + if (window->DC.LastItemRectHoveredRect && BeginDragDropTarget()) // NB: The LastItemRectHoveredRect test is merely an optional micro-optimization + { + if (const ImGuiPayload* payload = AcceptDragDropPayload(IMGUI_PAYLOAD_TYPE_COLOR_4F)) + { + IM_ASSERT(payload->DataSize == sizeof(ImVec4)); + memcpy((float*)col, payload->Data, sizeof(ImVec4)); + value_changed = true; + } + EndDragDropTarget(); + } + return value_changed; }