Drag and Drop: Fixed submitting a tooltip from drop target location. Added demo.

Amend 7bbf8f2, 92b7d6b.
This commit is contained in:
ocornut
2023-10-05 12:06:40 +02:00
parent 64b1aeebf5
commit a63e2f0a33
4 changed files with 46 additions and 4 deletions

View File

@ -12403,6 +12403,14 @@ void ImGui::ClearDragDrop()
memset(&g.DragDropPayloadBufLocal, 0, sizeof(g.DragDropPayloadBufLocal));
}
bool ImGui::BeginTooltipHidden()
{
ImGuiContext& g = *GImGui;
bool ret = Begin("##Tooltip_Hidden", NULL, ImGuiWindowFlags_Tooltip | ImGuiWindowFlags_NoInputs | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_AlwaysAutoResize);
SetWindowHiddendAndSkipItemsForCurrentFrame(g.CurrentWindow);
return ret;
}
// When this returns true you need to: a) call SetDragDropPayload() exactly once, b) you may render the payload visual/description, c) call EndDragDropSource()
// If the item has an identifier:
// - This assume/require the item to be activated (typically via ButtonBehavior).
@ -12505,12 +12513,13 @@ bool ImGui::BeginDragDropSource(ImGuiDragDropFlags flags)
{
// 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 = BeginTooltip();
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 (g.DragDropAcceptIdPrev && (g.DragDropAcceptFlags & ImGuiDragDropFlags_AcceptNoPreviewTooltip))
SetWindowHiddendAndSkipItemsForCurrentFrame(g.CurrentWindow);
}
if (!(flags & ImGuiDragDropFlags_SourceNoDisableHover) && !(flags & ImGuiDragDropFlags_SourceExtern))