pub struct RgbColor { /* private fields */ }Expand description
Describes a color in the SRGB colorspace using red, green and blue components in the range 0-255.
Implementations
sourceimpl RgbColor
impl RgbColor
sourcepub const fn new_8bpc(red: u8, green: u8, blue: u8) -> Self
pub const fn new_8bpc(red: u8, green: u8, blue: u8) -> Self
Construct a color from discrete red, green, blue values in the range 0-255.
sourcepub fn new_f32(red: f32, green: f32, blue: f32) -> Self
pub fn new_f32(red: f32, green: f32, blue: f32) -> Self
Construct a color from discrete red, green, blue values in the range 0.0-1.0 in the sRGB colorspace.
sourcepub fn to_tuple_rgb8(self) -> (u8, u8, u8)
pub fn to_tuple_rgb8(self) -> (u8, u8, u8)
Returns red, green, blue as 8bpc values. Will convert from 10bpc if that is the internal storage.
sourcepub fn to_tuple_rgba(self) -> SrgbaTuple
pub fn to_tuple_rgba(self) -> SrgbaTuple
Returns red, green, blue as floating point values in the range 0.0-1.0. An alpha channel with the value of 1.0 is included. The values are in the sRGB colorspace.
sourcepub fn to_linear_tuple_rgba(self) -> LinearRgba
pub fn to_linear_tuple_rgba(self) -> LinearRgba
Returns red, green, blue as floating point values in the range 0.0-1.0. An alpha channel with the value of 1.0 is included. The values are converted from sRGB to linear colorspace.
sourcepub fn from_named(name: &str) -> Option<RgbColor>
pub fn from_named(name: &str) -> Option<RgbColor>
Construct a color from an X11/SVG/CSS3 color name. Returns None if the supplied name is not recognized. The list of names can be found here: https://en.wikipedia.org/wiki/X11_color_names
sourcepub fn to_rgb_string(self) -> String
pub fn to_rgb_string(self) -> String
Returns a string of the form #RRGGBB
sourcepub fn to_x11_16bit_rgb_string(self) -> String
pub fn to_x11_16bit_rgb_string(self) -> String
Returns a string of the form rgb:RRRR/GGGG/BBBB
sourcepub fn from_rgb_str(s: &str) -> Option<RgbColor>
pub fn from_rgb_str(s: &str) -> Option<RgbColor>
Construct a color from a string of the form #RRGGBB where
R, G and B are all hex digits.
hsl:hue sat light is also accepted, and allows specifying a color
in the HSL color space, where hue is measure in degrees and has
a range of 0-360, and both sat and light are specified in percentage
in the range 0-100.
sourcepub fn from_named_or_rgb_string(s: &str) -> Option<Self>
pub fn from_named_or_rgb_string(s: &str) -> Option<Self>
Construct a color from an SVG/CSS3 color name.
or from a string of the form #RRGGBB where
R, G and B are all hex digits.
hsl:hue sat light is also accepted, and allows specifying a color
in the HSL color space, where hue is measure in degrees and has
a range of 0-360, and both sat and light are specified in percentage
in the range 0-100.
Returns None if the supplied name is not recognized.
The list of names can be found here:
https://ogeon.github.io/docs/palette/master/palette/named/index.html
Trait Implementations
sourceimpl<'de> Deserialize<'de> for RgbColor
impl<'de> Deserialize<'de> for RgbColor
sourcefn deserialize<D>(deserializer: D) -> Result<RgbColor, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<RgbColor, D::Error>where
D: Deserializer<'de>,
sourceimpl From<SrgbaTuple> for RgbColor
impl From<SrgbaTuple> for RgbColor
sourcefn from(srgb: SrgbaTuple) -> RgbColor
fn from(srgb: SrgbaTuple) -> RgbColor
sourceimpl FromDynamic for RgbColor
impl FromDynamic for RgbColor
fn from_dynamic(
value: &Value,
options: FromDynamicOptions
) -> Result<Self, Error>
sourceimpl Into<SrgbaTuple> for RgbColor
impl Into<SrgbaTuple> for RgbColor
sourcefn into(self) -> SrgbaTuple
fn into(self) -> SrgbaTuple
sourceimpl Serialize for RgbColor
impl Serialize for RgbColor
This is mildly unfortunate: in order to round trip RgbColor with serde we need to provide a Serialize impl equivalent to the Deserialize impl below. We use the impl below to allow more flexible specification of color strings in the config file. A side effect of doing it this way is that we have to serialize RgbColor as a 7-byte string when we could otherwise serialize it as a 3-byte array. There’s probably a way to make this work more efficiently, but for now this will do.