From 92b7d6bc4fe3ecc33a7fdb93046ecca0eacf6dd4 Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 28 May 2018 20:50:52 +0200 Subject: [PATCH] Added ImGuiDragDropFlags_AcceptNoPreviewTooltip flag to disable drag source tooltip from the target site (#143) --- CHANGELOG.txt | 1 + TODO.txt | 4 +++- imgui.cpp | 11 +++++++++++ imgui.h | 1 + imgui_internal.h | 4 +++- 5 files changed, 19 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 4a883c8a3..df79549b0 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -47,6 +47,7 @@ Other Changes: - TreeNode: Fixed nodes with ImGuiTreeNodeFlags_Leaf flag always returning true which was meaningless. - ColorEdit3, ColorEdit4, ColorButton: Added ImGuiColorEditFlags_NoDragDrop flag to disable ColorEditX as drag target and ColorButton as drag source. (#1826) - BeginDragDropSource(): Offset tooltip position so it is off the mouse cursor, but also closer to it than regular tooltips, and not clamped by viewport. (#1739) + - BeginDragDropTarget(): Added ImGuiDragDropFlags_AcceptNoPreviewTooltip flag to request hiding the drag source tooltip from the target site. (#143) - BeginCombo(), BeginMainMenuBar(), BeginChildFrame(): Temporary style modification are restored at the end of BeginXXX instead of EndXXX, to not affect tooltips and child windows. - Examples: GLFW: Made it possible to Shutdown/Init the backend again (by reseting the time storage properly). (#1827) [@ice1000] - Internals: PushItemFlag() flags are inherited by BeginChild(). diff --git a/TODO.txt b/TODO.txt index d6c471d26..8798f2255 100644 --- a/TODO.txt +++ b/TODO.txt @@ -215,11 +215,13 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - 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 / and or disable tooltip. + - 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) - drag and drop: test with reordering nodes (in a list, or a tree node). (#143) - drag and drop: test integrating with os drag and drop. + - drag and drop: make payload optional? (#143) - node/graph editor (#306) - pie menus patterns (#434) - markup: simple markup language for color change? (#902) diff --git a/imgui.cpp b/imgui.cpp index f73a966cb..a09f3fdf5 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -13145,6 +13145,7 @@ void ImGui::ClearDragDrop() ImGuiContext& g = *GImGui; g.DragDropActive = false; g.DragDropPayload.Clear(); + g.DragDropAcceptFlags = 0; g.DragDropAcceptIdCurr = g.DragDropAcceptIdPrev = 0; g.DragDropAcceptIdCurrRectSurface = FLT_MAX; g.DragDropAcceptFrameCount = -1; @@ -13239,6 +13240,15 @@ bool ImGui::BeginDragDropSource(ImGuiDragDropFlags flags) SetNextWindowPos(tooltip_pos); PushStyleColor(ImGuiCol_PopupBg, GetStyleColorVec4(ImGuiCol_PopupBg) * ImVec4(1.0f, 1.0f, 1.0f, 0.6f)); BeginTooltip(); + + // 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. + if (g.DragDropActive && g.DragDropAcceptIdPrev && (g.DragDropAcceptFlags & ImGuiDragDropFlags_AcceptNoPreviewTooltip)) + { + ImGuiWindow* tooltip_window = g.CurrentWindow; + tooltip_window->SkipItems = true; + tooltip_window->HiddenFrames = 1; + } } if (!(flags & ImGuiDragDropFlags_SourceNoDisableHover) && !(flags & ImGuiDragDropFlags_SourceExtern)) @@ -13379,6 +13389,7 @@ const ImGuiPayload* ImGui::AcceptDragDropPayload(const char* type, ImGuiDragDrop float r_surface = r.GetWidth() * r.GetHeight(); if (r_surface < g.DragDropAcceptIdCurrRectSurface) { + g.DragDropAcceptFlags = flags; g.DragDropAcceptIdCurr = g.DragDropTargetId; g.DragDropAcceptIdCurrRectSurface = r_surface; } diff --git a/imgui.h b/imgui.h index 5989164b5..f580ce8ba 100644 --- a/imgui.h +++ b/imgui.h @@ -717,6 +717,7 @@ enum ImGuiDragDropFlags_ // AcceptDragDropPayload() flags ImGuiDragDropFlags_AcceptBeforeDelivery = 1 << 10, // AcceptDragDropPayload() will returns true even before the mouse button is released. You can then call IsDelivery() to test if the payload needs to be delivered. ImGuiDragDropFlags_AcceptNoDrawDefaultRect = 1 << 11, // Do not draw the default highlight rectangle when hovering over target. + ImGuiDragDropFlags_AcceptNoPreviewTooltip = 1 << 12, // Request hiding the BeginDragDropSource tooltip from the BeginDragDropTarget site. ImGuiDragDropFlags_AcceptPeekOnly = ImGuiDragDropFlags_AcceptBeforeDelivery | ImGuiDragDropFlags_AcceptNoDrawDefaultRect // For peeking ahead and inspecting the payload before delivery. }; diff --git a/imgui_internal.h b/imgui_internal.h index 92c567318..ab665794f 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -688,7 +688,8 @@ struct ImGuiContext ImGuiPayload DragDropPayload; ImRect DragDropTargetRect; ImGuiID DragDropTargetId; - float DragDropAcceptIdCurrRectSurface; + ImGuiDragDropFlags DragDropAcceptFlags; + float DragDropAcceptIdCurrRectSurface; // Target item surface (we resolve overlapping targets by prioritizing the smaller surface) ImGuiID DragDropAcceptIdCurr; // Target item id (set at the time of accepting the payload) ImGuiID DragDropAcceptIdPrev; // Target item id from previous frame (we need to store this to allow for overlapping drag and drop targets) int DragDropAcceptFrameCount; // Last time a target expressed a desire to accept the source @@ -799,6 +800,7 @@ struct ImGuiContext DragDropSourceFlags = 0; DragDropMouseButton = -1; DragDropTargetId = 0; + DragDropAcceptFlags = 0; DragDropAcceptIdCurrRectSurface = 0.0f; DragDropAcceptIdPrev = DragDropAcceptIdCurr = 0; DragDropAcceptFrameCount = -1;