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

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

Closed
fjabad opened this issue Mar 24, 2021 · 2 comments
Labels
label/id and id stack implicit identifiers, pushid(), id stack

Comments

@fjabad
Copy link

fjabad commented Mar 24, 2021

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.");
        }
@fjabad
Copy link
Author

fjabad commented Mar 24, 2021

Oh, I see. Totally my fault.
Maybe the parameter should be called label_id or something along those lines to remind the user that it has two uses? Having a parameter named 'label' hides the second (and very important!) use. I'm sure I'm not the first who reports this issue.

By the way, I love the library. Keep up the good work!

Paco

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

3 participants