Drag and Drop: rework RenderDragDropTargetRect() into RenderDragDropTargetRectForItem() and add RenderDragDropTargetRectEx(). (#1603, #5204)

This commit is contained in:
ocornut
2025-10-03 18:54:15 +02:00
parent 3ac624b795
commit 1cdec11e24
2 changed files with 11 additions and 5 deletions

View File

@@ -14793,7 +14793,7 @@ const ImGuiPayload* ImGui::AcceptDragDropPayload(const char* type, ImGuiDragDrop
payload.Preview = was_accepted_previously; payload.Preview = was_accepted_previously;
flags |= (g.DragDropSourceFlags & ImGuiDragDropFlags_AcceptNoDrawDefaultRect); // Source can also inhibit the preview (useful for external sources that live for 1 frame) flags |= (g.DragDropSourceFlags & ImGuiDragDropFlags_AcceptNoDrawDefaultRect); // Source can also inhibit the preview (useful for external sources that live for 1 frame)
if (!(flags & ImGuiDragDropFlags_AcceptNoDrawDefaultRect) && payload.Preview) if (!(flags & ImGuiDragDropFlags_AcceptNoDrawDefaultRect) && payload.Preview)
RenderDragDropTargetRect(r, g.DragDropTargetClipRect); RenderDragDropTargetRectForItem(r);
g.DragDropAcceptFrameCount = g.FrameCount; g.DragDropAcceptFrameCount = g.FrameCount;
if ((g.DragDropSourceFlags & ImGuiDragDropFlags_SourceExtern) && g.DragDropMouseButton == -1) if ((g.DragDropSourceFlags & ImGuiDragDropFlags_SourceExtern) && g.DragDropMouseButton == -1)
@@ -14809,21 +14809,26 @@ const ImGuiPayload* ImGui::AcceptDragDropPayload(const char* type, ImGuiDragDrop
} }
// FIXME-STYLE FIXME-DRAGDROP: Settle on a proper default visuals for drop target. // FIXME-STYLE FIXME-DRAGDROP: Settle on a proper default visuals for drop target.
void ImGui::RenderDragDropTargetRect(const ImRect& bb, const ImRect& item_clip_rect) void ImGui::RenderDragDropTargetRectForItem(const ImRect& bb)
{ {
ImGuiContext& g = *GImGui; ImGuiContext& g = *GImGui;
ImGuiWindow* window = g.CurrentWindow; ImGuiWindow* window = g.CurrentWindow;
ImRect bb_display = bb; ImRect bb_display = bb;
bb_display.ClipWith(item_clip_rect); // Clip THEN expand so we have a way to visualize that target is not entirely visible. bb_display.ClipWith(g.DragDropTargetClipRect); // Clip THEN expand so we have a way to visualize that target is not entirely visible.
bb_display.Expand(3.5f); bb_display.Expand(3.5f);
bool push_clip_rect = !window->ClipRect.Contains(bb_display); bool push_clip_rect = !window->ClipRect.Contains(bb_display);
if (push_clip_rect) if (push_clip_rect)
window->DrawList->PushClipRectFullScreen(); window->DrawList->PushClipRectFullScreen();
window->DrawList->AddRect(bb_display.Min, bb_display.Max, GetColorU32(ImGuiCol_DragDropTarget), 0.0f, 0, 2.0f); // FIXME-DPI RenderDragDropTargetRectEx(window->DrawList, bb_display);
if (push_clip_rect) if (push_clip_rect)
window->DrawList->PopClipRect(); window->DrawList->PopClipRect();
} }
void ImGui::RenderDragDropTargetRectEx(ImDrawList* draw_list, const ImRect& bb)
{
draw_list->AddRect(bb.Min, bb.Max, GetColorU32(ImGuiCol_DragDropTarget), 0.0f, 0, 2.0f); // FIXME-DPI
}
const ImGuiPayload* ImGui::GetDragDropPayload() const ImGuiPayload* ImGui::GetDragDropPayload()
{ {
ImGuiContext& g = *GImGui; ImGuiContext& g = *GImGui;

View File

@@ -3423,7 +3423,8 @@ namespace ImGui
IMGUI_API bool BeginDragDropTargetCustom(const ImRect& bb, ImGuiID id); IMGUI_API bool BeginDragDropTargetCustom(const ImRect& bb, ImGuiID id);
IMGUI_API void ClearDragDrop(); IMGUI_API void ClearDragDrop();
IMGUI_API bool IsDragDropPayloadBeingAccepted(); IMGUI_API bool IsDragDropPayloadBeingAccepted();
IMGUI_API void RenderDragDropTargetRect(const ImRect& bb, const ImRect& item_clip_rect); IMGUI_API void RenderDragDropTargetRectForItem(const ImRect& bb);
IMGUI_API void RenderDragDropTargetRectEx(ImDrawList* draw_list, const ImRect& bb);
// Typing-Select API // Typing-Select API
// (provide Windows Explorer style "select items by typing partial name" + "cycle through items by typing same letter" feature) // (provide Windows Explorer style "select items by typing partial name" + "cycle through items by typing same letter" feature)