Skip to content

Commit

Permalink
Made drag source tooltip display at the same position as a regular to…
Browse files Browse the repository at this point in the history
…oltip to avoid discontinuity where dynamically swapping tooltip at the target site. Made drag source tooltip override previous tooltip if any. (#1739, #143).
  • Loading branch information
ocornut committed May 28, 2018
1 parent 92b7d6b commit 3218666
Showing 1 changed file with 2 additions and 14 deletions.
16 changes: 2 additions & 14 deletions imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13230,16 +13230,8 @@ bool ImGui::BeginDragDropSource(ImGuiDragDropFlags flags)

if (!(flags & ImGuiDragDropFlags_SourceNoPreviewTooltip))
{
// FIXME-DRAG
//SetNextWindowPos(g.IO.MousePos - g.ActiveIdClickOffset - g.Style.WindowPadding);
//PushStyleVar(ImGuiStyleVar_Alpha, g.Style.Alpha * 0.60f); // This is better but e.g ColorButton with checkboard has issue with transparent colors :(

// The default tooltip position is a little offset to give space to see the context menu (it's also clamped within the current viewport/monitor)
// In the context of a dragging tooltip we try to reduce that offset and we enforce following the cursor.
ImVec2 tooltip_pos = g.IO.MousePos + ImVec2(16 * g.Style.MouseCursorScale, 8 * g.Style.MouseCursorScale);
SetNextWindowPos(tooltip_pos);
PushStyleColor(ImGuiCol_PopupBg, GetStyleColorVec4(ImGuiCol_PopupBg) * ImVec4(1.0f, 1.0f, 1.0f, 0.6f));
BeginTooltip();
SetNextWindowBgAlpha(g.Style.Colors[ImGuiCol_PopupBg].w * 0.60f);
BeginTooltipEx(0, true);

// 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.
Expand All @@ -13265,11 +13257,7 @@ void ImGui::EndDragDropSource()
IM_ASSERT(g.DragDropActive);

if (!(g.DragDropSourceFlags & ImGuiDragDropFlags_SourceNoPreviewTooltip))
{
EndTooltip();
PopStyleColor();
//PopStyleVar();
}

// Discard the drag if have not called SetDragDropPayload()
if (g.DragDropPayload.DataFrameCount == -1)
Expand Down

0 comments on commit 3218666

Please sign in to comment.