-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Image border color modify the behavior of widgets #8238
Comments
sorry my code may not work, but I tried to be as clear as possible |
When you give Maybe just a personal opinion, but I don't like the approach to swap items in a list (or any container for that matter) while working through the list. If you swap an item to the right, it effectively gets its selectable duplicated in this frame, making the item still active in the next slot. The flag The demo code does basically the same, but it is still shaky, as the code comment admits. So shaky in fact, that a slight modification like adding a gap due to a border color breaks it. My suggestion would be to try a slightly different approach. First walk through the entire list, but instead of swapping, just memorize the indices to swap and that a swap needs to be made. Then, when you are done displaying all of the items in the list, perform the swap. This should be more robust since it doesn't introduce any duplicate ids. Yes, it adds a delay of one frame for the list to display properly (there are ways to get around that if you don't mind some extra steps), but this should be no problem since your number and image didn't match for the frame anyway. One approach without a frame delay would be to use invisible buttons in a first step for the entire list, then perform the swap and finally draw the updated list on top, using a draw list. |
Yeah I think it's what happens, but I find it strange since the Image isn't interactable, that's why I report it. But like you said the way I do it isn't really great. |
Non-interactable widgets like texts and images still have to advance the cursor based on their size, otherwise there would be lots of unwanted overlaps everywhere. Since the border is added on top of the given size, the image is bigger than the underlying selectable, advancing the cursor a bit further and introducing an unwanted gap because of that. You could also adjust the size of the selectable to accommodate for the border, but since the border size is an implementation detail, this might unexpectedly break in the future. |
Version/Branch of Dear ImGui:
Version 1.91.1, 1.91.2, 1.91.6
Back-ends:
imgui_impl_opengl3.cpp + imgui_impl_glfw.cpp
Compiler, OS:
Windows 11 + clang
Full config/build information:
No response
Details:
Hello. I wanted to be able to re-organize assets in a window, like the example "Widgets/Drag and Drop/Drag to reorder items (simple)", but with images. I add a bug, which was that multiples swap where donne on a single frame. I search why and I think it come from the border color argument of the Image function.
first clip, you can see the bug, second you can't. The only modification I made was to remove ImGui::GetStyleColorVec4(ImGuiCol_Border) from the call of ImGui::Image()
My code is a mix of asset browser example (to draw an image over a selectable) and reorder items example (for the switch)
Screenshots/Video:
Enregistrement.de.l.ecran.2024-12-17.234603.mp4
Enregistrement.de.l.ecran.2024-12-17.234732.mp4
Minimal, Complete and Verifiable Example code:
The text was updated successfully, but these errors were encountered: