cushy::styles

Trait ColorExt

Source
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§

Source

fn into_hsla(self) -> Hsla

Converts this color into its hue, saturation, and lightness components.

Source

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 and check_source.hue must be 180 degrees apart.
  • self’s saturation and check_source.saturation must be different by 1.0.
  • self’s lightness and check_lightness must be different by 1.0.
  • self’s alpha and check_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.

Source

fn most_contrasting(self, others: &[Self]) -> Self
where Self: Copy,

Returns the color in others that contrasts the most from self.

Provided Methods§

Source

fn source(self) -> ColorSource

Returns the hue and saturation of this color.

Source

fn lightness(self) -> ZeroToOne

Returns the perceived lightness of this color.

Source

fn lighten_by(self, amount: ZeroToOne) -> Color

Returns this color lightened by amount.

Source

fn darken_by(self, amount: ZeroToOne) -> Color

Returns this color darkened 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.

Implementors§