|
@@ -80,10 +80,14 @@ void Button::paint_event(PaintEvent& event)
|
|
|
|
|
|
if (m_icon) {
|
|
|
auto solid_color = m_icon->solid_color(60);
|
|
|
- // Note: 4.5 is the minimum recommended contrast ratio for text on the web:
|
|
|
- // (https://developer.mozilla.org/en-US/docs/Web/Accessibility/Understanding_WCAG/Perceivable/Color_contrast)
|
|
|
- // Reusing that threshold here as it seems to work reasonably well.
|
|
|
- bool should_invert_icon = solid_color.has_value() && palette().button().contrast_ratio(*solid_color) < 4.5f;
|
|
|
+ bool should_invert_icon = false;
|
|
|
+ if (solid_color.has_value()) {
|
|
|
+ auto contrast_ratio = palette().button().contrast_ratio(*solid_color);
|
|
|
+ // Note: 4.5 is the minimum recommended contrast ratio for text on the web:
|
|
|
+ // (https://developer.mozilla.org/en-US/docs/Web/Accessibility/Understanding_WCAG/Perceivable/Color_contrast)
|
|
|
+ // Reusing that threshold here as it seems to work reasonably well.
|
|
|
+ should_invert_icon = contrast_ratio < 4.5f && contrast_ratio < palette().button().contrast_ratio(solid_color->inverted());
|
|
|
+ }
|
|
|
if (should_invert_icon)
|
|
|
m_icon->invert();
|
|
|
if (is_enabled()) {
|