Skip to content

ImGui::SetKeyboardFocusHere doesn't highlight selected item #7370

Closed
@Woitek1993

Description

Version/Branch of Dear ImGui:

Version 1.90.0, Branch: docking

Back-ends:

imgui_impl_glfw.cpp + imgui_impl_opengl2.cpp

Compiler, OS:

Windows 10

Full config/build information:

No response

Details:

Hello,
I am trying to make a programmable change of the focus of the keyboard on the item using SetKeyboardFocusHere();; I've noticed that the highlight is not applied while doing so. I would like to get a highlight on this item in the same way as when the down/up navigation keys are pressed. The object in this case does not lose the highlight when the mouse is moved away.

Example code:

    ImGui::Selectable(std::format("Name: \"{0}\"", (t->m_name.c_str()) ? t->m_name.c_str() : "").c_str());
    if (ImGui::IsItemClicked())
    {
        SetKeyboardFocusHere();
    }
    ImGui::Selectable(std::format("Mask Name: \"{0}\"", (t->m_mask_name.c_str()) ? t->m_mask_name.c_str() : "").c_str());
    if (ImGui::IsItemClicked())
    {
        SetKeyboardFocusHere();
    }
    ImGui::Selectable(std::format("Width: {0}", t->m_width).c_str());
    if (ImGui::IsItemClicked())
    {
        SetKeyboardFocusHere();
    }

Screenshots/Video:

Got:
got
Expected:
expected

Minimal, Complete and Verifiable Example code:

No response

Metadata

Assignees

No one assigned

    Labels

    focusnavkeyboard/gamepad navigation

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions