Skip to content

How to suppress keyboard Nav changes inside my custom widget? #8516

@idbrii

Description

@idbrii

Version/Branch of Dear ImGui:

Version v1.92.0 WIP, Branch: master

Back-ends:

imgui_impl_win32.cpp

Compiler, OS:

Win11 + VS2022 (also tried VS2017)

Full config/build information:

I have a demo built into example_win32_directx12:
https://github.com/idbrii/cpp-imgui/blob/3c4d304618ca80d51153f2ede09d594cf33a7eea/examples/example_win32_directx12/main.cpp#L272-L283

Details:

How should I handle keyboard navigation within my custom widget?

Short version: I made a find-as-you-type version of ImGui::Combo but when you nav up and down with keyboard, the text input loses focus.

Long version:
I made a version of Combo that has fuzzy filtering. It works great, but doesn't play nice with ImGuiConfigFlags_NavEnableKeyboard. It handles navigating the combo list with IsKeyPressed:

    if (IsKeyPressed(ImGuiKey_UpArrow, true))
    {
        --move_delta;
    }
    else if (IsKeyPressed(ImGuiKey_DownArrow, true))
    {
        ++move_delta;
    }

To prevent the nav focus rectangle from bouncing around, I set g.NavCursorVisible = false, but the widget that's receiving my text inputs still changes. So you can use keyboard nav to activate the combo, type a query, nav up/down, but then you can't edit the query. So it seems that up/down are still changing some input direction id somewhere.

If I comment out ImGuiConfigFlags_NavEnableKeyboard, then I can type a query, nav up/down, and edit the query.

What do I need to do to work correctly with keyboard navigation? I see there's a ImGuiWindowFlags_NoNavInputs, but that's for Begin() and I'm using using BeginCombo().

Screenshots/Video:

I added a label so you can see me toggle ImGuiConfigFlags_NavEnableKeyboard:

            ImGui::Separator();
            ImGui::Value("ConfigFlags", io.ConfigFlags);
            bool has_nav = (io.ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard) != 0;
            ImGui::Checkbox("ConfigFlags has NavEnableKeyboard", &has_nav);

With NavEnableKeyboard I can't continue to type letters into my search:
NavEnableKeyboard

Without NavEnableKeyboard I can continue to type letters into my search:
no NavEnableKeyboard

Minimal, Complete and Verifiable Example code:

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    inputsnavkeyboard/gamepad navigation

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions