mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-09 18:16:09 +03:00
LibGUI: Invert button icons only when the contrast ratio improves
Fix the algorithm that automatically inverts solid color button icons when placed in similarly colored backgrounds. It was meant for fixing black icons in dark themed buttons. However, there may be situations where the resulting inverted version is actually worse than the original. This change prevents those cases.
This commit is contained in:
parent
0c2dc6be66
commit
bbfafa19b4
Notes:
sideshowbarker
2024-07-17 09:56:24 +09:00
Author: https://github.com/hjalves Commit: https://github.com/SerenityOS/serenity/commit/bbfafa19b4 Pull-request: https://github.com/SerenityOS/serenity/pull/14405 Reviewed-by: https://github.com/MacDue ✅
@ -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()) {
|
||||
|
Loading…
Reference in New Issue
Block a user