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.

Object Safety§

This trait is not object safe.

Implementors§