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

Is modal the only way to keep focus on another window? #8175

Open
sbenedetto opened this issue Nov 22, 2024 · 2 comments
Open

Is modal the only way to keep focus on another window? #8175

sbenedetto opened this issue Nov 22, 2024 · 2 comments

Comments

@sbenedetto
Copy link

Version/Branch of Dear ImGui:

Version 1.XX, Branch: XXX (master/docking/etc.)

Back-ends:

imgui_impl_XXX.cpp + imgui_impl_XXX.cpp

Compiler, OS:

macos

Full config/build information:

No response

Details:

In my application I have a GLFW window on which I draw a main imgui window as big as the GLFW window.

When I first tried to open another floating window from the main window it happened that if I click on the main window, the second window would disappear behind the main one. So I learned about popup and modals but I don't really like them because they grey out everything else.

Is there another way to open a secondary window and to make sure the focus stays on it until the it is closed? Not necessarily preventing the user from interacting with the underlying one, although I'd like to understand if that is also an option without modal/popup.

PS: Opening a "ticket" for asking a simple question adds a lots of friction. Many times I've hold myself back for asking questions. I read why the discord was closed, but I'm wondering if a new system is taking into consideration? The current mechanism adds a lot friction. Maybe is beneficial for @ocornut so that he gets less questions :-) but not so great for new comers.

Screenshots/Video:

No response

Minimal, Complete and Verifiable Example code:

No response

@achabense
Copy link

achabense commented Nov 23, 2024

but I don't really like them because they grey out everything else.

As a workaround, try ImGuiCol_ModalWindowDimBg:

static void test() {
    const char* title = "Alpha";

    if (!ImGui::IsPopupOpen(title)) {
        if (ImGui::IsKeyPressed(ImGuiKey_M, false)) {
            ImGui::OpenPopup(title);
        }
    }

    ImGui::PushStyleColor(ImGuiCol_ModalWindowDimBg, IM_COL32_BLACK_TRANS);
    if (ImGui::BeginPopupModal(title, 0, ImGuiWindowFlags_AlwaysAutoResize)) {
        if (ImGui::Button("Close")) {
            ImGui::CloseCurrentPopup();
        }
        ImGui::EndPopup();
    }
    ImGui::PopStyleColor();
}

image

@sbenedetto
Copy link
Author

Thanks @achabense! This already solves part of my problems.

What about

Is there another way to open a secondary window and to make sure the focus stays on it until the it is closed? Not necessarily preventing the user from interacting with the underlying one, although I'd like to understand if that is also an option without modal/popup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants