Skip to content

Commit bd0e203

Browse files
committed
Drag and Drop: added ImGuiDragDropFlags_AcceptDrawAsHovered. (#8632)
Not calling SetHoveredId() in that path, does not seem necessary.
1 parent b0d3c3a commit bd0e203

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

docs/CHANGELOG.txt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,12 @@ Other Changes:
9494
triggered by some widgets e.g. Checkbox(), Selectable() and many others, which
9595
cleared ActiveId at the same time as editing. (#9028)
9696
Note that IsItemDeactivatedAfterEdit() was not affected, only IsItemEdited).
97-
- Style, Drag and Drop: added ImGuiCol_DragDropTargetBg, style.DragDropTargetRounding,
98-
style.DragDropTargetBorderSize and style.DragDropTargetPadding to configure
99-
the drop target highlight. (#9056) [@aaronkirkham]
97+
- Drag and Drop:
98+
- Added ImGuiDragDropFlags_AcceptDrawAsHovered to make accepting item render
99+
as hovered, which can allow using e.g. Button() as drop target. (#8632)
100+
- Style: added ImGuiCol_DragDropTargetBg, style.DragDropTargetRounding,
101+
style.DragDropTargetBorderSize and style.DragDropTargetPadding to configure
102+
the drop target highlight. (#9056) [@aaronkirkham]
100103
- Demo: About Box: emit infos to convey when IM_ASSERT() macro is disabled,
101104
- so users don't miss out on programming errors being reported.
102105
- so it is included in config/build info submitted in new GitHub Issues.

imgui.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,6 +1484,7 @@ enum ImGuiDragDropFlags_
14841484
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.
14851485
ImGuiDragDropFlags_AcceptNoDrawDefaultRect = 1 << 11, // Do not draw the default highlight rectangle when hovering over target.
14861486
ImGuiDragDropFlags_AcceptNoPreviewTooltip = 1 << 12, // Request hiding the BeginDragDropSource tooltip from the BeginDragDropTarget site.
1487+
ImGuiDragDropFlags_AcceptDrawAsHovered = 1 << 13, // Accepting item will render as if hovered. Useful for e.g. a Button() used as a drop target.
14871488
ImGuiDragDropFlags_AcceptPeekOnly = ImGuiDragDropFlags_AcceptBeforeDelivery | ImGuiDragDropFlags_AcceptNoDrawDefaultRect, // For peeking ahead and inspecting the payload before delivery.
14881489

14891490
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS

imgui_widgets.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -574,8 +574,9 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool
574574

575575
// Special mode for Drag and Drop used by openables (tree nodes, tabs etc.)
576576
// where holding the button pressed for a long time while drag a payload item triggers the button.
577-
if (g.DragDropActive && (flags & ImGuiButtonFlags_PressedOnDragDropHold) && !(g.DragDropSourceFlags & ImGuiDragDropFlags_SourceNoHoldToOpenOthers))
578-
if (IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByActiveItem))
577+
if (g.DragDropActive)
578+
{
579+
if ((flags & ImGuiButtonFlags_PressedOnDragDropHold) && !(g.DragDropSourceFlags & ImGuiDragDropFlags_SourceNoHoldToOpenOthers) && IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByActiveItem))
579580
{
580581
hovered = true;
581582
SetHoveredID(id);
@@ -586,6 +587,9 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool
586587
FocusWindow(window);
587588
}
588589
}
590+
if (g.DragDropAcceptIdPrev == id && (g.DragDropAcceptFlagsPrev & ImGuiDragDropFlags_AcceptDrawAsHovered))
591+
hovered = true;
592+
}
589593

590594
if (flatten_hovered_children)
591595
g.HoveredWindow = backup_hovered_window;

0 commit comments

Comments
 (0)