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§
Required Methods§
Sourcefn new() -> Self
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());Sourcefn from_tuple(tuple: &Self::Tuple) -> Self
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);fn from_tuple_with_alpha(tuple: &Self::TupleA) -> Self
Sourcefn as_tuple(&self) -> Self::Tuple
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());Sourcefn get_saturation(&self) -> f32
fn get_saturation(&self) -> f32
Returns saturation value of color (0.0..100.00)
Sourcefn get_lightness(&self) -> f32
fn get_lightness(&self) -> f32
Returns lightness value of color (0.0..100.00)
Sourcefn set_saturation(&self, val: f32) -> Self
fn set_saturation(&self, val: f32) -> Self
Sets saturation value of color (0.0..100.00). Returns Color
Sourcefn set_lightness(&self, val: f32) -> Self
fn set_lightness(&self, val: f32) -> Self
Sets lightness value of color (0.0..100.00). Returns Color
fn to_rgb(&self) -> Rgb
fn to_hsl(&self) -> Hsl
Sourcefn to_css_string(&self) -> String
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%)");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
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.