Skip to content

ListBoxes with the same label concatenate all of their items under the first listbox's scroll #3964

@fjabad

Description

@fjabad

Version/Branch of Dear ImGui:

Version: 1.82
Branch: v1.82

Back-end/Renderer/Compiler/OS

Back-ends: example_glfw_opengl3
Compiler: VS 2019
Operating System: Windows 10

My Issue/Question:

When creating several listboxes with the same label, all the elements (including the selection) appears on the first ListBox. For example, in imgui_demo.cpp, line 709:

const char* items[] = { "Apple", "Banana", "Cherry", "Kiwi", "Mango", "Orange", "Pineapple", "Strawberry", "Watermelon" };
static int item_current = 1;
ImGui::ListBox("listbox", &item_current, items, IM_ARRAYSIZE(items), 4);

just creating a couple of listboxes more:

static int item_current1 = 1;
static int item_current2 = 1;
ImGui::ListBox("listbox", &item_current1, items, IM_ARRAYSIZE(items), 4);
ImGui::ListBox("listbox", &item_current2, items, IM_ARRAYSIZE(items), 4);

results in the provided screenshot (the first listbox has the 27 items, and the other two are empty). Using different item lists does not change the result.

Screenshots/Video

imagen

Standalone, minimal, complete and verifiable example: (see #2261)

Just replace lines 707-715 in imgui_demo.cpp with:

  {
            // Using the _simplified_ one-liner ListBox() api here
            // See "List boxes" section for examples of how to use the more flexible BeginListBox()/EndListBox() api.
            const char* items[] = { "Apple", "Banana", "Cherry", "Kiwi", "Mango", "Orange", "Pineapple", "Strawberry", "Watermelon" };
            static int item_current = 1;

            ImGui::ListBox("listbox", &item_current, items, IM_ARRAYSIZE(items), 4);
            static int item_current1 = 1;
            static int item_current2 = 1;
            ImGui::ListBox("listbox", &item_current1, items, IM_ARRAYSIZE(items), 4);
            ImGui::ListBox("listbox", &item_current2, items, IM_ARRAYSIZE(items), 4);


            ImGui::SameLine(); HelpMarker(
                "Using the simplified one-liner ListBox API here.\nRefer to the \"List boxes\" section below for an explanation of how to use the more flexible and general BeginListBox/EndListBox API.");
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions