pub trait ColorExt: Copy {
// Required methods
fn into_hsla(self) -> Hsla;
fn contrast_between(
self,
check_source: ColorSource,
check_lightness: ZeroToOne,
check_alpha: ZeroToOne,
) -> ZeroToOne;
fn most_contrasting(self, others: &[Self]) -> Self
where Self: Copy;
// Provided methods
fn source(self) -> ColorSource { ... }
fn lightness(self) -> ZeroToOne { ... }
fn lighten_by(self, amount: ZeroToOne) -> Color { ... }
fn darken_by(self, amount: ZeroToOne) -> Color { ... }
}Expand description
Extra functionality added to the Color type from Kludgine.
Required Methods§
Sourcefn into_hsla(self) -> Hsla
fn into_hsla(self) -> Hsla
Converts this color into its hue, saturation, and lightness components.
Sourcefn contrast_between(
self,
check_source: ColorSource,
check_lightness: ZeroToOne,
check_alpha: ZeroToOne,
) -> ZeroToOne
fn contrast_between( self, check_source: ColorSource, check_lightness: ZeroToOne, check_alpha: ZeroToOne, ) -> ZeroToOne
Returns the contrast between this color and the components provided.
To achieve a contrast of 1.0:
self’s hue andcheck_source.huemust be 180 degrees apart.self’s saturation andcheck_source.saturationmust be different by 1.0.self’s lightness andcheck_lightnessmust be different by 1.0.self’s alpha andcheck_alphamust be different by 1.0.
The algorithm currently used is purposely left undocumented as it will likely change. It should be a reasonable heuristic until someone smarter than @ecton comes along.
Sourcefn most_contrasting(self, others: &[Self]) -> Selfwhere
Self: Copy,
fn most_contrasting(self, others: &[Self]) -> Selfwhere
Self: Copy,
Returns the color in others that contrasts the most from self.
Provided Methods§
Sourcefn source(self) -> ColorSource
fn source(self) -> ColorSource
Returns the hue and saturation of this color.
Sourcefn lighten_by(self, amount: ZeroToOne) -> Color
fn lighten_by(self, amount: ZeroToOne) -> Color
Returns this color lightened by amount.
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.