Struct oliframe::Color

source ·
pub struct Color {
    pub r: f64,
    pub g: f64,
    pub b: f64,
    pub a: f64,
}
Expand description

The color

Fields§

§r: f64

Red

§g: f64

Green

§b: f64

Blue

§a: f64

Alpha

Implementations§

source§

impl Color

source

pub const fn new(r: f64, g: f64, b: f64, a: f64) -> Color

Arguments:

  • r: Red value [0..1]
  • g: Green value [0..1]
  • b: Blue value [0..1]
  • a: Alpha value [0..1]
source

pub fn to_array(&self) -> [f64; 4]

source

pub fn to_rgba8(&self) -> [u8; 4]

source

pub fn to_rgba16(&self) -> [u16; 4]

source

pub fn clamp(&self) -> Color

source

pub fn from_rgb(r: f64, g: f64, b: f64) -> Color

👎Deprecated: Use new instead.

Arguments:

  • r: Red value [0..1]
  • g: Green value [0..1]
  • b: Blue value [0..1]
source

pub fn from_rgba(r: f64, g: f64, b: f64, a: f64) -> Color

👎Deprecated: Use new instead.

Arguments:

  • r: Red value [0..1]
  • g: Green value [0..1]
  • b: Blue value [0..1]
  • a: Alpha value [0..1]
source

pub fn from_rgb_u8(r: u8, g: u8, b: u8) -> Color

👎Deprecated: Use from_rgba8 instead.

Arguments:

  • r: Red value [0..255]
  • g: Green value [0..255]
  • b: Blue value [0..255]
source

pub fn from_rgba_u8(r: u8, g: u8, b: u8, a: u8) -> Color

👎Deprecated: Use from_rgba8 instead.

Arguments:

  • r: Red value [0..255]
  • g: Green value [0..255]
  • b: Blue value [0..255]
  • a: Alpha value [0..255]
source

pub fn from_rgba8(r: u8, g: u8, b: u8, a: u8) -> Color

Arguments:

  • r: Red value [0..255]
  • g: Green value [0..255]
  • b: Blue value [0..255]
  • a: Alpha value [0..255]
source

pub fn from_linear_rgb(r: f64, g: f64, b: f64) -> Color

👎Deprecated: Use from_linear_rgba instead.

Arguments:

  • r: Red value [0..1]
  • g: Green value [0..1]
  • b: Blue value [0..1]
source

pub fn from_linear_rgba(r: f64, g: f64, b: f64, a: f64) -> Color

Arguments:

  • r: Red value [0..1]
  • g: Green value [0..1]
  • b: Blue value [0..1]
  • a: Alpha value [0..1]
source

pub fn from_linear_rgb_u8(r: u8, g: u8, b: u8) -> Color

👎Deprecated: Use from_linear_rgba8 instead.

Arguments:

  • r: Red value [0..255]
  • g: Green value [0..255]
  • b: Blue value [0..255]
source

pub fn from_linear_rgba_u8(r: u8, g: u8, b: u8, a: u8) -> Color

👎Deprecated: Use from_linear_rgba8 instead.

Arguments:

  • r: Red value [0..255]
  • g: Green value [0..255]
  • b: Blue value [0..255]
  • a: Alpha value [0..255]
source

pub fn from_linear_rgba8(r: u8, g: u8, b: u8, a: u8) -> Color

Arguments:

  • r: Red value [0..255]
  • g: Green value [0..255]
  • b: Blue value [0..255]
  • a: Alpha value [0..255]
source

pub fn from_hsv(h: f64, s: f64, v: f64) -> Color

👎Deprecated: Use from_hsva instead.

Arguments:

  • h: Hue angle [0..360]
  • s: Saturation [0..1]
  • v: Value [0..1]
source

pub fn from_hsva(h: f64, s: f64, v: f64, a: f64) -> Color

Arguments:

  • h: Hue angle [0..360]
  • s: Saturation [0..1]
  • v: Value [0..1]
  • a: Alpha [0..1]
source

pub fn from_hsl(h: f64, s: f64, l: f64) -> Color

👎Deprecated: Use from_hsla instead.

Arguments:

  • h: Hue angle [0..360]
  • s: Saturation [0..1]
  • l: Lightness [0..1]
source

pub fn from_hsla(h: f64, s: f64, l: f64, a: f64) -> Color

Arguments:

  • h: Hue angle [0..360]
  • s: Saturation [0..1]
  • l: Lightness [0..1]
  • a: Alpha [0..1]
source

pub fn from_hwb(h: f64, w: f64, b: f64) -> Color

👎Deprecated: Use from_hwba instead.

Arguments:

  • h: Hue angle [0..360]
  • w: Whiteness [0..1]
  • b: Blackness [0..1]
source

pub fn from_hwba(h: f64, w: f64, b: f64, a: f64) -> Color

Arguments:

  • h: Hue angle [0..360]
  • w: Whiteness [0..1]
  • b: Blackness [0..1]
  • a: Alpha [0..1]
source

pub fn from_oklab(l: f64, a: f64, b: f64) -> Color

👎Deprecated: Use from_oklaba instead.

Arguments:

  • l: Perceived lightness
  • a: How green/red the color is
  • b: How blue/yellow the color is
source

pub fn from_oklaba(l: f64, a: f64, b: f64, alpha: f64) -> Color

Arguments:

  • l: Perceived lightness
  • a: How green/red the color is
  • b: How blue/yellow the color is
  • alpha: Alpha [0..1]
source

pub fn from_html<S>(s: S) -> Result<Color, ParseColorError>
where S: AsRef<str>,

Create color from CSS color string.

§Examples
use csscolorparser::Color;

let c = Color::from_html("rgb(255,0,0)")?;

assert_eq!(c.to_array(), [1.0, 0.0, 0.0, 1.0]);
assert_eq!(c.to_rgba8(), [255, 0, 0, 255]);
assert_eq!(c.to_hex_string(), "#ff0000");
assert_eq!(c.to_rgb_string(), "rgb(255,0,0)");
source

pub fn name(&self) -> Option<&'static str>

source

pub fn rgba(&self) -> (f64, f64, f64, f64)

👎Deprecated

Returns: (r, g, b, a)

  • Red, green, blue and alpha in the range [0..1]
source

pub fn rgba_u8(&self) -> (u8, u8, u8, u8)

👎Deprecated: Use to_rgba8 instead.

Returns: (r, g, b, a)

  • Red, green, blue and alpha in the range [0..255]
source

pub fn to_hsva(&self) -> (f64, f64, f64, f64)

Returns: (h, s, v, a)

  • h: Hue angle [0..360]
  • s: Saturation [0..1]
  • v: Value [0..1]
  • a: Alpha [0..1]
source

pub fn to_hsla(&self) -> (f64, f64, f64, f64)

Returns: (h, s, l, a)

  • h: Hue angle [0..360]
  • s: Saturation [0..1]
  • l: Lightness [0..1]
  • a: Alpha [0..1]
source

pub fn to_hwba(&self) -> (f64, f64, f64, f64)

Returns: (h, w, b, a)

  • h: Hue angle [0..360]
  • w: Whiteness [0..1]
  • b: Blackness [0..1]
  • a: Alpha [0..1]
source

pub fn to_linear_rgba(&self) -> (f64, f64, f64, f64)

Returns: (r, g, b, a)

  • Red, green, blue and alpha in the range [0..1]
source

pub fn to_linear_rgba_u8(&self) -> (u8, u8, u8, u8)

Returns: (r, g, b, a)

  • Red, green, blue and alpha in the range [0..255]
source

pub fn to_oklaba(&self) -> (f64, f64, f64, f64)

Returns: (l, a, b, alpha)

source

pub fn to_hex_string(&self) -> String

Get the RGB hexadecimal color string.

source

pub fn to_rgb_string(&self) -> String

Get the CSS rgb() format string.

source

pub fn interpolate_rgb(&self, other: &Color, t: f64) -> Color

Blend this color with the other one, in the RGB color-space. t in the range [0..1].

source

pub fn interpolate_linear_rgb(&self, other: &Color, t: f64) -> Color

Blend this color with the other one, in the linear RGB color-space. t in the range [0..1].

source

pub fn interpolate_hsv(&self, other: &Color, t: f64) -> Color

Blend this color with the other one, in the HSV color-space. t in the range [0..1].

source

pub fn interpolate_oklab(&self, other: &Color, t: f64) -> Color

Blend this color with the other one, in the Oklab color-space. t in the range [0..1].

Trait Implementations§

source§

impl Clone for Color

source§

fn clone(&self) -> Color

Returns a copy 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 Color

source§

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

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

impl Default for Color

source§

fn default() -> Color

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

impl Display for Color

source§

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

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

impl From<[f32; 3]> for Color

source§

fn from(_: [f32; 3]) -> Color

Converts to this type from the input type.
source§

impl From<[f32; 4]> for Color

source§

fn from(_: [f32; 4]) -> Color

Converts to this type from the input type.
source§

impl From<[f64; 3]> for Color

source§

fn from(_: [f64; 3]) -> Color

Converts to this type from the input type.
source§

impl From<[f64; 4]> for Color

source§

fn from(_: [f64; 4]) -> Color

Converts to this type from the input type.
source§

impl From<[u8; 3]> for Color

source§

fn from(_: [u8; 3]) -> Color

Converts to this type from the input type.
source§

impl From<[u8; 4]> for Color

source§

fn from(_: [u8; 4]) -> Color

Converts to this type from the input type.
source§

impl From<(f64, f64, f64)> for Color

source§

fn from(_: (f64, f64, f64)) -> Color

Converts to this type from the input type.
source§

impl From<(f64, f64, f64, f64)> for Color

source§

fn from(_: (f64, f64, f64, f64)) -> Color

Converts to this type from the input type.
source§

impl From<(u8, u8, u8)> for Color

source§

fn from(_: (u8, u8, u8)) -> Color

Converts to this type from the input type.
source§

impl From<(u8, u8, u8, u8)> for Color

source§

fn from(_: (u8, u8, u8, u8)) -> Color

Converts to this type from the input type.
source§

impl FromStr for Color

§

type Err = ParseColorError

The associated error which can be returned from parsing.
source§

fn from_str(s: &str) -> Result<Color, <Color as FromStr>::Err>

Parses a string s to return a value of this type. Read more
source§

impl PartialEq for Color

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for Color

source§

fn partial_cmp(&self, other: &Color) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

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

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

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

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl TryFrom<&str> for Color

§

type Error = ParseColorError

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

fn try_from(s: &str) -> Result<Color, <Color as TryFrom<&str>>::Error>

Performs the conversion.
source§

impl StructuralPartialEq for Color

Auto Trait Implementations§

§

impl Freeze for Color

§

impl RefUnwindSafe for Color

§

impl Send for Color

§

impl Sync for Color

§

impl Unpin for Color

§

impl UnwindSafe for Color

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> 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> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
source§

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

§

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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

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>,

§

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.