mirror of
https://github.com/microsoft/terminal.git
synced 2025-12-10 18:43:54 -06:00
Force selection FG to black or white depending on BG luminance (#17753)
This commit is contained in:
parent
516ade54cb
commit
1cb3445834
@ -432,8 +432,8 @@ void AtlasEngine::SetSelectionBackground(const COLORREF color) noexcept
|
||||
{
|
||||
auto misc = _api.s.write()->misc.write();
|
||||
misc->selectionColor = selectionColor;
|
||||
// Selection Foreground is based on the default foreground; it is also updated in UpdateDrawingBrushes
|
||||
misc->selectionForeground = 0xff000000 | ColorFix::GetPerceivableColor(misc->foregroundColor, color, 0.5f * 0.5f);
|
||||
// Select a black or white foreground based on the perceptual lightness of the background.
|
||||
misc->selectionForeground = ColorFix::GetLuminosity(selectionColor) < 0.5f ? 0xffffffff : 0xff000000;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -658,10 +658,7 @@ try
|
||||
|
||||
if (textAttributes.GetForeground().IsDefault() && fg != _api.s->misc->foregroundColor)
|
||||
{
|
||||
auto misc = _api.s.write()->misc.write();
|
||||
misc->foregroundColor = fg;
|
||||
// Selection Foreground is based on the default foreground; it is also updated in SetSelectionColor
|
||||
misc->selectionForeground = 0xff000000 | ColorFix::GetPerceivableColor(fg, misc->selectionColor, 0.5f * 0.5f);
|
||||
_api.s.write()->misc.write()->foregroundColor = fg;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -209,4 +209,9 @@ COLORREF ColorFix::GetPerceivableColor(COLORREF color, COLORREF reference, float
|
||||
return linearToColorref(oklab::oklab_to_linear_srgb(colorOklab)) | (color & 0xff000000);
|
||||
}
|
||||
|
||||
float ColorFix::GetLuminosity(COLORREF color) noexcept
|
||||
{
|
||||
return oklab::linear_srgb_to_oklab(colorrefToLinear(color)).l;
|
||||
}
|
||||
|
||||
TIL_FAST_MATH_END
|
||||
|
||||
@ -10,4 +10,5 @@
|
||||
namespace ColorFix
|
||||
{
|
||||
COLORREF GetPerceivableColor(COLORREF color, COLORREF reference, float minSquaredDistance) noexcept;
|
||||
float GetLuminosity(COLORREF color) noexcept;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user