Struct pix_engine::color::Color
source · pub struct Color { /* private fields */ }
Expand description
A color represented with a Mode.
Implementations§
source§impl Color
impl Color
pub const ALICE_BLUE: Self = _
pub const ANTIQUE_WHITE: Self = _
pub const AQUA: Self = _
pub const AQUA_MARINE: Self = _
pub const AZURE: Self = _
pub const BEIGE: Self = _
pub const BISQUE: Self = _
pub const BLACK: Self = _
pub const BLANCHE_DALMOND: Self = _
pub const BLUE: Self = _
pub const BLUE_VIOLET: Self = _
pub const BROWN: Self = _
pub const BURLY_WOOD: Self = _
pub const CADET_BLUE: Self = _
pub const CHARTREUSE: Self = _
pub const CHOCOLATE: Self = _
pub const CORAL: Self = _
pub const CORNFLOWER_BLUE: Self = _
pub const CORN_SILK: Self = _
pub const CRIMSON: Self = _
pub const CYAN: Self = _
pub const DARK_BLUE: Self = _
pub const DARK_CYAN: Self = _
pub const DARK_GOLDENROD: Self = _
pub const DARK_GRAY: Self = _
pub const DARK_GREEN: Self = _
pub const DARK_GREY: Self = _
pub const DARK_KHAKI: Self = _
pub const DARK_MAGENTA: Self = _
pub const DARK_OLIVE_GREEN: Self = _
pub const DARK_ORANGE: Self = _
pub const DARK_ORCHID: Self = _
pub const DARK_RED: Self = _
pub const DARK_SALMON: Self = _
pub const DARK_SEA_GREEN: Self = _
pub const DARK_SLATE_BLUE: Self = _
pub const DARK_SLATE_GRAY: Self = _
pub const DARK_SLATE_GREY: Self = _
pub const DARK_TURQUOISE: Self = _
pub const DARK_VIOLET: Self = _
pub const DEEP_PINK: Self = _
pub const DEEP_SKY_BLUE: Self = _
pub const DIM_GRAY: Self = _
pub const DIM_GREY: Self = _
pub const DODGER_BLUE: Self = _
pub const FIRE_BRICK: Self = _
pub const FLORAL_WHITE: Self = _
pub const FOREST_GREEN: Self = _
pub const FUCHSIA: Self = _
pub const GAINSBORO: Self = _
pub const GHOST_WHITE: Self = _
pub const GOLD: Self = _
pub const GOLDENROD: Self = _
pub const GRAY: Self = _
pub const GREEN: Self = _
pub const GREEN_YELLOW: Self = _
pub const GREY: Self = _
pub const HONEYDEW: Self = _
pub const HOTOINK: Self = _
pub const INDIAN_RED: Self = _
pub const INDIGO: Self = _
pub const IVORY: Self = _
pub const KHAKI: Self = _
pub const LAVENDER: Self = _
pub const LAVENDER_BLUSH: Self = _
pub const LAWN_GREEN: Self = _
pub const LEMON_CHIFFON: Self = _
pub const LIGHT_BLUE: Self = _
pub const LIGHT_CORAL: Self = _
pub const LIGHT_CYAN: Self = _
pub const LIGHT_GOLDENROD_YELLOW: Self = _
pub const LIGHT_GRAY: Self = _
pub const LIGHT_GREEN: Self = _
pub const LIGHT_GREY: Self = _
pub const LIGHT_PINK: Self = _
pub const LIGHT_SALMON: Self = _
pub const LIGHT_SEA_GREEN: Self = _
pub const LIGHT_SKY_BLUE: Self = _
pub const LIGHT_SLATE_GRAY: Self = _
pub const LIGHT_SLATE_GREY: Self = _
pub const LIGHT_STEEL_BLUE: Self = _
pub const LIGHT_YELLOW: Self = _
pub const LIME: Self = _
pub const LIME_GREEN: Self = _
pub const LINEN: Self = _
pub const MAGENTA: Self = _
pub const MAROON: Self = _
pub const MEDIUMAQUA_MARINE: Self = _
pub const MEDIUM_BLUE: Self = _
pub const MEDIUM_ORCHID: Self = _
pub const MEDIUM_PURPLE: Self = _
pub const MEDIUM_SEA_GREEN: Self = _
pub const MEDIUM_SLATE_BLUE: Self = _
pub const MEDIUM_SPRING_GREEN: Self = _
pub const MEDIUM_TURQUOISE: Self = _
pub const MEDIUM_VIOLET_RED: Self = _
pub const MIDNIGHT_BLUE: Self = _
pub const MINT_CREAM: Self = _
pub const MISTY_ROSE: Self = _
pub const MOCCASIN: Self = _
pub const NAVAJO_WHITE: Self = _
pub const NAVY: Self = _
pub const OLD_LACE: Self = _
pub const OLIVE: Self = _
pub const OLIVE_DRAB: Self = _
pub const ORANGE: Self = _
pub const ORANGE_RED: Self = _
pub const ORCHID: Self = _
pub const PALE_GOLDENROD: Self = _
pub const PALE_GREEN: Self = _
pub const PALE_TURQUOISE: Self = _
pub const PALE_VIOLET_RED: Self = _
pub const PAPAYA_WHIP: Self = _
pub const PEACH_PUFF: Self = _
pub const PERU: Self = _
pub const PINK: Self = _
pub const PLUM: Self = _
pub const POWDER_BLUE: Self = _
pub const PURPLE: Self = _
pub const REBECCA_PURPLE: Self = _
pub const RED: Self = _
pub const ROSY_BROWN: Self = _
pub const ROYAL_BLUE: Self = _
pub const SADDLE_BROWN: Self = _
pub const SALMON: Self = _
pub const SANDY_BROWN: Self = _
pub const SEA_GREEN: Self = _
pub const SEA_SHELL: Self = _
pub const SIENNA: Self = _
pub const SILVER: Self = _
pub const SKY_BLUE: Self = _
pub const SLATE_BLUE: Self = _
pub const SLATE_GRAY: Self = _
pub const SLATE_GREY: Self = _
pub const SNOW: Self = _
pub const SPRING_GREEN: Self = _
pub const STEEL_BLUE: Self = _
pub const TAN: Self = _
pub const TEAL: Self = _
pub const THISTLE: Self = _
pub const TOMATO: Self = _
pub const TRANSPARENT: Self = _
pub const TURQUOISE: Self = _
pub const VIOLET: Self = _
pub const WHEAT: Self = _
pub const WHITE: Self = _
pub const WHITE_SMOKE: Self = _
pub const YELLOW: Self = _
pub const YELLOW_GREEN: Self = _
source§impl Color
impl Color
sourcepub fn from_slice<T, S>(mode: ColorMode, slice: S) -> PixResult<Self>
pub fn from_slice<T, S>(mode: ColorMode, slice: S) -> PixResult<Self>
Constructs a Color
from a slice of 1-4 values. The number of values
provided alter how they are interpreted similar to the color!, rgb!, hsb!, and
hsl! macros.
Errors
If the slice is empty or has more than 4 values, an error is returned.
Examples
let vals: Vec<f64> = vec![128.0, 64.0, 0.0];
let c = Color::from_slice(ColorMode::Rgb, &vals)?; // RGB Vec
assert_eq!(c.channels(), [128, 64, 0, 255]);
let vals: [f64; 4] = [128.0, 64.0, 0.0, 128.0];
let c = Color::from_slice(ColorMode::Rgb, &vals[..])?; // RGBA slice
assert_eq!(c.channels(), [128, 64, 0, 128]);
sourcepub const fn from_hex_alpha(hex: u32) -> Self
pub const fn from_hex_alpha(hex: u32) -> Self
sourcepub const fn inverted(&self) -> Self
pub const fn inverted(&self) -> Self
Constructs a Color
by inverting the RGBA values.
Example
let c = Color::from_hex(0xF0FF00);
assert_eq!(c.inverted().as_hex(), 0x0F00FF);
sourcepub fn blended<A>(&self, bg: Color, alpha: A) -> Self
pub fn blended<A>(&self, bg: Color, alpha: A) -> Self
Constructs an opaque Color
blended over a given background, using an alpha value.
sourcepub fn lerp<A>(&self, other: Color, amt: A) -> Self
pub fn lerp<A>(&self, other: Color, amt: A) -> Self
Constructs a Color
by linear interpolating between two Color
s by a given amount between
0.0
and 1.0
.
Examples
let from = rgb!(255, 0, 0);
let to = rgb!(0, 100, 255);
let lerped = from.lerp(to, 0.5);
assert_eq!(lerped.channels(), [128, 50, 128, 255]);
let from = rgb!(255, 0, 0);
let to = hsb!(120.0, 80.0, 100.0, 0.5);
let lerped = from.lerp(to, 0.25); // `to` is implicity converted to RGB
assert_eq!(lerped.channels(), [204, 64, 13, 223]);
source§impl Color
impl Color
sourcepub const fn new(r: u8, g: u8, b: u8) -> Self
pub const fn new(r: u8, g: u8, b: u8) -> Self
Constructs a Color
with red
, green
, blue
and max alpha
.
Example
let c = Color::new(0, 0, 128);
assert_eq!(c.channels(), [0, 0, 128, 255]);
sourcepub const fn new_alpha(r: u8, g: u8, b: u8, a: u8) -> Self
pub const fn new_alpha(r: u8, g: u8, b: u8, a: u8) -> Self
Constructs a Color
with red
, green
, blue
and alpha
.
Example
let c = Color::new_alpha(0, 0, 128, 50);
assert_eq!(c.channels(), [0, 0, 128, 50]);
sourcepub fn with_mode_alpha<T: Into<f64>>(
mode: Mode,
v1: T,
v2: T,
v3: T,
alpha: T
) -> Self
pub fn with_mode_alpha<T: Into<f64>>( mode: Mode, v1: T, v2: T, v3: T, alpha: T ) -> Self
sourcepub const fn rgb(r: u8, g: u8, b: u8) -> Self
pub const fn rgb(r: u8, g: u8, b: u8) -> Self
Constructs a Color
with red
, green
, blue
and max alpha
.
Alias for Color::new.
Example
let c = Color::rgb(128, 64, 0);
assert_eq!(c.channels(), [128, 64, 0, 255]);
sourcepub const fn rgba(r: u8, g: u8, b: u8, a: u8) -> Self
pub const fn rgba(r: u8, g: u8, b: u8, a: u8) -> Self
Constructs a Color
with red
, green
, blue
and alpha
.
Alias for Color::new_alpha.
Example
let c = Color::rgba(128, 64, 128, 128);
assert_eq!(c.channels(), [128, 64, 128, 128]);
sourcepub fn hsb<T: Into<f64>>(h: T, s: T, b: T) -> Self
pub fn hsb<T: Into<f64>>(h: T, s: T, b: T) -> Self
Constructs a Color
with hue
, saturation
, brightness
and max alpha
.
Example
let c = Color::hsb(126.0, 80.0, 50.0);
assert_eq!(c.channels(), [25, 128, 36, 255]);
sourcepub fn hsba<T: Into<f64>>(h: T, s: T, b: T, a: T) -> Self
pub fn hsba<T: Into<f64>>(h: T, s: T, b: T, a: T) -> Self
Constructs a Color
with hue
, saturation
, brightness
and alpha
.
Example
let c = Color::hsba(126.0, 80.0, 50.0, 0.5);
assert_eq!(c.channels(), [25, 128, 36, 128]);
sourcepub fn hsl<T: Into<f64>>(h: T, s: T, l: T) -> Self
pub fn hsl<T: Into<f64>>(h: T, s: T, l: T) -> Self
Constructs a Color
with hue
, saturation
, lightness
and max alpha
.
Example
let c = Color::hsl(126.0, 80.0, 50.0);
assert_eq!(c.channels(), [25, 230, 46, 255]);
sourcepub fn hsla<T: Into<f64>>(h: T, s: T, l: T, a: T) -> Self
pub fn hsla<T: Into<f64>>(h: T, s: T, l: T, a: T) -> Self
Constructs a Color
with hue
, saturation
, lightness
and alpha
.
Example
let c = Color::hsla(126.0, 80.0, 50.0, 0.5);
assert_eq!(c.channels(), [25, 230, 46, 128]);
sourcepub fn from_levels<T: Into<f64>>(
mode: Mode,
v1: T,
v2: T,
v3: T,
alpha: T
) -> Self
pub fn from_levels<T: Into<f64>>( mode: Mode, v1: T, v2: T, v3: T, alpha: T ) -> Self
sourcepub fn random() -> Self
pub fn random() -> Self
Constructs a random Color
with red
, green
, blue
and max alpha.
Example
let c = Color::random();
// `c.channels()` will return something like:
// [207, 12, 217, 255]
sourcepub fn random_alpha() -> Self
pub fn random_alpha() -> Self
Constructs a random Color
with red
, green
, blue
and alpha.
Example
let c = Color::random_alpha();
// `c.channels()` will return something like:
// [132, 159, 233, 76]
sourcepub const fn as_hex_alpha(&self) -> u32
pub const fn as_hex_alpha(&self) -> u32
sourcepub const fn maxes(&self) -> [f64; 4]
pub const fn maxes(&self) -> [f64; 4]
Returns a list of max values for each color channel based on Mode.
Examples
let c = Color::rgb(0, 0, 0);
assert_eq!(c.maxes(), [255.0, 255.0, 255.0, 255.0]);
let c = Color::hsb(0.0, 0.0, 0.0);
assert_eq!(c.maxes(), [360.0, 100.0, 100.0, 1.0]);
let c = Color::hsl(0.0, 0.0, 0.0);
assert_eq!(c.maxes(), [360.0, 100.0, 100.0, 1.0]);
sourcepub fn levels(&self) -> [f64; 4]
pub fn levels(&self) -> [f64; 4]
Returns the Color
levels for the given Mode which range from 0.0..=1.0
.
sourcepub fn set_levels(&mut self, levels: [f64; 4])
pub fn set_levels(&mut self, levels: [f64; 4])
sourcepub const fn channels(&self) -> [u8; 4]
pub const fn channels(&self) -> [u8; 4]
Returns the Color
channels as [red, green, blue, alpha]
which range from 0..=255
.
Example
let c = Color::rgba(128, 64, 128, 128);
assert_eq!(c.channels(), [128, 64, 128, 128]);
sourcepub const fn red(&self) -> u8
pub const fn red(&self) -> u8
Returns the red Color
channel ranging from 0..=255
.
Example
let c = Color::rgb(100, 0, 0);
assert_eq!(c.red(), 100);
sourcepub fn set_red(&mut self, r: u8)
pub fn set_red(&mut self, r: u8)
Set the red Color
channel ranging from 0..=255
.
Example
let mut c = Color::default();
assert_eq!(c.channels(), [0, 0, 0, 255]);
c.set_red(100);
assert_eq!(c.channels(), [100, 0, 0, 255]);
sourcepub const fn green(&self) -> u8
pub const fn green(&self) -> u8
Returns the green Color
channel ranging from 0..=255
.
Example
let c = Color::rgb(0, 100, 0);
assert_eq!(c.green(), 100);
sourcepub fn set_green(&mut self, g: u8)
pub fn set_green(&mut self, g: u8)
Set the green Color
channel ranging from 0..=255
.
Example
let mut c = Color::default();
assert_eq!(c.channels(), [0, 0, 0, 255]);
c.set_green(100);
assert_eq!(c.channels(), [0, 100, 0, 255]);
sourcepub const fn blue(&self) -> u8
pub const fn blue(&self) -> u8
Returns the blue Color
channel ranging from 0..=255
.
Example
let c = Color::rgb(0, 0, 100);
assert_eq!(c.blue(), 100);
sourcepub fn set_blue(&mut self, b: u8)
pub fn set_blue(&mut self, b: u8)
Set the blue Color
channel ranging from 0..=255
.
Example
let mut c = Color::default();
assert_eq!(c.channels(), [0, 0, 0, 255]);
c.set_blue(100);
assert_eq!(c.channels(), [0, 0, 100, 255]);
sourcepub const fn alpha(&self) -> u8
pub const fn alpha(&self) -> u8
Returns the alpha Color
channel ranging from 0..=255
.
Examples
let c = Color::rgba(0, 0, 0, 100);
assert_eq!(c.alpha(), 100);
sourcepub fn set_alpha(&mut self, a: u8)
pub fn set_alpha(&mut self, a: u8)
Set the alpha Color
channel ranging from 0..=255
.
Examples
let mut c = Color::default();
assert_eq!(c.channels(), [0, 0, 0, 255]);
c.set_alpha(100);
assert_eq!(c.channels(), [0, 0, 0, 100]);
sourcepub fn hue(&self) -> f64
pub fn hue(&self) -> f64
Returns the hue ranging from 0.0..=360.0
.
Example
let c = Color::rgb(0, 100, 0);
assert_eq!(c.hue(), 120.0);
sourcepub fn set_hue<H: Into<f64>>(&mut self, h: H)
pub fn set_hue<H: Into<f64>>(&mut self, h: H)
Set the hue ranging from 0.0..=360.0
.
Example
let mut c = Color::rgb(128, 0, 0);
assert_eq!(c.channels(), [128, 0, 0, 255]);
c.set_hue(100.0);
assert_eq!(c.channels(), [43, 128, 0, 255]);
sourcepub fn saturation(&self) -> f64
pub fn saturation(&self) -> f64
Returns the saturation ranging from 0.0..=100.0
.
Example
let c = Color::rgb(0, 100, 0);
assert_eq!(c.saturation(), 100.0);
sourcepub fn set_saturation<S: Into<f64>>(&mut self, s: S)
pub fn set_saturation<S: Into<f64>>(&mut self, s: S)
Set the saturation ranging from 0.0..=100.0
. Defaults to Hsb if the
current mode is not Hsb or Hsl already.
Examples
let mut c = Color::rgb(128, 0, 0);
assert_eq!(c.channels(), [128, 0, 0, 255]);
c.set_saturation(50.0);
assert_eq!(c.channels(), [128, 64, 64, 255]);
let mut c = Color::rgb(128, 0, 0);
c.set_mode(ColorMode::Hsl);
assert_eq!(c.channels(), [128, 0, 0, 255]);
c.set_saturation(50.0);
assert_eq!(c.channels(), [96, 32, 32, 255]);
sourcepub fn brightness(&self) -> f64
pub fn brightness(&self) -> f64
Returns the brightness ranging from 0.0..=100.0
.
Example
let c = Color::rgb(0, 102, 0);
assert_eq!(c.brightness(), 40.0);
sourcepub fn set_brightness<B: Into<f64>>(&mut self, b: B)
pub fn set_brightness<B: Into<f64>>(&mut self, b: B)
Set the brightness ranging from 0.0..=100.0
.
Example
let mut c = Color::rgb(128, 0, 0);
assert_eq!(c.channels(), [128, 0, 0, 255]);
c.set_brightness(90.0);
assert_eq!(c.channels(), [230, 0, 0, 255]);
sourcepub fn lightness(&self) -> f64
pub fn lightness(&self) -> f64
Returns the lightness ranging from 0.0..=100.0
.
Example
let c = Color::rgb(0, 102, 0);
assert_eq!(c.lightness(), 20.0);
sourcepub fn set_lightness<L: Into<f64>>(&mut self, l: L)
pub fn set_lightness<L: Into<f64>>(&mut self, l: L)
Set the lightness ranging from 0.0..=100.0
.
Example
let mut c = Color::rgb(128, 0, 0);
assert_eq!(c.channels(), [128, 0, 0, 255]);
c.set_lightness(90.0);
assert_eq!(c.channels(), [255, 204, 204, 255]);
Methods from Deref<Target = [u8; 4]>§
1.57.0 · sourcepub fn as_slice(&self) -> &[T]
pub fn as_slice(&self) -> &[T]
Returns a slice containing the entire array. Equivalent to &s[..]
.
sourcepub fn each_ref(&self) -> [&T; N]
🔬This is a nightly-only experimental API. (array_methods
)
pub fn each_ref(&self) -> [&T; N]
array_methods
)Borrows each element and returns an array of references with the same
size as self
.
Example
#![feature(array_methods)]
let floats = [3.1, 2.7, -1.0];
let float_refs: [&f64; 3] = floats.each_ref();
assert_eq!(float_refs, [&3.1, &2.7, &-1.0]);
This method is particularly useful if combined with other methods, like
map
. This way, you can avoid moving the original
array if its elements are not Copy
.
#![feature(array_methods)]
let strings = ["Ferris".to_string(), "♥".to_string(), "Rust".to_string()];
let is_ascii = strings.each_ref().map(|s| s.is_ascii());
assert_eq!(is_ascii, [true, false, true]);
// We can still access the original array: it has not been moved.
assert_eq!(strings.len(), 3);
sourcepub fn split_array_ref<const M: usize>(&self) -> (&[T; M], &[T])
🔬This is a nightly-only experimental API. (split_array
)
pub fn split_array_ref<const M: usize>(&self) -> (&[T; M], &[T])
split_array
)Divides one array reference into two at an index.
The first will contain all indices from [0, M)
(excluding
the index M
itself) and the second will contain all
indices from [M, N)
(excluding the index N
itself).
Panics
Panics if M > N
.
Examples
#![feature(split_array)]
let v = [1, 2, 3, 4, 5, 6];
{
let (left, right) = v.split_array_ref::<0>();
assert_eq!(left, &[]);
assert_eq!(right, &[1, 2, 3, 4, 5, 6]);
}
{
let (left, right) = v.split_array_ref::<2>();
assert_eq!(left, &[1, 2]);
assert_eq!(right, &[3, 4, 5, 6]);
}
{
let (left, right) = v.split_array_ref::<6>();
assert_eq!(left, &[1, 2, 3, 4, 5, 6]);
assert_eq!(right, &[]);
}
sourcepub fn rsplit_array_ref<const M: usize>(&self) -> (&[T], &[T; M])
🔬This is a nightly-only experimental API. (split_array
)
pub fn rsplit_array_ref<const M: usize>(&self) -> (&[T], &[T; M])
split_array
)Divides one array reference into two at an index from the end.
The first will contain all indices from [0, N - M)
(excluding
the index N - M
itself) and the second will contain all
indices from [N - M, N)
(excluding the index N
itself).
Panics
Panics if M > N
.
Examples
#![feature(split_array)]
let v = [1, 2, 3, 4, 5, 6];
{
let (left, right) = v.rsplit_array_ref::<0>();
assert_eq!(left, &[1, 2, 3, 4, 5, 6]);
assert_eq!(right, &[]);
}
{
let (left, right) = v.rsplit_array_ref::<2>();
assert_eq!(left, &[1, 2, 3, 4]);
assert_eq!(right, &[5, 6]);
}
{
let (left, right) = v.rsplit_array_ref::<6>();
assert_eq!(left, &[]);
assert_eq!(right, &[1, 2, 3, 4, 5, 6]);
}
sourcepub fn as_ascii(&self) -> Option<&[AsciiChar; N]>
🔬This is a nightly-only experimental API. (ascii_char
)
pub fn as_ascii(&self) -> Option<&[AsciiChar; N]>
ascii_char
)Converts this array of bytes into a array of ASCII characters,
or returns None
if any of the characters is non-ASCII.
Examples
#![feature(ascii_char)]
#![feature(const_option)]
const HEX_DIGITS: [std::ascii::Char; 16] =
*b"0123456789abcdef".as_ascii().unwrap();
assert_eq!(HEX_DIGITS[1].as_str(), "1");
assert_eq!(HEX_DIGITS[10].as_str(), "a");
sourcepub unsafe fn as_ascii_unchecked(&self) -> &[AsciiChar; N]
🔬This is a nightly-only experimental API. (ascii_char
)
pub unsafe fn as_ascii_unchecked(&self) -> &[AsciiChar; N]
ascii_char
)Converts this array of bytes into a array of ASCII characters, without checking whether they’re valid.
Safety
Every byte in the array must be in 0..=127
, or else this is UB.
Trait Implementations§
source§impl AddAssign<u8> for Color
impl AddAssign<u8> for Color
source§fn add_assign(&mut self, val: u8)
fn add_assign(&mut self, val: u8)
+=
operation. Read moresource§impl AddAssign for Color
impl AddAssign for Color
source§fn add_assign(&mut self, other: Color)
fn add_assign(&mut self, other: Color)
+=
operation. Read moresource§impl<'de> Deserialize<'de> for Color
impl<'de> Deserialize<'de> for Color
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl DivAssign<f32> for Color
impl DivAssign<f32> for Color
source§fn div_assign(&mut self, s: f32)
fn div_assign(&mut self, s: f32)
/=
operation. Read moresource§impl DivAssign<f64> for Color
impl DivAssign<f64> for Color
source§fn div_assign(&mut self, s: f64)
fn div_assign(&mut self, s: f64)
/=
operation. Read moresource§impl DivAssign<i128> for Color
impl DivAssign<i128> for Color
source§fn div_assign(&mut self, s: i128)
fn div_assign(&mut self, s: i128)
/=
operation. Read moresource§impl DivAssign<i16> for Color
impl DivAssign<i16> for Color
source§fn div_assign(&mut self, s: i16)
fn div_assign(&mut self, s: i16)
/=
operation. Read moresource§impl DivAssign<i32> for Color
impl DivAssign<i32> for Color
source§fn div_assign(&mut self, s: i32)
fn div_assign(&mut self, s: i32)
/=
operation. Read moresource§impl DivAssign<i64> for Color
impl DivAssign<i64> for Color
source§fn div_assign(&mut self, s: i64)
fn div_assign(&mut self, s: i64)
/=
operation. Read moresource§impl DivAssign<i8> for Color
impl DivAssign<i8> for Color
source§fn div_assign(&mut self, s: i8)
fn div_assign(&mut self, s: i8)
/=
operation. Read moresource§impl DivAssign<isize> for Color
impl DivAssign<isize> for Color
source§fn div_assign(&mut self, s: isize)
fn div_assign(&mut self, s: isize)
/=
operation. Read moresource§impl DivAssign<u128> for Color
impl DivAssign<u128> for Color
source§fn div_assign(&mut self, s: u128)
fn div_assign(&mut self, s: u128)
/=
operation. Read moresource§impl DivAssign<u16> for Color
impl DivAssign<u16> for Color
source§fn div_assign(&mut self, s: u16)
fn div_assign(&mut self, s: u16)
/=
operation. Read moresource§impl DivAssign<u32> for Color
impl DivAssign<u32> for Color
source§fn div_assign(&mut self, s: u32)
fn div_assign(&mut self, s: u32)
/=
operation. Read moresource§impl DivAssign<u64> for Color
impl DivAssign<u64> for Color
source§fn div_assign(&mut self, s: u64)
fn div_assign(&mut self, s: u64)
/=
operation. Read moresource§impl DivAssign<u8> for Color
impl DivAssign<u8> for Color
source§fn div_assign(&mut self, s: u8)
fn div_assign(&mut self, s: u8)
/=
operation. Read moresource§impl DivAssign<usize> for Color
impl DivAssign<usize> for Color
source§fn div_assign(&mut self, s: usize)
fn div_assign(&mut self, s: usize)
/=
operation. Read moresource§impl FromStr for Color
impl FromStr for Color
source§fn from_str(string: &str) -> Result<Self, Self::Err>
fn from_str(string: &str) -> Result<Self, Self::Err>
Converts to Color from a hexadecimal string.
Examples
use std::str::FromStr;
let c = Color::from_str("#F0F")?; // 3-digit Hex string
assert_eq!(c.channels(), [255, 0, 255, 255]);
let c = Color::from_str("#F0F5")?; // 4-digit Hex string
assert_eq![c.channels(), [255, 0, 255, 85]];
let c = Color::from_str("#F0F5BF")?; // 6-digit Hex string
assert_eq!(c.channels(), [240, 245, 191, 255]);
let c = Color::from_str("#F0F5BF5F")?; // 8-digit Hex string
assert_eq!(c.channels(), [240, 245, 191, 95]);
source§impl MulAssign<f32> for Color
impl MulAssign<f32> for Color
source§fn mul_assign(&mut self, s: f32)
fn mul_assign(&mut self, s: f32)
*=
operation. Read moresource§impl MulAssign<f64> for Color
impl MulAssign<f64> for Color
source§fn mul_assign(&mut self, s: f64)
fn mul_assign(&mut self, s: f64)
*=
operation. Read moresource§impl MulAssign<i128> for Color
impl MulAssign<i128> for Color
source§fn mul_assign(&mut self, s: i128)
fn mul_assign(&mut self, s: i128)
*=
operation. Read moresource§impl MulAssign<i16> for Color
impl MulAssign<i16> for Color
source§fn mul_assign(&mut self, s: i16)
fn mul_assign(&mut self, s: i16)
*=
operation. Read moresource§impl MulAssign<i32> for Color
impl MulAssign<i32> for Color
source§fn mul_assign(&mut self, s: i32)
fn mul_assign(&mut self, s: i32)
*=
operation. Read moresource§impl MulAssign<i64> for Color
impl MulAssign<i64> for Color
source§fn mul_assign(&mut self, s: i64)
fn mul_assign(&mut self, s: i64)
*=
operation. Read moresource§impl MulAssign<i8> for Color
impl MulAssign<i8> for Color
source§fn mul_assign(&mut self, s: i8)
fn mul_assign(&mut self, s: i8)
*=
operation. Read moresource§impl MulAssign<isize> for Color
impl MulAssign<isize> for Color
source§fn mul_assign(&mut self, s: isize)
fn mul_assign(&mut self, s: isize)
*=
operation. Read moresource§impl MulAssign<u128> for Color
impl MulAssign<u128> for Color
source§fn mul_assign(&mut self, s: u128)
fn mul_assign(&mut self, s: u128)
*=
operation. Read moresource§impl MulAssign<u16> for Color
impl MulAssign<u16> for Color
source§fn mul_assign(&mut self, s: u16)
fn mul_assign(&mut self, s: u16)
*=
operation. Read moresource§impl MulAssign<u32> for Color
impl MulAssign<u32> for Color
source§fn mul_assign(&mut self, s: u32)
fn mul_assign(&mut self, s: u32)
*=
operation. Read moresource§impl MulAssign<u64> for Color
impl MulAssign<u64> for Color
source§fn mul_assign(&mut self, s: u64)
fn mul_assign(&mut self, s: u64)
*=
operation. Read moresource§impl MulAssign<u8> for Color
impl MulAssign<u8> for Color
source§fn mul_assign(&mut self, s: u8)
fn mul_assign(&mut self, s: u8)
*=
operation. Read moresource§impl MulAssign<usize> for Color
impl MulAssign<usize> for Color
source§fn mul_assign(&mut self, s: usize)
fn mul_assign(&mut self, s: usize)
*=
operation. Read moresource§impl PartialEq for Color
impl PartialEq for Color
source§impl SubAssign<u8> for Color
impl SubAssign<u8> for Color
source§fn sub_assign(&mut self, val: u8)
fn sub_assign(&mut self, val: u8)
-=
operation. Read moresource§impl SubAssign for Color
impl SubAssign for Color
source§fn sub_assign(&mut self, other: Color)
fn sub_assign(&mut self, other: Color)
-=
operation. Read more