From d5d4d709c7f03527d334ff0ffd65d0a090c64102 Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 27 Jun 2023 14:41:51 +0200 Subject: [PATCH] Drag and Drop: moved "drag souce doesn't report as hovered" from ButtonBehavior() to ItemHoverable(). Ensure DragXXX, SliderXXXX, InputText, PlotXXX follow same logic. Amend 251f178a6, a33f0d1f7 --- docs/CHANGELOG.txt | 3 +++ imgui.cpp | 4 ++++ imgui_widgets.cpp | 4 ---- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index c20cfe941..86b9de707 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -75,6 +75,9 @@ Other changes: - Clipper: Rework inner logic to allow functioning with a zero-clear constructor. This is order to facilitate usage for language bindings (e.g cimgui or dear_binding) where user may not be callinga constructor manually. (#5856) +- Drag and Drop: Apply default behavior of drag source not reporting itself as hovered + at lower-level, so DragXXX, SliderXXX, InputXXX, Plot widgets are fullfilling it. + (Behavior doesn't apply when ImGuiDragDropFlags_SourceNoDisableHover is set). - Modals: In the case of nested modal, made sure that focused or appearing windows are moved below the lowest blocking modal (rather than the highest one). (#4317) - GetKeyName(): Fixed assert with ImGuiMod_XXX values when IMGUI_DISABLE_OBSOLETE_KEYIO is set. diff --git a/imgui.cpp b/imgui.cpp index 2349389ba..a60c2f179 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -4050,6 +4050,10 @@ bool ImGui::ItemHoverable(const ImRect& bb, ImGuiID id) return false; } + // Drag source doesn't report as hovered + if (g.DragDropActive && g.DragDropPayload.SourceId == id && !(g.DragDropSourceFlags & ImGuiDragDropFlags_SourceNoDisableHover)) + return false; + // We exceptionally allow this function to be called with id==0 to allow using it for easy high-level // hover test in widgets code. We could also decide to split this function is two. if (id != 0) diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index fdcd21240..2dc948680 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -506,10 +506,6 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool bool pressed = false; bool hovered = ItemHoverable(bb, id); - // Drag source doesn't report as hovered - if (hovered && g.DragDropActive && g.DragDropPayload.SourceId == id && !(g.DragDropSourceFlags & ImGuiDragDropFlags_SourceNoDisableHover)) - hovered = false; - // Special mode for Drag and Drop where holding button pressed for a long time while dragging another item triggers the button if (g.DragDropActive && (flags & ImGuiButtonFlags_PressedOnDragDropHold) && !(g.DragDropSourceFlags & ImGuiDragDropFlags_SourceNoHoldToOpenOthers)) if (IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByActiveItem))