Trait WcagColorContrast

Source
pub trait WcagColorContrast<T: WcagRelativeLuminance>: WcagRelativeLuminance + Sized
where Srgb: From<T> + From<Self>,
{ // Provided methods fn wcag_contrast_ratio(&self, other: T) -> f64 { ... } fn wcag_level(&self, other: T) -> WcagLevel { ... } fn find_minimum_contrast<Space>( &self, other: T, level: WcagLevel, ) -> Option<Space> where Self: WcagColorContrast<Space>, Space: ColorMix<Self, T> + From<Self> + From<T> + Copy + PartialEq + Debug, Srgb: From<Space>, Hex: From<Space> { ... } }
Expand description

Trait for calculating WCAG specified color contrast between colors.

This trait provides methods to determine how perceptually contrasting two colours are using the WCAG relative luminance calculation in Srgb color space.

Provided Methods§

Source

fn wcag_contrast_ratio(&self, other: T) -> f64

Calculate the contrast ratio between self and other. colors according to WCAG 2.1. Returns a value between 1:1 and 21:1

other must implement Into<Srgb>

Source

fn wcag_level(&self, other: T) -> WcagLevel

Get the WCAG level for the contrast between self and other.

other must implement Into<Srgb>

Source

fn find_minimum_contrast<Space>( &self, other: T, level: WcagLevel, ) -> Option<Space>
where Self: WcagColorContrast<Space>, Space: ColorMix<Self, T> + From<Self> + From<T> + Copy + PartialEq + Debug, Srgb: From<Space>, Hex: From<Space>,

Find the closest color that meets a specific WCAG level against a background.

This function uses ColorMix in the specified Space to find the minimum adjustment needed to meet the contrast requirement - mixing the colour at lower percentages to find the lowest percentage mix that would meet the WcagLevel requirement.

Returns None if it is impossible to find a

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<C: Copy, T: Copy> WcagColorContrast<T> for C
where Srgb: From<C> + From<T>,