Open CobaltXII opened 3 years ago
Hello, Thanks for the report.
That's quite interesting. A few things:
BeginPopupContextItem()
is the id of the popup and doesn't have to be the same as the widget above.BeginPopupContextItem()
by default can be called with no parameter and will use the last item id, as convenience. In your example if you emitted both parameters to BeginPopupContextItem()
it would have the same result.There is indeed an issue with the fact that the Combo popup will share the same ID as the Context Item Popups and they will keep overriding each others.
The immediate/easy workaround is simply to use another ID when caling BeginPopupContextItem()
. This will fix your issue.
However from my POV we are trying to encourage people from not passing an ID override when calling BeginPopupContextItem()
and just use the last item ID, so this is a problem that will need fixing on our end.
Pushed a fix: 029c83c73e724af28cd1cc0714671b0673d95751
Thanks so much for the quick response. Combo boxes work well with the fix. I changed all my code to call BeginPopupContextItem
with no arguments. This works fine for all the widgets I am using except for ColorEdit4
. However, it continues to work fine if I call BeginPopupContextItem
with the ID of the color editor as I was doing before. Here is the code I am using:
ImGui::ColorEdit4(name, &color->x, ImGuiColorEditFlags_Float);
// if (ImGui::BeginPopupContextItem(name)) { <-- this works!
if (ImGui::BeginPopupContextItem()) {
if (ImGui::MenuItem("Reset")) (void*)0;
ImGui::EndPopup();
}
And this is the assertion that is failing:
Assertion failed: (id != 0), function BeginPopupContextItem, file lib/imgui/imgui.cpp, line 7931.
I will open a separate issue for this if you want. Thanks in advance.
Thanks! I'll look at this from pov of view of ColorEdit later (it uses a group + popup so may be different)
All widgets using groups such as SliderFloat3()
, ColorEdit4()
will have the same issue.
What I would do right now is to use
if (ImGui::BeginPopupContextItem("Context")) { }
Or if you have multiple of them in same id stack level:
if (ImGui::BeginPopupContextItem("mywidget##context")) {}
The fix is not presently trivial, relates to #840, #2840, #2550, #1875
I think we may have to investigate the idea presented in #840 (which would mean that last item id would change when activating a sub-component, may be fine).
Version/Branch of Dear ImGui:
Version: dear imgui, v1.79 WIP Branch: master
Back-end/Renderer/Compiler/OS
Back-ends: imgui_impl_opengl3.cpp + imgui_impl_sdl2.cpp Operating System: macOS
My Issue/Question:
Context menus don't work on combo boxes but they work on other widgets. In the following code, if I right-click on
Combo
, all of ImGui freezes (but not the program itself). If I right-click onSlider
, it works fine.Standalone, minimal, complete and verifiable example: