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

Some ImGui::Button not detecting click #6093

Closed
luis605 opened this issue Jan 17, 2023 · 1 comment
Closed

Some ImGui::Button not detecting click #6093

luis605 opened this issue Jan 17, 2023 · 1 comment
Labels
label/id and id stack implicit identifiers, pushid(), id stack

Comments

@luis605
Copy link

luis605 commented Jan 17, 2023

I have 3 buttons created by a for loop and being drawn in a Child. I am facing some problems when clicking in buttons that do not have index 0, in fact they aren't detecting the press. The program should change focus and active variables when I click in some of those 3 buttons and the text " Selected Button is at index: x" should be printed but the button press is only be detecting when I click the first/top button.

int ImGuiListViewEx(std::vector<std::string>& items, int& focus, int& scroll, int& active) {
    ImGui::SetNextWindowSize(ImVec2(400, 200)); // set the container size

    ImVec2 screen = ImGui::GetIO().DisplaySize;
    ImVec2 childSize = ImVec2(.2 * screen.x, .7 * screen.y);
    ImGui::BeginChild("Entities List", childSize, true, ImGuiWindowFlags_HorizontalScrollbar);

    for (int i = 0; i < 3; i++) {
        if (ImGui::Button("Hello World Button", ImVec2(120,40))) {
            std::cout << "Selected Button is at index: " << i << std::endl;
            focus = i;
            active = i;
        }
    }

    ImGui::EndChild();
    return active;
}

If you need some context I will past the full minimal reproducible example here: https://pastebin.com/RnSMftta

@ocornut
Copy link
Owner

ocornut commented Jan 17, 2023

This is covered in the FAQ.

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