Skip to content

Keeping combo open after clicking selectable #7573

Closed
@JerimiahOfficial

Description

Version/Branch of Dear ImGui:

Version 1.90.6, Branch: master

Back-ends:

imgui_impl_win32.cpp + imgui_impl_dx11.cpp

Compiler, OS:

Windows 10 + gcc

Full config/build information:

No response

Details:

My Issue/Question:
I want to create a multi select combo box that doesn't close when selecting an option. I am currently using the example from #1658 and it closes when I selected and option. Is there a way to keep the popup open when clicking the selectable inside of it?

Screenshots/Video:

No response

Minimal, Complete and Verifiable Example code:

const char* items[] = { "AAAA", "BBBB", "CCCC", "DDDD", "EEEE", "FFFF", "GGGG", "HHHH", "IIII", "JJJJ", "KKKK", "LLLLLLL", "MMMM", "OOOOOOO", "PPPP", "QQQQQQQQQQ", "RRR", "SSSS" };
static const char* current_item = NULL;

if (ImGui::BeginCombo("##combo", current_item)) {
    for (int n = 0; n < IM_ARRAYSIZE(items); n++) {
        bool is_selected = (current_item == items[n]);
        
        if (ImGui::Selectable(items[n], is_selected)
            current_item = items[n];
            
        if (is_selected)
            ImGui::SetItemDefaultFocus();
    }
    ImGui::EndCombo();
}

Found solution

Use ImGuiSelectableFlags_DontClosePopups on selectables.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions