From 7954d6782e0d7324eb68caac6c2dfbcc9afc9954 Mon Sep 17 00:00:00 2001 From: aaronkirkham Date: Wed, 5 Nov 2025 23:16:48 +0000 Subject: [PATCH] Drag and Drop, Style: added basic styling options to DragDrop target rect. (#9056) --- imgui.cpp | 14 ++++++++++++-- imgui.h | 6 +++++- imgui_draw.cpp | 3 +++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 89a57174c..955f7b8a9 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1450,6 +1450,9 @@ ImGuiStyle::ImGuiStyle() AntiAliasedFill = true; // Enable anti-aliased filled shapes (rounded rectangles, circles, etc.). CurveTessellationTol = 1.25f; // Tessellation tolerance when using PathBezierCurveTo() without a specific number of segments. Decrease for highly tessellated curves (higher quality, more polygons), increase to reduce quality. CircleTessellationMaxError = 0.30f; // Maximum error (in pixels) allowed when using AddCircle()/AddCircleFilled() or drawing rounded corner rectangles with no explicit segment count specified. Decrease for higher quality but more geometry. + DragDropTargetRectRounding = 0.0f; // Corner radius of the drag-drop hover frame + DragDropTargetRectLineThickness = 2.0f; // Thickness of the drop-drop hover frame lines + DragDropTargetRectExpansionSize = 3.5f; // The size in which the drag-drop hover rect will expand over the target // Behaviors HoverStationaryDelay = 0.15f; // Delay for IsItemHovered(ImGuiHoveredFlags_Stationary). Time required to consider mouse stationary. @@ -3711,6 +3714,7 @@ const char* ImGui::GetStyleColorName(ImGuiCol idx) case ImGuiCol_TextSelectedBg: return "TextSelectedBg"; case ImGuiCol_TreeLines: return "TreeLines"; case ImGuiCol_DragDropTarget: return "DragDropTarget"; + case ImGuiCol_DragDropTargetBg: return "DragDropTargetBg"; case ImGuiCol_UnsavedMarker: return "UnsavedMarker"; case ImGuiCol_NavCursor: return "NavCursor"; case ImGuiCol_NavWindowingHighlight: return "NavWindowingHighlight"; @@ -14893,7 +14897,7 @@ void ImGui::RenderDragDropTargetRectForItem(const ImRect& bb) ImGuiWindow* window = g.CurrentWindow; ImRect bb_display = bb; 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(g.Style.DragDropTargetRectExpansionSize); bool push_clip_rect = !window->ClipRect.Contains(bb_display); if (push_clip_rect) window->DrawList->PushClipRectFullScreen(); @@ -14904,7 +14908,13 @@ void ImGui::RenderDragDropTargetRectForItem(const ImRect& bb) 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 + ImGuiContext& g = *GImGui; + + const ImVec4& color_bg = GetStyleColorVec4(ImGuiCol_DragDropTargetBg); + if (color_bg.w > 0.0f) + draw_list->AddRectFilled(bb.Min, bb.Max, GetColorU32(color_bg), g.Style.DragDropTargetRectRounding, 0); + + draw_list->AddRect(bb.Min, bb.Max, GetColorU32(ImGuiCol_DragDropTarget), g.Style.DragDropTargetRectRounding, 0, g.Style.DragDropTargetRectLineThickness); // FIXME-DPI } const ImGuiPayload* ImGui::GetDragDropPayload() diff --git a/imgui.h b/imgui.h index bcafbf9a8..82d64ec1d 100644 --- a/imgui.h +++ b/imgui.h @@ -1776,7 +1776,8 @@ enum ImGuiCol_ ImGuiCol_TextLink, // Hyperlink color ImGuiCol_TextSelectedBg, // Selected text inside an InputText ImGuiCol_TreeLines, // Tree node hierarchy outlines when using ImGuiTreeNodeFlags_DrawLines - ImGuiCol_DragDropTarget, // Rectangle highlighting a drop target + ImGuiCol_DragDropTarget, // Rectangle border highlighting a drop target + ImGuiCol_DragDropTargetBg, // Rectangle background highlighting a drop target ImGuiCol_UnsavedMarker, // Unsaved Document marker (in window title and tabs) ImGuiCol_NavCursor, // Color of keyboard/gamepad navigation cursor/rectangle, when visible ImGuiCol_NavWindowingHighlight, // Highlight window when using CTRL+TAB @@ -2322,6 +2323,9 @@ struct ImGuiStyle bool AntiAliasedFill; // Enable anti-aliased edges around filled shapes (rounded rectangles, circles, etc.). Disable if you are really tight on CPU/GPU. Latched at the beginning of the frame (copied to ImDrawList). float CurveTessellationTol; // Tessellation tolerance when using PathBezierCurveTo() without a specific number of segments. Decrease for highly tessellated curves (higher quality, more polygons), increase to reduce quality. float CircleTessellationMaxError; // Maximum error (in pixels) allowed when using AddCircle()/AddCircleFilled() or drawing rounded corner rectangles with no explicit segment count specified. Decrease for higher quality but more geometry. + float DragDropTargetRectRounding; // Corner radius of the drag-drop target rect + float DragDropTargetRectLineThickness; // Thickness of the drop-drop target rect lines + float DragDropTargetRectExpansionSize; // The size in which the drag-drop target rect will expand over the target // Colors ImVec4 Colors[ImGuiCol_COUNT]; diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 9e6babf78..54d72f410 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -240,6 +240,7 @@ void ImGui::StyleColorsDark(ImGuiStyle* dst) colors[ImGuiCol_TextSelectedBg] = ImVec4(0.26f, 0.59f, 0.98f, 0.35f); colors[ImGuiCol_TreeLines] = colors[ImGuiCol_Border]; colors[ImGuiCol_DragDropTarget] = ImVec4(1.00f, 1.00f, 0.00f, 0.90f); + colors[ImGuiCol_DragDropTargetBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); colors[ImGuiCol_UnsavedMarker] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f); colors[ImGuiCol_NavCursor] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f); colors[ImGuiCol_NavWindowingHighlight] = ImVec4(1.00f, 1.00f, 1.00f, 0.70f); @@ -306,6 +307,7 @@ void ImGui::StyleColorsClassic(ImGuiStyle* dst) colors[ImGuiCol_TextSelectedBg] = ImVec4(0.00f, 0.00f, 1.00f, 0.35f); colors[ImGuiCol_TreeLines] = colors[ImGuiCol_Border]; colors[ImGuiCol_DragDropTarget] = ImVec4(1.00f, 1.00f, 0.00f, 0.90f); + colors[ImGuiCol_DragDropTargetBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); colors[ImGuiCol_UnsavedMarker] = ImVec4(0.90f, 0.90f, 0.90f, 1.00f); colors[ImGuiCol_NavCursor] = colors[ImGuiCol_HeaderHovered]; colors[ImGuiCol_NavWindowingHighlight] = ImVec4(1.00f, 1.00f, 1.00f, 0.70f); @@ -373,6 +375,7 @@ void ImGui::StyleColorsLight(ImGuiStyle* dst) colors[ImGuiCol_TextSelectedBg] = ImVec4(0.26f, 0.59f, 0.98f, 0.35f); colors[ImGuiCol_TreeLines] = colors[ImGuiCol_Border]; colors[ImGuiCol_DragDropTarget] = ImVec4(0.26f, 0.59f, 0.98f, 0.95f); + colors[ImGuiCol_DragDropTargetBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); colors[ImGuiCol_UnsavedMarker] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f); colors[ImGuiCol_NavCursor] = colors[ImGuiCol_HeaderHovered]; colors[ImGuiCol_NavWindowingHighlight] = ImVec4(0.70f, 0.70f, 0.70f, 0.70f);