Drag and Drop: Fixed using BeginDragDropSource() within a Begin()/BeginChild() that returned false. (#4515) + BeginDragDropTarget()

Note how 79ae6d3b adedd a SkipItems test in BeginDragDropTargetCustom() only.
Catching this similar to work needed to neatly represent the error in #4375 #4158, #4008, #2562
This commit is contained in:
ocornut 2021-09-06 20:42:40 +02:00
parent bd6c9e99fc
commit 607ad8c949
2 changed files with 7 additions and 7 deletions

View File

@ -52,6 +52,7 @@ Other Changes:
- Nav: Fixed toggling menu layer with Alt or exiting menu layer with Esc not moving mouse when - Nav: Fixed toggling menu layer with Alt or exiting menu layer with Esc not moving mouse when
the NavEnableSetMousePos config flag is set. the NavEnableSetMousePos config flag is set.
- Menus: adjust closing logic to accomodate for varying font size and dpi. - Menus: adjust closing logic to accomodate for varying font size and dpi.
- Drag and Drop: Fixed using BeginDragDropSource() inside a BeginChild() that returned false. (#4515)
- PlotHistogram: Fixed zero-line position when manually specifying min<0 and max>0. (#4349) [@filippocrocchini] - PlotHistogram: Fixed zero-line position when manually specifying min<0 and max>0. (#4349) [@filippocrocchini]
- IO: Added 'io.WantCaptureMouseUnlessPopupClose' alternative to `io.WantCaptureMouse'. (#4480) - IO: Added 'io.WantCaptureMouseUnlessPopupClose' alternative to `io.WantCaptureMouse'. (#4480)
This allows apps to receive the click on void when that click is used to close popup (by default, This allows apps to receive the click on void when that click is used to close popup (by default,

View File

@ -7813,6 +7813,7 @@ ImVec2 ImGui::GetWindowContentRegionMax()
// Lock horizontal starting position + capture group bounding box into one "item" (so you can use IsItemHovered() or layout primitives such as SameLine() on whole group, etc.) // Lock horizontal starting position + capture group bounding box into one "item" (so you can use IsItemHovered() or layout primitives such as SameLine() on whole group, etc.)
// Groups are currently a mishmash of functionalities which should perhaps be clarified and separated. // Groups are currently a mishmash of functionalities which should perhaps be clarified and separated.
// FIXME-OPT: Could we safely early out on ->SkipItems?
void ImGui::BeginGroup() void ImGui::BeginGroup()
{ {
ImGuiContext& g = *GImGui; ImGuiContext& g = *GImGui;
@ -9978,14 +9979,16 @@ bool ImGui::BeginDragDropSource(ImGuiDragDropFlags flags)
return false; return false;
if (g.ActiveIdMouseButton != -1) if (g.ActiveIdMouseButton != -1)
mouse_button = g.ActiveIdMouseButton; mouse_button = g.ActiveIdMouseButton;
if (g.IO.MouseDown[mouse_button] == false) if (g.IO.MouseDown[mouse_button] == false || window->SkipItems)
return false; return false;
g.ActiveIdAllowOverlap = false; g.ActiveIdAllowOverlap = false;
} }
else else
{ {
// Uncommon path: items without ID // Uncommon path: items without ID
if (g.IO.MouseDown[mouse_button] == false) if (g.IO.MouseDown[mouse_button] == false || window->SkipItems)
return false;
if ((g.LastItemData.StatusFlags & ImGuiItemStatusFlags_HoveredRect) == 0 && (g.ActiveId == 0 || g.ActiveIdWindow != window))
return false; return false;
// If you want to use BeginDragDropSource() on an item with no unique identifier for interaction, such as Text() or Image(), you need to: // If you want to use BeginDragDropSource() on an item with no unique identifier for interaction, such as Text() or Image(), you need to:
@ -9996,10 +9999,6 @@ bool ImGui::BeginDragDropSource(ImGuiDragDropFlags flags)
return false; return false;
} }
// Early out
if ((g.LastItemData.StatusFlags & ImGuiItemStatusFlags_HoveredRect) == 0 && (g.ActiveId == 0 || g.ActiveIdWindow != window))
return false;
// Magic fallback (=somehow reprehensible) to handle items with no assigned ID, e.g. Text(), Image() // Magic fallback (=somehow reprehensible) to handle items with no assigned ID, e.g. Text(), Image()
// We build a throwaway ID based on current ID stack + relative AABB of items in window. // We build a throwaway ID based on current ID stack + relative AABB of items in window.
// THE IDENTIFIER WON'T SURVIVE ANY REPOSITIONING OF THE WIDGET, so if your widget moves your dragging operation will be canceled. // THE IDENTIFIER WON'T SURVIVE ANY REPOSITIONING OF THE WIDGET, so if your widget moves your dragging operation will be canceled.
@ -10165,7 +10164,7 @@ bool ImGui::BeginDragDropTarget()
if (!(g.LastItemData.StatusFlags & ImGuiItemStatusFlags_HoveredRect)) if (!(g.LastItemData.StatusFlags & ImGuiItemStatusFlags_HoveredRect))
return false; return false;
ImGuiWindow* hovered_window = g.HoveredWindowUnderMovingWindow; ImGuiWindow* hovered_window = g.HoveredWindowUnderMovingWindow;
if (hovered_window == NULL || window->RootWindow != hovered_window->RootWindow) if (hovered_window == NULL || window->RootWindow != hovered_window->RootWindow || window->SkipItems)
return false; return false;
const ImRect& display_rect = (g.LastItemData.StatusFlags & ImGuiItemStatusFlags_HasDisplayRect) ? g.LastItemData.DisplayRect : g.LastItemData.Rect; const ImRect& display_rect = (g.LastItemData.StatusFlags & ImGuiItemStatusFlags_HasDisplayRect) ? g.LastItemData.DisplayRect : g.LastItemData.Rect;