|
@@ -78,6 +78,13 @@ void Button::paint_event(PaintEvent& event)
|
|
}
|
|
}
|
|
|
|
|
|
if (m_icon) {
|
|
if (m_icon) {
|
|
|
|
+ auto solid_color = m_icon->solid_color(60);
|
|
|
|
+ // Note: 4.5 is the minimum recommended constrast 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;
|
|
|
|
+ if (should_invert_icon)
|
|
|
|
+ m_icon->invert();
|
|
if (is_enabled()) {
|
|
if (is_enabled()) {
|
|
if (is_hovered())
|
|
if (is_hovered())
|
|
painter.blit_brightened(icon_location, *m_icon, m_icon->rect());
|
|
painter.blit_brightened(icon_location, *m_icon, m_icon->rect());
|
|
@@ -86,6 +93,8 @@ void Button::paint_event(PaintEvent& event)
|
|
} else {
|
|
} else {
|
|
painter.blit_disabled(icon_location, *m_icon, m_icon->rect(), palette());
|
|
painter.blit_disabled(icon_location, *m_icon, m_icon->rect(), palette());
|
|
}
|
|
}
|
|
|
|
+ if (should_invert_icon)
|
|
|
|
+ m_icon->invert();
|
|
}
|
|
}
|
|
auto& font = is_checked() ? this->font().bold_variant() : this->font();
|
|
auto& font = is_checked() ? this->font().bold_variant() : this->font();
|
|
if (m_icon && !text().is_empty()) {
|
|
if (m_icon && !text().is_empty()) {
|