alloy::model

Struct Color

source
pub struct Color(/* private fields */);
Expand description

A color represented by four floating point values.

Implementations§

source§

impl Color

source

pub const fn new(red: f32, green: f32, blue: f32, alpha: f32) -> Self

Create a new color with the given red, green, blue, and alpha values.

§Parameters
  • red - The red value.
  • green - The green value.
  • blue - The blue value.
  • alpha - The alpha value.
source

pub fn from_rgba32(rgba: u32) -> Self

Create a new color from a 32-bit RGBA value.

§Parameters
  • rgba - The 32-bit RGBA value.
source

pub fn from_rgba64(rgba: u64) -> Self

Create a new color from a 64-bit RGBA value.

§Parameters
  • rgba - The 64-bit RGBA value.
source

pub fn from_argb32(argb: u32) -> Self

Create a new color from a 32-bit ARGB value.

§Parameters
  • argb - The 32-bit ARGB value.
source

pub fn from_argb64(argb: u64) -> Self

Create a new color from a 64-bit ARGB value.

§Parameters
  • argb - The 64-bit ARGB value.
source

pub const fn new_opaque(red: f32, green: f32, blue: f32) -> Self

Create a new color with the given red, green, and blue values.

The alpha value will be set to 1.0.

§Parameters
  • red - The red value.
  • green - The green value.
  • blue - The blue value.
source

pub const fn from_vec3(vec: &Vec3) -> Self

Create a new color from an existing 3-component vector.

§Parameters
  • vec3 - The vector to create the color from.
source

pub const fn from_vec4(vec: &Vec4) -> Self

Create a new color from an existing 4-component vector.

§Parameters
  • vec4 - The vector to create the color from.
source§

impl Color

source

pub const BLACK: Self = _

A solid opaque black Color object.

source

pub const WHITE: Self = _

A solid opaque while Color object.

source

pub const RED: Self = _

A solid opaque red Color object.

source

pub const GREEN: Self = _

A solid opaque green Color object.

source

pub const BLUE: Self = _

A solid opaque blue Color object.

source

pub const YELLOW: Self = _

A solid opaque yellow Color object.

source

pub const CYAN: Self = _

A solid opaque cyan Color object.

source

pub const MAGENTA: Self = _

A solid opaque magenta Color object.

source

pub const TRANSPARENT: Self = _

A solid transparent/invisible Color object.

source§

impl Color

source

pub fn is_opaque(&self) -> bool

Checks whether this color is opaque.

This only returns true if the value is fully solid (e.g. alpha is 1.0).

source

pub fn is_transparent(&self) -> bool

Checks whether this color is transparent.

This only returns true if the value is fully transparent (e.g. alpha is 0.0).

source

pub const fn r(&self) -> f32

Get the red value of the color.

source

pub const fn g(&self) -> f32

Get the green value of the color.

source

pub const fn b(&self) -> f32

Get the blue value of the color.

source

pub const fn a(&self) -> f32

Get the alpha value of the color.

source

pub fn r_mut(&mut self) -> &mut f32

source

pub fn g_mut(&mut self) -> &mut f32

source

pub fn b_mut(&mut self) -> &mut f32

source

pub fn a_mut(&mut self) -> &mut f32

source

pub const fn rg(&self) -> &Vec2

Gets the red and green components of this color as a Vec2.

source

pub const fn gb(&self) -> &Vec2

Gets the green and blue components of this color as a Vec2.

source

pub const fn ba(&self) -> &Vec2

Gets the blue and alpha components of this color as a Vec2.

source

pub const fn rgb(&self) -> &Vec3

Gets the red, green, and blue components of this color as a Vec3.

source

pub const fn gba(&self) -> &Vec3

Gets the green, blue, and alpha components of this color as a Vec3.

source

pub fn rg_mut(&mut self) -> &mut Vec2

Gets a mutable reference to the red and green components of this color as a Vec2.

source

pub fn gb_mut(&mut self) -> &mut Vec2

Gets a mutable reference to the green and blue components of this color as a Vec2.

source

pub fn ba_mut(&mut self) -> &mut Vec2

Gets a mutable reference to the blue and alpha components of this color as a Vec2.

