Function contrast_ratio

Source
pub fn contrast_ratio(
    a: Color,
    b: Color,
    encoding: RgbEncoding,
) -> Result<f64, ThemeError>
Expand description

Symmetric ratio 1..=21 for two opaque colors in the same stated units. Transparent inputs require contrast_on, not an assumed black backdrop.

use ferravex_math::Color;
use ferravex_play::ui::theme::{contrast_ratio, RgbEncoding};
assert_eq!(contrast_ratio(Color::from_hex(0), Color::from_hex(0xffffff),
                         RgbEncoding::Srgb)?, 21.);