pub enum Color {
}
Expand description
Specifies the desired color setting of a light.
HSBK is the preferred method of specifying colors (RGB represents color poorly); as such,
Hue
, Saturation
, Brightness
, and Kelvin
are among the more useful variants here.
RGB colors will automatically be converted by the API.
Variants
Red
Sets the hue and saturation components necessary to change the color to red, leaving brightness untouched.
Orange
Sets the hue and saturation components necessary to change the color to orange, leaving brightness untouched.
Yellow
Sets the hue and saturation components necessary to change the color to yellow, leaving brightness untouched.
Green
Sets the hue and saturation components necessary to change the color to green, leaving brightness untouched.
Blue
Sets the hue and saturation components necessary to change the color to blue, leaving brightness untouched.
Purple
Sets the hue and saturation components necessary to change the color to purple, leaving brightness untouched.
Pink
Sets the hue and saturation components necessary to change the color to pink, leaving brightness untouched.
White
Sets the hue and saturation components necessary to change the color to white, leaving brightness untouched.
Hue(u16)
Sets the hue, leaving all else untouched.
The hue should be between 0 and 360.
Saturation(f32)
Sets the saturation, leaving all else untouched.
The saturation should be between 0 and 1.
Brightness(f32)
Sets the brightness, leaving all else untouched.
The brightness should be between 0 and 1.
Kelvin(u16)
Sets the temperature to the given value and saturation to 0, leaving all else untouched.
The temperature should be between 1500 and 9000.
Hsbk(Option<u16>, Option<f32>, Option<f32>, Option<u16>)
Used to specify more than one of hue, saturation, brightness, and color temperature.
See Hue
, Saturation
, Brightness
, and Kelvin
. None
values are ignored.
Rgb([u8; 3])
Sets the color to an RGB color using the given numeric components.
It is preferred to use this over RgbStr
where posssible.
RgbStr(String)
Sets the color to an RGB color using the given specifier string.
Strings may be of the form #ff0000
or ff0000
; outputs will be normalized to the former.
It is preferred to use Rgb
instead of this where posssible.
Custom(String)
Uses a custom specifier string.
This option exists for undocumented features. For instance, “cyan” is a valid color choice, but it is undocumented and therefore (theoretically) unstable, so it is not officially/ supported by this crate.
Implementations
sourceimpl Color
impl Color
sourcepub fn validate(&self) -> Result<(), Error>
pub fn validate(&self) -> Result<(), Error>
Checks whether the color is valid.
Notes
Custom color strings are not validated.
Examples
use lifxi::http::Color;
// Too short
let setting = Color::RgbStr("".to_string());
assert!(setting.validate().is_err());
// Too long for no leading #
let setting = Color::RgbStr("1234567".to_string());
assert!(setting.validate().is_err());
// Too high (max 9000)
let setting = Color::Kelvin(10_000);
assert!(setting.validate().is_err());
// Too high (max 1.0)
let setting = Color::Brightness(1.2);
assert!(setting.validate().is_err());
// Too low (min 0.0)
let setting = Color::Saturation(-0.1);
assert!(setting.validate().is_err());
let setting = Color::Kelvin(2_000);
assert!(setting.validate().is_ok());