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

What is the best place to temporary change ImGuiCol_ModalWindowDimBg ? #7340

Closed
pozemka opened this issue Feb 21, 2024 · 3 comments
Closed

Comments

@pozemka
Copy link

pozemka commented Feb 21, 2024

Version/Branch of Dear ImGui:

v1.90.2 WIP

Back-ends:

imgui_impl_win32.cpp + imgui_impl_opengl3.cpp

Compiler, OS:

Windows 10

Full config/build information:

No response

Details:

Hello I am trying to create modal popup that disable interaction with the rest of the application elements but keep them perfectly visible for preview purposes. My first idea was to use following code:

ImGui::PushStyleColor(ImGuiCol_ModalWindowDimBg, ImVec4(0, 0, 0, 0));
if (ImGui::BeginPopupModal("MyPopup", nullptr) {
    ImGui::Text("Hello");
    if (ImGui::Button("OK")) { 
        ImGui::CloseCurrentPopup(); 
    }
    ImGui::EndPopup();
}
ImGui::PopStyleColor();

But it seems that dimmed background is drawn outside of popup's begin-end and not affected by this PushStyleColor.

If I change color in style globally it does work but I want to other popups to have dimmed background.

ImGuiStyle& style = ImGui::GetStyle();
style.Colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0, 0, 0, 0);

So the question is how to change ImGuiCol_ModalWindowDimBg only for one popup?

Screenshots/Video:

No response

Minimal, Complete and Verifiable Example code:

No response

@ocornut
Copy link
Owner

ocornut commented Feb 21, 2024

Currently those would be rendered in EndFrame().
I think we should record this value at the time of Begin(), the same way we record some color properties for docked window, and use it later.

@pozemka
Copy link
Author

pozemka commented Feb 22, 2024

As a workaround I'm changing the color of this popup by directly changing the style :

    if (ImGui::BeginPopupModal("MyPopup", nullptr) {
        ImGuiStyle& style = ImGui::GetStyle();
        style.Colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.0f, 0.0f, 0.0f, 0.0f);
        ...
        ImGui::EndPopup();
    }

And each frame before NewFrame I'm restoring original color:

ImGuiStyle& style = ImGui::GetStyle();
style.Colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.35f);
ImGui::NewFrame();

It is not elegant but it works.

ocornut added a commit that referenced this issue Feb 22, 2024
…andled by BeginPopupModal(). (#7340)

+ Misc: Added optional alpha multiplier parameter to GetColorU32(ImU32) variant.
@ocornut
Copy link
Owner

ocornut commented Feb 22, 2024

Should now be fixed by 34965cf

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

No branches or pull requests

2 participants