From 082b19f863d71f838c941596f701292c94d842ce Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 15 May 2023 20:54:50 +0100 Subject: [PATCH] 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. --- src/generic/hyperlinkg.cpp | 8 +++++++- src/msw/hyperlink.cpp | 10 +++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/generic/hyperlinkg.cpp b/src/generic/hyperlinkg.cpp index 191be40579..f583b108e7 100644 --- a/src/generic/hyperlinkg.cpp +++ b/src/generic/hyperlinkg.cpp @@ -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 diff --git a/src/msw/hyperlink.cpp b/src/msw/hyperlink.cpp index 47de3ff9f6..4649b1c97e 100644 --- a/src/msw/hyperlink.cpp +++ b/src/msw/hyperlink.cpp @@ -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;