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
This commit is contained in:
ocornut 2023-06-27 14:41:51 +02:00
parent a2f6581171
commit d5d4d709c7
3 changed files with 7 additions and 4 deletions

View File

@ -75,6 +75,9 @@ Other changes:
- Clipper: Rework inner logic to allow functioning with a zero-clear constructor. - 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) This is order to facilitate usage for language bindings (e.g cimgui or dear_binding)
where user may not be callinga constructor manually. (#5856) 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 - 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) 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. - GetKeyName(): Fixed assert with ImGuiMod_XXX values when IMGUI_DISABLE_OBSOLETE_KEYIO is set.

View File

@ -4050,6 +4050,10 @@ bool ImGui::ItemHoverable(const ImRect& bb, ImGuiID id)
return false; 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 // 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. // hover test in widgets code. We could also decide to split this function is two.
if (id != 0) if (id != 0)

View File

@ -506,10 +506,6 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool
bool pressed = false; bool pressed = false;
bool hovered = ItemHoverable(bb, id); 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 // 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 (g.DragDropActive && (flags & ImGuiButtonFlags_PressedOnDragDropHold) && !(g.DragDropSourceFlags & ImGuiDragDropFlags_SourceNoHoldToOpenOthers))
if (IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByActiveItem)) if (IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByActiveItem))