[go: up one dir, main page]

RgbColor

Struct RgbColor 

Source
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

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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

Source

pub fn to_rgb_string(self) -> String

Returns a string of the form #RRGGBB

Source

pub fn to_x11_16bit_rgb_string(self) -> String

Returns a string of the form rgb:RRRR/GGGG/BBBB

Source

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.

Source

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 Clone for RgbColor

Source§

fn clone(&self) -> RgbColor

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RgbColor

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for RgbColor

Source§

fn default() -> RgbColor

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for RgbColor

Available on crate feature use_serde only.
Source§

fn deserialize<D>(deserializer: D) -> Result<RgbColor, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<RgbColor> for ColorSpec

Source§

fn from(col: RgbColor) -> Self

Converts to this type from the input type.
Source§

impl From<SrgbaTuple> for RgbColor

Source§

fn from(srgb: SrgbaTuple) -> RgbColor

Converts to this type from the input type.
Source§

impl FromDynamic for RgbColor

Source§

fn from_dynamic( value: &Value, options: FromDynamicOptions, ) -> Result<Self, Error>

Source§

impl Hash for RgbColor

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Into<SrgbaTuple> for RgbColor

Source§

fn into(self) -> SrgbaTuple

Converts this type into the (usually inferred) input type.
Source§

impl PartialEq for RgbColor

Source§

fn eq(&self, other: &RgbColor) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
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.

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl ToDynamic for RgbColor

Source§

impl Copy for RgbColor

Source§

impl Eq for RgbColor

Source§

impl StructuralPartialEq for RgbColor

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,