ocornut / imgui

Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies
MIT License
59.73k stars 10.17k forks source link

Is it possible to don't pass focus to window on click? #5566

Open DimaKoltun opened 2 years ago

DimaKoltun commented 2 years ago

Version/Branch of Dear ImGui:

Version: 1.88 Branch: docking

Back-end/Renderer/Compiler/OS

Back-ends: imgui_impl_sdl.cpp + imgui_implopengl3.cpp (or specify if using a custom engine/back-end) Compiler: XXX (if the question is related to building or platform specific features)_ Operating System: Windows

My Issue/Question:

Is it possible to don't pass focus to another window on click? I have a file browser with a toolbar, but I don't want to transfer focus to the toolbar by clicking on it, or on any of its children. Files should have "main" focus to make navigation by keyboard work, and if i press on toolbar buttons or empty space on toolbar, i don't want to lose focus from file panel, is it possible somehow to do it?

image

Standalone, minimal, complete and verifiable example: (see https://github.com/ocornut/imgui/issues/2261)

        ImGui::Begin("##Window", nullptr);

        if (ImGui::BeginChild("##toolbar", ImVec2(500.f, 35.f), true, ImGuiWindowFlags_NoNav))
        {
            ImGui::Button("back");
            ImGui::SameLine();
            ImGui::Button("forward");

            ImGui::EndChild();
        }

        if (ImGui::BeginChild("##FilesPanel", ImVec2(500.f, 50.f), true))
        {
            for (int i = 0; i < 5; i++)
            {
                if (i != 0)
                {
                    ImGui::SameLine();
                }

                std::string folderName = "Folder " + std::to_string(i);
                ImGui::Button(folderName.c_str());
            }

            ImGui::EndChild();
        }

        ImGui::End();
ocornut commented 2 years ago

It's currently not possible, you'd have to restore focus to the other window yourself.