Avoid unreadable text with unfocused selected item

With non-themed MSW renderer, avoid using wxSYS_COLOUR_BTNFACE for unfocused
item selection unless it has sufficient contrast with the text color.
This commit is contained in:
Paul Cornett
2021-12-22 09:23:41 -08:00
parent 4eeae960a3
commit 025b8a447c

View File

@@ -368,7 +368,13 @@ void wxRendererMSWBase::DrawItemSelectionRect(wxWindow *win,
wxColour color(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT));
if ((flags & wxCONTROL_FOCUSED) == 0)
{
color = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE);
// Use wxSYS_COLOUR_BTNFACE for unfocused selection, but only if it
// has enough contrast with wxSYS_COLOUR_HIGHLIGHTTEXT, as otherwise
// the text will be unreadable
const wxColour btnface(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE));
const wxColour highlightText(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT));
if (fabs(btnface.GetLuminance() - highlightText.GetLuminance()) > 0.5)
color = btnface;
}
wxDCBrushChanger setBrush(dc, wxBrush(color));