Skip to content

Commit f45adb9

Browse files
committed
Drag and Drop, Style: added basic styling options to DragDrop target rect. Amends. (#9056)
1 parent 7954d67 commit f45adb9

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

docs/CHANGELOG.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ Other Changes:
7676
triggered by some widgets e.g. Checkbox(), Selectable() and many others, which
7777
cleared ActiveId at the same time as editing. (#9028)
7878
Note that IsItemDeactivatedAfterEdit() was not affected, only IsItemEdited).
79+
- Style, Drag and Drop: added ImGuiCol_DragDropTargetBg, style.DragDropTargetRounding,
80+
style.DragDropTargetBorderSize and style.DragDropTargetPadding to configure
81+
the drop target highlight. (#9056) [@aaronkirkham]
7982
- Demo: About Box: emit infos to convey when IM_ASSERT() macro is disabled,
8083
- so users don't miss out on programming errors being reported.
8184
- so it is included in config/build info submitted in new GitHub Issues.

imgui.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1436,6 +1436,9 @@ ImGuiStyle::ImGuiStyle()
14361436
TreeLinesFlags = ImGuiTreeNodeFlags_DrawLinesNone;
14371437
TreeLinesSize = 1.0f; // Thickness of outlines when using ImGuiTreeNodeFlags_DrawLines.
14381438
TreeLinesRounding = 0.0f; // Radius of lines connecting child nodes to the vertical line.
1439+
DragDropTargetRounding = 0.0f; // Radius of the drag and drop target frame.
1440+
DragDropTargetBorderSize = 2.0f; // Thickness of the drag and drop target border.
1441+
DragDropTargetPadding = 3.0f; // Size to expand the drag and drop target from actual target item size.
14391442
ColorButtonPosition = ImGuiDir_Right; // Side of the color button in the ColorEdit4 widget (left/right). Defaults to ImGuiDir_Right.
14401443
ButtonTextAlign = ImVec2(0.5f,0.5f);// Alignment of button text when button is larger than text.
14411444
SelectableTextAlign = ImVec2(0.0f,0.0f);// Alignment of selectable text. Defaults to (0.0f, 0.0f) (top-left aligned). It's generally important to keep this left-aligned if you want to lay multiple items on a same line.
@@ -1450,9 +1453,6 @@ ImGuiStyle::ImGuiStyle()
14501453
AntiAliasedFill = true; // Enable anti-aliased filled shapes (rounded rectangles, circles, etc.).
14511454
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.
14521455
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.
1453-
DragDropTargetRectRounding = 0.0f; // Corner radius of the drag-drop hover frame
1454-
DragDropTargetRectLineThickness = 2.0f; // Thickness of the drop-drop hover frame lines
1455-
DragDropTargetRectExpansionSize = 3.5f; // The size in which the drag-drop hover rect will expand over the target
14561456

14571457
// Behaviors
14581458
HoverStationaryDelay = 0.15f; // Delay for IsItemHovered(ImGuiHoveredFlags_Stationary). Time required to consider mouse stationary.
@@ -1503,6 +1503,9 @@ void ImGuiStyle::ScaleAllSizes(float scale_factor)
15031503
TabCloseButtonMinWidthUnselected = (TabCloseButtonMinWidthUnselected > 0.0f && TabCloseButtonMinWidthUnselected != FLT_MAX) ? ImTrunc(TabCloseButtonMinWidthUnselected * scale_factor) : TabCloseButtonMinWidthUnselected;
15041504
TabBarOverlineSize = ImTrunc(TabBarOverlineSize * scale_factor);
15051505
TreeLinesRounding = ImTrunc(TreeLinesRounding * scale_factor);
1506+
DragDropTargetRounding = ImTrunc(DragDropTargetRounding * scale_factor);
1507+
DragDropTargetBorderSize = ImTrunc(DragDropTargetBorderSize * scale_factor);
1508+
DragDropTargetPadding = ImTrunc(DragDropTargetPadding * scale_factor);
15061509
SeparatorTextPadding = ImTrunc(SeparatorTextPadding * scale_factor);
15071510
DisplayWindowPadding = ImTrunc(DisplayWindowPadding * scale_factor);
15081511
DisplaySafeAreaPadding = ImTrunc(DisplaySafeAreaPadding * scale_factor);
@@ -14897,7 +14900,7 @@ void ImGui::RenderDragDropTargetRectForItem(const ImRect& bb)
1489714900
ImGuiWindow* window = g.CurrentWindow;
1489814901
ImRect bb_display = bb;
1489914902
bb_display.ClipWith(g.DragDropTargetClipRect); // Clip THEN expand so we have a way to visualize that target is not entirely visible.
14900-
bb_display.Expand(g.Style.DragDropTargetRectExpansionSize);
14903+
bb_display.Expand(g.Style.DragDropTargetPadding);
1490114904
bool push_clip_rect = !window->ClipRect.Contains(bb_display);
1490214905
if (push_clip_rect)
1490314906
window->DrawList->PushClipRectFullScreen();
@@ -14909,12 +14912,8 @@ void ImGui::RenderDragDropTargetRectForItem(const ImRect& bb)
1490914912
void ImGui::RenderDragDropTargetRectEx(ImDrawList* draw_list, const ImRect& bb)
1491014913
{
1491114914
ImGuiContext& g = *GImGui;
14912-
14913-
const ImVec4& color_bg = GetStyleColorVec4(ImGuiCol_DragDropTargetBg);
14914-
if (color_bg.w > 0.0f)
14915-
draw_list->AddRectFilled(bb.Min, bb.Max, GetColorU32(color_bg), g.Style.DragDropTargetRectRounding, 0);
14916-
14917-
draw_list->AddRect(bb.Min, bb.Max, GetColorU32(ImGuiCol_DragDropTarget), g.Style.DragDropTargetRectRounding, 0, g.Style.DragDropTargetRectLineThickness); // FIXME-DPI
14915+
draw_list->AddRectFilled(bb.Min, bb.Max, GetColorU32(ImGuiCol_DragDropTargetBg), g.Style.DragDropTargetRounding, 0);
14916+
draw_list->AddRect(bb.Min, bb.Max, GetColorU32(ImGuiCol_DragDropTarget), g.Style.DragDropTargetRounding, 0, g.Style.DragDropTargetBorderSize);
1491814917
}
1491914918

1492014919
const ImGuiPayload* ImGui::GetDragDropPayload()

imgui.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2309,6 +2309,9 @@ struct ImGuiStyle
23092309
ImGuiTreeNodeFlags TreeLinesFlags; // Default way to draw lines connecting TreeNode hierarchy. ImGuiTreeNodeFlags_DrawLinesNone or ImGuiTreeNodeFlags_DrawLinesFull or ImGuiTreeNodeFlags_DrawLinesToNodes.
23102310
float TreeLinesSize; // Thickness of outlines when using ImGuiTreeNodeFlags_DrawLines.
23112311
float TreeLinesRounding; // Radius of lines connecting child nodes to the vertical line.
2312+
float DragDropTargetRounding; // Radius of the drag and drop target frame.
2313+
float DragDropTargetBorderSize; // Thickness of the drag and drop target border.
2314+
float DragDropTargetPadding; // Size to expand the drag and drop target from actual target item size.
23122315
ImGuiDir ColorButtonPosition; // Side of the color button in the ColorEdit4 widget (left/right). Defaults to ImGuiDir_Right.
23132316
ImVec2 ButtonTextAlign; // Alignment of button text when button is larger than text. Defaults to (0.5f, 0.5f) (centered).
23142317
ImVec2 SelectableTextAlign; // Alignment of selectable text. Defaults to (0.0f, 0.0f) (top-left aligned). It's generally important to keep this left-aligned if you want to lay multiple items on a same line.
@@ -2323,9 +2326,6 @@ struct ImGuiStyle
23232326
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).
23242327
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.
23252328
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.
2326-
float DragDropTargetRectRounding; // Corner radius of the drag-drop target rect
2327-
float DragDropTargetRectLineThickness; // Thickness of the drop-drop target rect lines
2328-
float DragDropTargetRectExpansionSize; // The size in which the drag-drop target rect will expand over the target
23292329

23302330
// Colors
23312331
ImVec4 Colors[ImGuiCol_COUNT];

0 commit comments

Comments
 (0)