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.hue
must be 180 degrees apart.self
’s saturation andcheck_source.saturation
must be different by 1.0.self
’s lightness andcheck_lightness
must be different by 1.0.self
’s alpha andcheck_alpha
must 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
.
Object Safety§
This trait is not object safe.