Skip to content

Suggestion: do not focus window when the close button is clicked #8683

@achabense

Description

@achabense

Version/Branch of Dear ImGui:

Version 1.91.9

Back-ends:

Any

Compiler, OS:

Any

Full config/build information:

No response

Details:

When users close a window by clicking the close button, if the window is hidden by other windows, it will be brought to the foreground (due to focus) and disappear immediately (due to close), which is not ideal.

Screenshots/Video:

Current behavior (note that Window C will be brought to foreground for one frame due to focus):
Image

Expected behavior (Window C will disappear directly):
Image

The expected behavior can be achieved by adding extra modes to ButtonBehavior (without focusing the window).

See ec6fb8d.

Minimal, Complete and Verifiable Example code:

bool close_button_no_focus = false;

static void example() {
    static bool b = true, c = true;
    const ImGuiWindowFlags flags = ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoSavedSettings;
    if (ImGui::Begin("Window A", 0, flags)) {
        ImGui::Checkbox("Close button: don't focus window", &close_button_no_focus);
        ImGui::Checkbox("Window B", &b);
        ImGui::Checkbox("Window C", &c);

    }
    ImGui::End();
    if (b) {
        ImGui::Begin("Window B", &b, flags);
        ImGui::Text("--- Window B ---");
        ImGui::End();
    }
    if (c) {
        ImGui::Begin("Window C", &c, flags);
        ImGui::Text("--- Window C ---");
        ImGui::End();
    }
}

Metadata

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