source

pub fn rgb_mut(&mut self) -> &mut Vec3

Gets a mutable reference to the red, green, and blue components of this color as a Vec3.

source

pub fn gba_mut(&mut self) -> &mut Vec3

Gets a mutable reference to the green, blue, and alpha components of this color as a Vec3.

source

pub fn blend(&self, other: &Self) -> Self

Blends this color with another color, returning the blended result.

Blending makes heavy use of the alpha channel to determine how two colors should be combined. The alpha channel of the other color is used to determine how much of the other color should be blended with this color.

If the alpha cannel of the other color is 1.0, then the other color will be fully blended with this color. If the alpha channel of the other color is 0.0, then the other color will not be blended with this color at all.

§Parameters
  • other - The other color to blend with.
source§

impl Color

source

pub fn set_r(&mut self, value: f32)

Set the red value of the color.

§Parameters
  • value - The new red value.
source

pub fn set_g(&mut self, value: f32)

Set the green value of the color.

§Parameters
  • value - The new green value.
source

pub fn set_b(&mut self, value: f32)

Set the blue value of the color.

§Parameters
  • value - The new blue value.
source

pub fn set_a(&mut self, value: f32)

Set the alpha value of the color.

§Parameters
  • value - The new alpha value.
source

pub fn set_rg(&mut self, value: &Vec2)

Sets the red and green components of this color.

§Parameters
  • value - The new red and green values.
source

pub fn set_gb(&mut self, value: &Vec2)

Sets the green and blue components of this color.

§Parameters
  • value - The new green and blue values.
source

pub fn set_ba(&mut self, value: &Vec2)

Sets the blue and alpha components of this color.

§Parameters
  • value - The new blue and alpha values.
source

pub fn set_rgb(&mut self, value: &Vec3)

Sets the red, green, and blue components of this color.

§Parameters
  • value - The new red, green, and blue values.
source

pub fn set_gba(&mut self, value: &Vec3)

Sets the green, blue, and alpha components of this color.

§Parameters
  • value - The new green, blue, and alpha values.
source§

impl Color

source

pub const fn as_vec4(&self) -> &Vec4

Convert this color to a Vec4.

source

pub fn as_mut_vec4(&mut self) -> &mut Vec4

Convert this color to a mutable Vec4.

source

pub const fn as_ptr(&self) -> *const f32

Convert this color to a pointer to f32

source

pub fn as_mut_ptr(&mut self) -> *mut f32

Convert this color to a mutable pointer to f32.

source

pub fn to_rgba32(&self) -> u32

Convert this color to a 32-bit RGB value.

source

pub fn to_rgba64(&self) -> u64

Convert this color to a 64-bit RGBA value.

source

pub fn to_argb32(&self) -> u32

Convert this color to a 32-bit ARGB value.

source

pub fn to_argb64(&self) -> u64

Convert this color to a 64-bit ARGB value.

Trait Implementations§

source§

impl AsMut<Vec4> for Color

source§

fn as_mut(&mut self) -> &mut Vec4

Converts this type into a mutable reference of the (usually inferred) input type.
source§

impl AsRef<Vec4> for Color

source§

fn as_ref(&self) -> &Vec4

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl Borrow<Vec4> for Color

source§

fn borrow(&self) -> &Vec4

Immutably borrows from an owned value. Read more
source§

impl BorrowMut<Vec4> for Color

source§

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

Mutably borrows from an owned value. Read more
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

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

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

impl From<&Vec3> for Color

source§

fn from(vec: &Vec3) -> Self

Converts to this type from the input type.
source§

impl From<&Vec4> for Color

source§

fn from(vec: &Vec4) -> Self

Converts to this type from the input type.
source§

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

source§

fn from((r, g, b): (f32, f32, f32)) -> Self

Converts to this type from the input type.
source§

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

source§

fn from((r, g, b, a): (f32, f32, f32, f32)) -> Self

Converts to this type from the input type.
source§

impl LowerHex for Color

source§

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

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

impl PartialEq for Color

source§

fn eq(&self, other: &Color) -> 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 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

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

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

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

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

impl Copy for Color

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> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> 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> 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>,

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.