Browse Source

Drag and Drop: 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)

omar 7 years ago
parent
commit
b88fbd69cc
2 changed files with 7 additions and 1 deletions
  1. 2 0
      CHANGELOG.txt
  2. 5 1
      imgui.cpp

+ 2 - 0
CHANGELOG.txt

@@ -46,6 +46,8 @@ Other Changes:
  - Nav: To keep the navigated item in view we also attempt to scroll the parent window as well as the current window. (#787)
  - 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)
+ - 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]
 
 -----------------------------------------------------------------------

+ 5 - 1
imgui.cpp

@@ -13203,7 +13203,11 @@ bool ImGui::BeginDragDropSource(ImGuiDragDropFlags flags)
             // 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 :(
-            SetNextWindowPos(g.IO.MousePos);
+
+            // 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();
         }