Modals: Temporary changes of ImGuiCol_ModalWindowDimBg are properly handled by BeginPopupModal(). (#7340)

+ Misc: Added optional alpha multiplier parameter to GetColorU32(ImU32) variant.
This commit is contained in:
ocornut
2024-02-22 14:53:33 +01:00
parent 659fb41d0a
commit 34965cf23a
4 changed files with 13 additions and 6 deletions

View File

@ -3047,13 +3047,14 @@ const ImVec4& ImGui::GetStyleColorVec4(ImGuiCol idx)
return style.Colors[idx];
}
ImU32 ImGui::GetColorU32(ImU32 col)
ImU32 ImGui::GetColorU32(ImU32 col, float alpha_mul)
{
ImGuiStyle& style = GImGui->Style;
if (style.Alpha >= 1.0f)
alpha_mul *= style.Alpha;
if (alpha_mul >= 1.0f)
return col;
ImU32 a = (col & IM_COL32_A_MASK) >> IM_COL32_A_SHIFT;
a = (ImU32)(a * style.Alpha); // We don't need to clamp 0..255 because Style.Alpha is in 0..1 range.
a = (ImU32)(a * alpha_mul); // We don't need to clamp 0..255 because alpha is in 0..1 range.
return (col & ~IM_COL32_A_MASK) | (a << IM_COL32_A_SHIFT);
}
@ -5002,7 +5003,7 @@ static void ImGui::RenderDimmedBackgrounds()
{
// Draw dimming behind modal or a begin stack child, whichever comes first in draw order.
ImGuiWindow* dim_behind_window = FindBottomMostVisibleWindowWithinBeginStack(modal_window);
RenderDimmedBackgroundBehindWindow(dim_behind_window, GetColorU32(ImGuiCol_ModalWindowDimBg, g.DimBgRatio));
RenderDimmedBackgroundBehindWindow(dim_behind_window, GetColorU32(modal_window->DC.ModalDimBgColor, g.DimBgRatio));
}
else if (dim_bg_for_window_list)
{
@ -6960,6 +6961,8 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
window->DC.TextWrapPos = -1.0f; // disabled
window->DC.ItemWidthStack.resize(0);
window->DC.TextWrapPosStack.resize(0);
if (flags & ImGuiWindowFlags_Modal)
window->DC.ModalDimBgColor = ColorConvertFloat4ToU32(GetStyleColorVec4(ImGuiCol_ModalWindowDimBg));
if (window->AutoFitFramesX > 0)
window->AutoFitFramesX--;