refactor(theme): extract ChildBgAlpha threshold logic to testable helper (F1.2)
HellionStyle.PushGlobal had two lines that resolved the child-bg alpha based on window opacity. Moves the 0.999f threshold and the alpha-mask into HellionStyleHelpers.ResolveChildBgAlpha so the logic is reachable from the build suite without touching the ImGui surface.
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user