diff --git a/HellionChat/Ui/HellionStyle.cs b/HellionChat/Ui/HellionStyle.cs index 4d0774a..96a6b7f 100644 --- a/HellionChat/Ui/HellionStyle.cs +++ b/HellionChat/Ui/HellionStyle.cs @@ -43,13 +43,10 @@ internal static class HellionStyle var alphaByte = (uint)Math.Clamp((int)(windowOpacity * 255f), 0x55, 0xFF); var windowBgWithAlpha = (c.WindowBg & 0xFFFFFF00u) | alphaByte; - // ChildBg alpha: child areas rendered inside ChatLogWindow would - // multiply their alpha with WindowBg, making 50% opacity appear - // ~75% solid. At full opacity the theme's alpha is preserved; below - // it ChildBg goes fully transparent so only WindowBg sets the final - // coverage. - var childBgAlpha = windowOpacity >= 0.999f ? (c.ChildBg & 0xFFu) : 0u; - var childBgWithAlpha = (c.ChildBg & 0xFFFFFF00u) | childBgAlpha; + // ChildBg alpha resolution lives in HellionStyleHelpers so the + // threshold logic can be covered by a pure-helper test in the + // build suite. + var childBgWithAlpha = HellionStyleHelpers.ResolveChildBgAlpha(c.ChildBg, windowOpacity); // Layout stack.PushStyleVar(ImGuiStyleVar.WindowRounding, l.WindowRounding); diff --git a/HellionChat/Ui/HellionStyleHelpers.cs b/HellionChat/Ui/HellionStyleHelpers.cs new file mode 100644 index 0000000..d257681 --- /dev/null +++ b/HellionChat/Ui/HellionStyleHelpers.cs @@ -0,0 +1,17 @@ +namespace HellionChat.Ui; + +internal static class HellionStyleHelpers +{ + // Child surfaces are drawn over WindowBg, so at partial window opacity + // the theme's own ChildBg alpha would double-multiply and read too solid. + // Above ~full opacity we preserve the theme alpha; below it we wipe to 0 + // so WindowBg alone carries the coverage. The 0.999f threshold is a + // float-imprecision guard around the user-facing 100% slider value. + // TEST-MIRROR: ../../Hellion Build test/_Helpers/HellionStyleHelpersTests.cs + public static uint ResolveChildBgAlpha(uint themeChildBgRgba, float windowOpacity) + { + var alphaPreserved = windowOpacity >= 0.999f; + var childBgAlpha = alphaPreserved ? (themeChildBgRgba & 0xFFu) : 0u; + return (themeChildBgRgba & 0xFFFFFF00u) | childBgAlpha; + } +}