Skip to content

Some ImGui::Button not detecting click #6093

@luis605

Description

@luis605

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions