Color

Trait Color 

Source
pub trait Color {
    type Tuple;
    type TupleA;

Show 24 methods // Required methods fn new() -> Self; fn from_tuple(tuple: &Self::Tuple) -> Self; fn from_tuple_with_alpha(tuple: &Self::TupleA) -> Self; fn as_tuple(&self) -> Self::Tuple; fn get_red(&self) -> f32; fn get_green(&self) -> f32; fn get_blue(&self) -> f32; fn set_red(&self, val: f32) -> Self; fn set_green(&self, val: f32) -> Self; fn set_blue(&self, val: f32) -> Self; fn get_hue(&self) -> f32; fn get_saturation(&self) -> f32; fn get_lightness(&self) -> f32; fn set_hue(&self, val: f32) -> Self; fn set_saturation(&self, val: f32) -> Self; fn set_lightness(&self, val: f32) -> Self; fn to_rgb(&self) -> Rgb; fn to_hsl(&self) -> Hsl; fn to_css_string(&self) -> String; fn adjust_hue(&self, amt: f32) -> Self; fn saturate(&self, amt: f32) -> Self; fn lighten(&self, amt: f32) -> Self; fn adjust_color(&self, col_name: RgbUnit, val: f32) -> Self; fn invert(&self) -> Self;
}
Expand description

Common to all trait

Required Associated Types§

Source

type Tuple

ColorTuple or ColorTupleA.

Source

type TupleA

Required Methods§

Source

fn new() -> Self

Creates a black color

§Example
use colors_transform::{Rgb,Color};

let black = Rgb::from(0.0,0.0,0.0);
assert_eq!(black, Rgb::new());
Source

fn from_tuple(tuple: &Self::Tuple) -> Self

Creates a color from tuple.

§Example
use colors_transform::{Rgb,Hsl,Color};

let rgb = Rgb::from_tuple(&(10.0,11.0,12.0));
let hsl = Hsl::from(310.0,50.0,50.0);
Source

fn from_tuple_with_alpha(tuple: &Self::TupleA) -> Self

Source

fn as_tuple(&self) -> Self::Tuple

Returns tuple representation of color

§Example
use colors_transform::{Hsl,Color};
let hsl_tuple = (10.0,11.0,12.0);
let hsl = Hsl::from_tuple(&hsl_tuple);
assert_eq!(hsl_tuple,hsl.as_tuple());
Source

fn get_red(&self) -> f32

Returns red value of color (0.0..255.00)

Source

fn get_green(&self) -> f32

Returns green value of color (0.0..255.00)

Source

fn get_blue(&self) -> f32

Returns blue value of color (0.0..255.00)

Source

fn set_red(&self, val: f32) -> Self

Sets red value of color (0.0..255.00). Returns Color

Source

fn set_green(&self, val: f32) -> Self

Sets green value of color (0.0..255.00). Returns Color

Source

fn set_blue(&self, val: f32) -> Self

Sets blue value of color (0.0..255.00). Returns Color

Source

fn get_hue(&self) -> f32

Returns hue value of color (0.0..359.00)

Source

fn get_saturation(&self) -> f32

Returns saturation value of color (0.0..100.00)

Source

fn get_lightness(&self) -> f32

Returns lightness value of color (0.0..100.00)

Source

fn set_hue(&self, val: f32) -> Self

Sets hue value of color (0.0..359.00). Returns Color

Source

fn set_saturation(&self, val: f32) -> Self

Sets saturation value of color (0.0..100.00). Returns Color

Source

fn set_lightness(&self, val: f32) -> Self

Sets lightness value of color (0.0..100.00). Returns Color

Source

fn to_rgb(&self) -> Rgb

Source

fn to_hsl(&self) -> Hsl

Source

fn to_css_string(&self) -> String

Returns css string

§Example
use colors_transform::{Hsl,Color};

let hsl = Hsl::from_tuple(&(301.0,27.0,91.0));
assert_eq!(hsl.to_css_string(), "hsl(301,27%,91%)");
Source

fn adjust_hue(&self, amt: f32) -> Self

Source

fn saturate(&self, amt: f32) -> Self

Source

fn lighten(&self, amt: f32) -> Self

Source

fn adjust_color(&self, col_name: RgbUnit, val: f32) -> Self

Source

fn invert(&self) -> Self

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§