diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index bf7ebe8c7..3bab14762 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -94,9 +94,12 @@ Other Changes: triggered by some widgets e.g. Checkbox(), Selectable() and many others, which cleared ActiveId at the same time as editing. (#9028) Note that IsItemDeactivatedAfterEdit() was not affected, only IsItemEdited). -- Style, Drag and Drop: added ImGuiCol_DragDropTargetBg, style.DragDropTargetRounding, - style.DragDropTargetBorderSize and style.DragDropTargetPadding to configure - the drop target highlight. (#9056) [@aaronkirkham] +- Drag and Drop: + - Added ImGuiDragDropFlags_AcceptDrawAsHovered to make accepting item render + as hovered, which can allow using e.g. Button() as drop target. (#8632) + - Style: added ImGuiCol_DragDropTargetBg, style.DragDropTargetRounding, + style.DragDropTargetBorderSize and style.DragDropTargetPadding to configure + the drop target highlight. (#9056) [@aaronkirkham] - Demo: About Box: emit infos to convey when IM_ASSERT() macro is disabled, - so users don't miss out on programming errors being reported. - so it is included in config/build info submitted in new GitHub Issues. diff --git a/imgui.h b/imgui.h index 4381040f1..81774857f 100644 --- a/imgui.h +++ b/imgui.h @@ -1484,6 +1484,7 @@ enum ImGuiDragDropFlags_ 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_AcceptDrawAsHovered = 1 << 13, // Accepting item will render as if hovered. Useful for e.g. a Button() used as a drop target. ImGuiDragDropFlags_AcceptPeekOnly = ImGuiDragDropFlags_AcceptBeforeDelivery | ImGuiDragDropFlags_AcceptNoDrawDefaultRect, // For peeking ahead and inspecting the payload before delivery. #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 6d17213a2..8c322e8dd 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -574,8 +574,9 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool // Special mode for Drag and Drop used by openables (tree nodes, tabs etc.) // where holding the button pressed for a long time while drag a payload item triggers the button. - if (g.DragDropActive && (flags & ImGuiButtonFlags_PressedOnDragDropHold) && !(g.DragDropSourceFlags & ImGuiDragDropFlags_SourceNoHoldToOpenOthers)) - if (IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByActiveItem)) + if (g.DragDropActive) + { + if ((flags & ImGuiButtonFlags_PressedOnDragDropHold) && !(g.DragDropSourceFlags & ImGuiDragDropFlags_SourceNoHoldToOpenOthers) && IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByActiveItem)) { hovered = true; SetHoveredID(id); @@ -586,6 +587,9 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool FocusWindow(window); } } + if (g.DragDropAcceptIdPrev == id && (g.DragDropAcceptFlagsPrev & ImGuiDragDropFlags_AcceptDrawAsHovered)) + hovered = true; + } if (flatten_hovered_children) g.HoveredWindow = backup_hovered_window;