iced-rs / iced

A cross-platform GUI library for Rust, inspired by Elm
https://iced.rs
MIT License
22.96k stars 1.06k forks source link

Add stronger guarantee of readability/contrast for palette background/text color pairs #2376

Closed Davidster closed 1 month ago

Davidster commented 1 month ago

If we run the todo example with the SolarizedDark theme, we can see that the text color selected for display on top of a cyan background is white ('All' button):

image

which brutally fails the WCAG contrast guidelines.

This change guarantees that the text color passes the test, and passes the guidelines by selecting black text for the example in question.

hecrj commented 1 month ago

Ended up reverting this because the solution here is just trading some bad cases for others.

The fallback.inverse() case still does not guarantee readability and it is affecting the Light and Dark theme variants, which are the most common.

We need to find a smarter way to generate a readable color.

Davidster commented 1 month ago

Darn, well surely if swapping to the complete other end of the luminance spectrum doesn't fix the contrast then there is no possible way to pass the WCAG test for that particular background color, right? Maybe if neither white nor black passes the test then we could take the one that's closest to passing?

.. and log a warning if no good option was found?

Davidster commented 1 month ago

we could also use the AA contrast ratio (4.5:1) instead of AAA (7:1) as a minimum

hecrj commented 1 month ago

Maybe if neither white nor black passes the test then we could take the one that's closest to passing?

@Davidster Good idea. Did that in https://github.com/iced-rs/iced/commit/72b975ec82660b39f27b6cb015b763caf20e6483 and seems to work well.