-
-
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
Accessing IDs in different states, and passing an explicit ID into ImageButton() #1390
Comments
Linking to #331 I agree |
One possible solution to solve it, is to create an API that allows P.S. Some time ago I posted a possible implementation here: #1096, but I've not tested it much, to be honest. So I think it would be better to rewrite it from scratch. |
Closing this for now, as this issue seems duplicate of two separate issues:
In the test_engine repository we're using a function
|
Would it be possible to provide an example of how to use this |
FYI the old For reference: #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
// Legacy API obsoleted in 1.89. Two differences with new ImageButton()
// - old ImageButton() used ImTextureId as item id (created issue with multiple buttons with same image, transient texture id values, opaque computation of ID)
// - new ImageButton() requires an explicit 'const char* str_id'
// - old ImageButton() had frame_padding' override argument.
// - new ImageButton() always use style.FramePadding.
bool ImGui::ImageButton(ImTextureID user_texture_id, const ImVec2& size, const ImVec2& uv0, const ImVec2& uv1, int frame_padding, const ImVec4& bg_col, const ImVec4& tint_col)
{
// Default to using texture ID as ID. User can still push string/integer prefixes.
PushID((void*)(intptr_t)user_texture_id);
if (frame_padding >= 0)
PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2((float)frame_padding, (float)frame_padding));
bool ret = ImageButton("", user_texture_id, size, uv0, uv1, bg_col, tint_col);
if (frame_padding >= 0)
PopStyleVar();
PopID();
return ret;
}
#endif // #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS |
Also #74, #96, #480, #501, #647, #654, #719, #843, #894, #1057, #1173, #1390, #1414, #1556, #1768, #2041, #2116, #2330, #2475, #2562, #2667, #2807, #2885, #3102, #3375, #3526, #3964, #4008, #4070, #4158, #4172, #4199, #4375, #4395, #4471, #4548, #4612, #4631, #4657, #4796, #5210, #5303, #5360, #5393, #5533, #5692, #5707, #5729, #5773, #5787, #5884, #6046, #6093, #6186, #6223, #6364, #6387, #6567, #6692, #6724, #6939, #6984, #7246, #7270, #7375, #7421, #7434, #7472, #7581, #7724, #7926, #7937 and probably more.. Tagging to increase visibility!
I have four ImageButtons(), and they popup a Modal popup when clicked.
It is possible for two or more four ImageButton()'s to share the same image.
Because the imageID is used as their ID, if they share the same image then they can't be clicked.
So I wrap them in a PushID() unique to each button.
But because they are now in an inner PushID(), they can't call the popup modal by ID, because it's in a different ID stack-frame.
My solution is to wrap them, but call outside of them:
ImGuiID backgroundSelectionPopup = ImGui::GetCurrentContext()->CurrentWindow->GetID(BackgroundSelectionPopup);
I then, in the inner PushID() stack-frame, call
ImGui::OpenPopupEx(backgroundSelectionPopup, false);
myself when the buttons are clicked.This works fine, but feels hackish. Works fine for me in the present, though, so no complaints #here.
I think I read that you are already considering how to make IDs callable from different stack-frames, so I'm just presenting my scenario as a real-world use-case. I would also suggest making an overload of ImageButton() that takes an explicit ID.
The text was updated successfully, but these errors were encountered: