-
-
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
Cannot create multiple buttons with same texture? #5533
Comments
We can use PushID to give ID to the button |
I have pushed a refactor in 4a2ae06 Changed signature of ImageButton() function: (#5533, #4471, #2464, #1390)
|
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!
What is the new usage of ImageButton? imgui_demo doesn't seem to be update. What is str_id and what do I need to pass as that argument? For what I understand, ImageButtons with the same texture would have had the same id and they wouldn't be selected correctly, am I right? And I believe that I can pass an empty string if the texture is only used once or if I manually push an ID, correct? |
Hello
I am creating a texture which loads an icon like so
SDL_Texture* Texture = Load("SomePath.png");
I then create two buttons with the same texture
ImGui::ImageButton(Texture, SomeSize);
ImGui::ImageButton(Texture, SomeSize);
When doing this, only the first button works... Isn't the SDL_Texture pointer the id for the image button?
The text was updated successfully, but these errors were encountered: