Updated EquationButton contrast fixed dark mode foreground color bugs (#1155)

* Fixed contrast between background and foreground colors in the equation button. Fixed the issue where the text in the equation text box is white when the background is white

* Adjust the foreground color algorithm

* moved the contrast method to utils so that it is resuable

* Moved brushes for the GetContrastColor method to the app.xaml resource dictionary

* Removed the change for the edit box colors, so it can be in a different PR
This commit is contained in:
Stephanie Anderl
2020-05-05 10:20:05 -07:00
committed by GitHub
parent 9817738307
commit 3055a12178
8 changed files with 39 additions and 6 deletions

View File

@@ -24,6 +24,7 @@ using namespace Windows::UI;
using namespace Windows::UI::Core;
using namespace Windows::UI::ViewManagement;
using namespace Windows::UI::Xaml;
using namespace Windows::UI::Xaml::Media;
using namespace Windows::Foundation;
using namespace Windows::Storage;
@@ -302,3 +303,18 @@ bool operator!=(const Color& color1, const Color& color2)
{
return !(color1 == color2);
}
// This method calculates the luminance ratio between White and the given background color.
// The luminance is calculate using the RGB values and does not use the A value.
// White or Black is returned
SolidColorBrush ^ Utils::GetContrastColor(Color backgroundColor)
{
auto luminance = 0.2126 * backgroundColor.R + 0.7152 * backgroundColor.G + 0.0722 * backgroundColor.B;
if ((255 + 0.05) / (luminance + 0.05) >= 2.5)
{
return static_cast<SolidColorBrush ^>(Application::Current->Resources->Lookup(L"WhiteBrush"));
}
return static_cast<SolidColorBrush ^>(Application::Current->Resources->Lookup(L"BlackBrush"));
}

View File

@@ -409,6 +409,7 @@ namespace Utils
Platform::String ^ EscapeHtmlSpecialCharacters(Platform::String ^ originalString, std::shared_ptr<std::vector<wchar_t>> specialCharacters = nullptr);
Windows::UI::Xaml::Media::SolidColorBrush ^ GetContrastColor(Windows::UI::Color backgroundColor);
}
// This goes into the header to define the property, in the public: section of the class