Internals: Added BeginDragDropTooltip() internal function to convey semantic (drag and drop tooltip doesn't get clipped within display boundaries). Revert part of 3218666fb992d522f571160128591f299b6f65eb. (#1739, #143).
diff --git a/TODO.txt b/TODO.txt
index 8798f22..0ad2c63 100644
--- a/TODO.txt
+++ b/TODO.txt
@@ -163,7 +163,7 @@
- tooltip: drag and drop with tooltip near monitor edges lose/changes its last direction instead of locking one. The drag and drop tooltip should always follow without changing direction.
- tooltip: tooltip that doesn't fit in entire screen seems to lose their "last preferred direction" and may teleport when moving mouse.
- tooltip: allow to set the width of a tooltip to allow TextWrapped() etc. while keeping the height automatic.
- - tooltip: allow tooltips with timers? or general timer policy? (instantaneous vs timed)
+ - tooltip: tooltips with delay timers? or general timer policy? (instantaneous vs timed) (#1485)
- menus: calling BeginMenu() twice with a same name doesn't append as Begin() does for regular windows (#1207)
- menus: menu bars inside modals windows are acting weird.
@@ -215,7 +215,6 @@
- filters: handle wildcards (with implicit leading/trailing *), regexps
- filters: fuzzy matches (may use code at blog.forrestthewoods.com/4cffeed33fdb)
- - drag and drop: allow drag target to alter tooltip.
- drag and drop: add demo. (#143, #479)
- drag and drop: have some way to know when a drag begin from BeginDragDropSource() pov
- drag and drop: allow using with other mouse buttons (where activeid won't be set). (#1637)
diff --git a/imgui.cpp b/imgui.cpp
index 8fb4064..3794e6d 100644
--- a/imgui.cpp
+++ b/imgui.cpp
@@ -13230,11 +13230,9 @@
if (!(flags & ImGuiDragDropFlags_SourceNoPreviewTooltip))
{
- 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.
+ BeginDragDropTooltip();
if (g.DragDropActive && g.DragDropAcceptIdPrev && (g.DragDropAcceptFlags & ImGuiDragDropFlags_AcceptNoPreviewTooltip))
{
ImGuiWindow* tooltip_window = g.CurrentWindow;
@@ -13257,13 +13255,32 @@
IM_ASSERT(g.DragDropActive);
if (!(g.DragDropSourceFlags & ImGuiDragDropFlags_SourceNoPreviewTooltip))
- EndTooltip();
+ EndDragDropTooltip();
// Discard the drag if have not called SetDragDropPayload()
if (g.DragDropPayload.DataFrameCount == -1)
ClearDragDrop();
}
+void ImGui::BeginDragDropTooltip()
+{
+ // 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.
+ // Whatever we do we want to call SetNextWindowPos() to enforce a tooltip position and disable clipping the tooltip without our display area, like regular tooltip do.
+ ImGuiContext& g = *GImGui;
+ //ImVec2 tooltip_pos = g.IO.MousePos - g.ActiveIdClickOffset - g.Style.WindowPadding;
+ ImVec2 tooltip_pos = g.IO.MousePos + ImVec2(16 * g.Style.MouseCursorScale, 8 * g.Style.MouseCursorScale);
+ SetNextWindowPos(tooltip_pos);
+ SetNextWindowBgAlpha(g.Style.Colors[ImGuiCol_PopupBg].w * 0.60f);
+ //PushStyleVar(ImGuiStyleVar_Alpha, g.Style.Alpha * 0.60f); // This would be nice but e.g ColorButton with checkboard has issue with transparent colors :(
+ BeginTooltipEx(0, true);
+}
+
+void ImGui::EndDragDropTooltip()
+{
+ EndTooltip();
+}
+
// Use 'cond' to choose to submit payload on drag start or every frame
bool ImGui::SetDragDropPayload(const char* type, const void* data, size_t data_size, ImGuiCond cond)
{
diff --git a/imgui_internal.h b/imgui_internal.h
index ab66579..9682465 100644
--- a/imgui_internal.h
+++ b/imgui_internal.h
@@ -1111,6 +1111,8 @@
IMGUI_API bool BeginDragDropTargetCustom(const ImRect& bb, ImGuiID id);
IMGUI_API void ClearDragDrop();
IMGUI_API bool IsDragDropPayloadBeingAccepted();
+ IMGUI_API void BeginDragDropTooltip();
+ IMGUI_API void EndDragDropTooltip();
// FIXME-WIP: New Columns API
IMGUI_API void BeginColumns(const char* str_id, int count, ImGuiColumnsFlags flags = 0); // setup number of columns. use an identifier to distinguish multiple column sets. close with EndColumns().