Drag and Drop: tweaked BeginDragDropSource() to remove indent. Added debug log.
diff --git a/imgui.cpp b/imgui.cpp
index 4d1c5f0..a917148 100644
--- a/imgui.cpp
+++ b/imgui.cpp
@@ -13096,6 +13096,8 @@
void ImGui::ClearDragDrop()
{
ImGuiContext& g = *GImGui;
+ if (g.DragDropActive)
+ IMGUI_DEBUG_LOG_ACTIVEID("[dragdrop] ClearDragDrop()\n");
g.DragDropActive = false;
g.DragDropPayload.Clear();
g.DragDropAcceptFlags = ImGuiDragDropFlags_None;
@@ -13134,7 +13136,7 @@
bool source_drag_active = false;
ImGuiID source_id = 0;
ImGuiID source_parent_id = 0;
- if (!(flags & ImGuiDragDropFlags_SourceExtern))
+ if ((flags & ImGuiDragDropFlags_SourceExtern) == 0)
{
source_id = g.LastItemData.ID;
if (source_id != 0)
@@ -13196,43 +13198,44 @@
}
IM_ASSERT(g.DragDropWithinTarget == false); // Can't nest BeginDragDropSource() and BeginDragDropTarget()
- if (source_drag_active)
+ if (!source_drag_active)
+ return false;
+
+ // Activate drag and drop
+ if (!g.DragDropActive)
{
- if (!g.DragDropActive)
- {
- IM_ASSERT(source_id != 0);
- ClearDragDrop();
- ImGuiPayload& payload = g.DragDropPayload;
- payload.SourceId = source_id;
- payload.SourceParentId = source_parent_id;
- g.DragDropActive = true;
- g.DragDropSourceFlags = flags;
- g.DragDropMouseButton = mouse_button;
- if (payload.SourceId == g.ActiveId)
- g.ActiveIdNoClearOnFocusLoss = true;
- }
- g.DragDropSourceFrameCount = g.FrameCount;
- g.DragDropWithinSource = true;
-
- if (!(flags & ImGuiDragDropFlags_SourceNoPreviewTooltip))
- {
- // Target can request the Source to not display its tooltip (we use a dedicated flag to make this request explicit)
- // We unfortunately can't just modify the source flags and skip the call to BeginTooltip, as caller may be emitting contents.
- bool ret;
- if (g.DragDropAcceptIdPrev && (g.DragDropAcceptFlags & ImGuiDragDropFlags_AcceptNoPreviewTooltip))
- ret = BeginTooltipHidden();
- else
- ret = BeginTooltip();
- IM_ASSERT(ret); // FIXME-NEWBEGIN: If this ever becomes false, we need to Begin("##Hidden", NULL, ImGuiWindowFlags_NoSavedSettings) + SetWindowHiddendAndSkipItemsForCurrentFrame().
- IM_UNUSED(ret);
- }
-
- if (!(flags & ImGuiDragDropFlags_SourceNoDisableHover) && !(flags & ImGuiDragDropFlags_SourceExtern))
- g.LastItemData.StatusFlags &= ~ImGuiItemStatusFlags_HoveredRect;
-
- return true;
+ IM_ASSERT(source_id != 0);
+ ClearDragDrop();
+ IMGUI_DEBUG_LOG_ACTIVEID("[dragdrop] BeginDragDropSource() DragDropActive = true, source_id = %08X\n", source_id);
+ ImGuiPayload& payload = g.DragDropPayload;
+ payload.SourceId = source_id;
+ payload.SourceParentId = source_parent_id;
+ g.DragDropActive = true;
+ g.DragDropSourceFlags = flags;
+ g.DragDropMouseButton = mouse_button;
+ if (payload.SourceId == g.ActiveId)
+ g.ActiveIdNoClearOnFocusLoss = true;
}
- return false;
+ g.DragDropSourceFrameCount = g.FrameCount;
+ g.DragDropWithinSource = true;
+
+ if (!(flags & ImGuiDragDropFlags_SourceNoPreviewTooltip))
+ {
+ // Target can request the Source to not display its tooltip (we use a dedicated flag to make this request explicit)
+ // We unfortunately can't just modify the source flags and skip the call to BeginTooltip, as caller may be emitting contents.
+ bool ret;
+ if (g.DragDropAcceptIdPrev && (g.DragDropAcceptFlags & ImGuiDragDropFlags_AcceptNoPreviewTooltip))
+ ret = BeginTooltipHidden();
+ else
+ ret = BeginTooltip();
+ IM_ASSERT(ret); // FIXME-NEWBEGIN: If this ever becomes false, we need to Begin("##Hidden", NULL, ImGuiWindowFlags_NoSavedSettings) + SetWindowHiddendAndSkipItemsForCurrentFrame().
+ IM_UNUSED(ret);
+ }
+
+ if (!(flags & ImGuiDragDropFlags_SourceNoDisableHover) && !(flags & ImGuiDragDropFlags_SourceExtern))
+ g.LastItemData.StatusFlags &= ~ImGuiItemStatusFlags_HoveredRect;
+
+ return true;
}
void ImGui::EndDragDropSource()