Use more appropriate colour for wxHyperlinkCtrl in dark mode

The default blue doesn't have enough with the typical dark mode
background, so use a much lighter shade of blue in this case.

The choice of the exact colour to use is pretty arbitrary, but there
doesn't seem any standard value for the link colour in the dark mode.
This commit is contained in:
Vadim Zeitlin 2023-05-15 20:54:50 +01:00
parent cd28031b4d
commit 082b19f863
2 changed files with 16 additions and 2 deletions

View file

@ -34,6 +34,7 @@
#include "wx/menu.h"
#include "wx/log.h"
#include "wx/dataobj.h"
#include "wx/settings.h"
#endif
#include "wx/clipbrd.h"
@ -105,8 +106,13 @@ namespace
wxColour GetLinkColour()
{
// There is a standard link colour appropriate for the default "light" mode,
// see https://html.spec.whatwg.org/multipage/rendering.html#phrasing-content-3
return wxColour(0x00, 0x00, 0xee);
// it doesn't stand out enough in dark mode, so choose "light sky blue"
// colour for the links in dark mode instead (this is a rather arbitrary
// choice, but there doesn't seem to be any standard one).
return wxSystemSettings::SelectLightDark(wxColour(0x00, 0x00, 0xee),
wxColour(0x87, 0xce, 0xfa));
}
} // anonymous namespace

View file

@ -108,6 +108,14 @@ bool wxHyperlinkCtrl::Create(wxWindow *parent,
return false;
}
if ( wxSystemSettings::GetAppearance().IsDark() )
{
// Override the colour used by default by the native control with the
// colour appropriate for the dark mode, as the default one doesn't
// have enough contrast in it.
SetNormalColour(GetClassDefaultAttributes().colFg);
}
ConnectMenuHandlers();
return true;
@ -243,7 +251,7 @@ wxHyperlinkCtrl::GetClassDefaultAttributes(wxWindowVariant variant)
{
auto attrs = wxGenericHyperlinkCtrl::GetClassDefaultAttributes(variant);
if ( HasNativeHyperlinkCtrl() )
if ( HasNativeHyperlinkCtrl() && !wxSystemSettings::GetAppearance().IsDark() )
attrs.colFg = wxSystemSettings::GetColour(wxSYS_COLOUR_HOTLIGHT);
return attrs;