Skip to content
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

Bug with the ID for ImageButton #7270

Closed
VadimBoev opened this issue Jan 28, 2024 · 2 comments
Closed

Bug with the ID for ImageButton #7270

VadimBoev opened this issue Jan 28, 2024 · 2 comments
Labels
label/id and id stack implicit identifiers, pushid(), id stack

Comments

@VadimBoev
Copy link

Version/Branch of Dear ImGui:

Version ImGui v1.89.5 (release)

Back-ends:

custom engine

Compiler, OS:

Windows 10, VS 2022, CLang for compile Android library

Full config/build information:

Screenshot_2024-01-28-23-36-09-284_com dropclub game
Screenshot_2024-01-28-23-36-02-068_com dropclub game

Details:

When two ImageButton (in turn), the second button does not respond to click:

Hello. I ran into the problem that when I use two buttons with image, the second one does not click, and accordingly (if you look at the example) the message was not displayed. I was finding a solution from this topic (#2464), but before that I thought that it should automatically generate an ID inside itself, as ImGui::Button does.
I understand that the generation of the ID in ImGui::Button depends on the 'label' and specifying the ID and so on. However, could it have been done differently for ImageButton to solve the problem? And how reliable is the use of ImGui::PushID(11) in this case, will there be any failures or bugs?

Screenshots/Video:

No response

Minimal, Complete and Verifiable Example code:

// Here's some code anyone can copy and paste to reproduce my issue
ImGui::Begin("ImageButton ID Bug");
if (ImGui::ImageButton(arrow, ImVec2(110, 110)))
{
    Log("button up clicked");
}

if (ImGui::ImageButton(arrow, ImVec2(110, 110), ImVec2(1,1), ImVec2(0,0)))
{
    Log("button down clicked");
}
ImGui::End();

// This solution helped me fix the problem:
ImGui::Begin("ImageButton ID Maybe fix");
if (ImGui::ImageButton(arrow, ImVec2(110, 110)))
{
    Log("button up clicked");
}

ImGui::PushID(11);
if (ImGui::ImageButton(arrow, ImVec2(110, 110), ImVec2(1,1), ImVec2(0,0)))
{
    Log("button down clicked");
}
ImGui::PopID();

ImGui::End();
@ocornut ocornut added the label/id and id stack implicit identifiers, pushid(), id stack label Jan 28, 2024
@ocornut
Copy link
Owner

ocornut commented Jan 28, 2024

You are using the obsolete function signature for ImageButton(), which uses the texture id as a unique identifier.
Use the ImageButton() call that takes an explicit identifier.

@ocornut ocornut closed this as completed Jan 28, 2024
@VadimBoev
Copy link
Author

Thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
label/id and id stack implicit identifiers, pushid(), id stack
Projects
None yet
Development

No branches or pull requests

2 participants