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§
Source§impl 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§
Source§impl<'de> Deserialize<'de> for RgbColor
Available on crate feature use_serde only.
impl<'de> Deserialize<'de> for RgbColor
use_serde only.Source§fn 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>,
Source§impl From<SrgbaTuple> for RgbColor
impl From<SrgbaTuple> for RgbColor
Source§fn from(srgb: SrgbaTuple) -> RgbColor
fn from(srgb: SrgbaTuple) -> RgbColor
Source§impl FromDynamic for RgbColor
impl FromDynamic for RgbColor
fn from_dynamic( value: &Value, options: FromDynamicOptions, ) -> Result<Self, Error>
Source§impl Into<SrgbaTuple> for RgbColor
impl Into<SrgbaTuple> for RgbColor
Source§fn into(self) -> SrgbaTuple
fn into(self) -> SrgbaTuple
Source§impl Serialize for RgbColor
Available on crate feature use_serde only.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.
impl Serialize for RgbColor
use_serde only.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.