Skip to content

Style: Basic styling options for DragDrop target rect - #9056

Closed
aaronkirkham wants to merge 1 commit into
ocornut:masterfrom
aaronkirkham:dragdrop-styling
Closed

aaronkirkham wants to merge 1 commit into
ocornut:masterfrom
aaronkirkham:dragdrop-styling

Conversation

@aaronkirkham

Copy link
Copy Markdown
Contributor

Hey,

After using the very limited styling options for the old drag-drop target rect for as long as I can remember - I decided it was time to finally add some semi-useful options so I can achieve the look I wanted.

This PR adds three new style variables and a color. These new variables/color are defaulted to their old, previously hard-coded values so nothing will change visually unless you explicitly change these new options.

Here's a quick look at what is possible, and the code I'm using to achieve it

Before
before

After
after

style->DragDropTargetRectRounding      = style->FrameRounding;
style->DragDropTargetRectExpansionSize = 1.0f;
style->DragDropTargetRectLineThickness = 2.0f;

colors[ImGuiCol_DragDropTarget]   = ImVec4(0.26f, 0.59f, 0.98f, 1.00f);
colors[ImGuiCol_DragDropTargetBg] = ImVec4(0.26f, 0.59f, 0.98f, 0.25f);

Happy to take feedback and make changes on the naming of these variables.

@ocornut ocornut added style drag drop drag and drop labels Nov 5, 2025
ocornut added a commit that referenced this pull request Nov 6, 2025
@ocornut

ocornut commented Nov 6, 2025

Copy link
Copy Markdown
Owner

Thank you for your PR.
I have merged this as 7954d67 + various changes and renaming f45adb9.

@ocornut ocornut closed this Nov 6, 2025
Intrets pushed a commit to Intrets/imgui that referenced this pull request Jan 1, 2026
Intrets pushed a commit to Intrets/imgui that referenced this pull request Jan 1, 2026
@Marcets423

Copy link
Copy Markdown

I appreciate the addition of the style variables. I had made a bit of a hack to get similar results in 1.90, and I can finally get rid of it!
@ocornut do you have any objections to adding these new style variables to the ImGuiStyleVar_ enum? It would be great if the variables could be manipulated with GetStyleVarInfo and PushStyleVar

@ocornut

ocornut commented Apr 27, 2026 •

Copy link
Copy Markdown
Owner

@Marcets423 May I ask if you actually have the need for them to change mid-frame and how/why? The general idea to not spam the enum is to only include stuff which is likely to change mid-frame (vs stuff you would change in your initial style).

@Marcets423

Copy link
Copy Markdown

@ocornut I see your point. We have a wrapper library with a theme serialisation module, and we're building themes using a theme editor that lists the available variables (similar to the Style window). I use GetStyleVarInfo heavily there. It allows us to edit the style in an XML format, so there's no need to recompile.

My immediate need is for a DragDropTargetRectRounding enum, (I've just upgraded from 1.90, so I haven't put the other variables to use yet).
In our current style guide, we use 3 variations of rounding values in our app (small, medium, and large radius), and we have about 6-8 different drop targets. We want the DragDrop rect to match the target widgets' radius, so most use cases would probably be ImGui::PushStyleVar(ImGuiStyleVar_DragDropTargetRounding, style->FrameRounding).

Before this, I was using frameRounding as the radius arg in the rect drawing that was moved to "RenderDragDropTargetRectEx" post v1.90. (Which is probably still the best way to do it in our use case, to be fair, as I don't have to worry about matching DragDropTargetRounding to FrameRounding.) So if you think that it's not ideal to add enums to these variables, then it's not that big of an issue for us. It's mainly me who is trying to reduce our modifications to the library where I can.

@ocornut

ocornut commented Apr 27, 2026

Copy link
Copy Markdown
Owner

I could add the rounding parameter to RenderDragDropTargetRectEx() + add support for a special < 0 value for style.DragDropTargetRounding where RenderDragDropTargetRectForItem() would use style.FramePadding, which seems sensible. What do you think?

ocornut added a commit that referenced this pull request Apr 27, 2026
)

+ readded rounding arg to RenderDragDropTargetRectEx().
@ocornut

ocornut commented Apr 27, 2026

Copy link
Copy Markdown
Owner

I have pushed ab36fba with:

  • added ImGuiStyleVar_DragDropTargetRounding
  • added a float rounding parameter to `RenderDragDropTargetRectEx().

add support for a special < 0 value for style.DragDropTargetRounding where RenderDragDropTargetRectForItem() would use style.FramePadding

I ended up not doing that, as it felt too arbitrary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

drag drop drag and drop style

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

⌂ 换网址