Add wxSystemAppearance to check for dark mode under macOS

Provide a way to retrieve the name of the current system appearance
(mostly for diagnostic purposes) and check if it uses predominantly dark
colours.

Currently this class has a non-trivial (but still very simple)
implementation under macOS only and simply checks whether the default
text colour is brighter than the default background colour under the
other platforms, but other platform-specific implementations could be
added later.

Also update the drawing sample "system colours" page to show the system
appearance as well.
This commit is contained in:
Vadim Zeitlin
2019-04-16 01:50:41 +02:00
parent d662a2223e
commit 9a9c845289
5 changed files with 174 additions and 0 deletions

View File

@@ -1623,6 +1623,22 @@ void MyCanvas::DrawSystemColours(wxDC& dc)
int lineHeight = textSize.GetHeight();
wxRect r(textSize.GetWidth() + 10, 10, 100, lineHeight);
wxString title = "System colours";
const wxSystemAppearance appearance = wxSystemSettings::GetAppearance();
const wxString appearanceName = appearance.GetName();
if ( !appearanceName.empty() )
title += wxString::Format(" for \"%s\"", appearanceName);
if ( appearance.IsDark() )
title += " (using dark system theme)";
dc.DrawText(title, 10, r.y);
r.y += 2*lineHeight;
dc.DrawText(wxString::Format("Window background is %s",
appearance.IsUsingDarkBackground() ? "dark"
: "light"),
10, r.y);
r.y += 3*lineHeight;
dc.SetPen(*wxTRANSPARENT_PEN);
static const struct {