Struct ggez::graphics::Color

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

A RGBA color in the sRGB color space represented as f32’s in the range [0.0-1.0]

For convenience, several colors are provided: WHITE BLACK RED GREEN BLUE CYAN MAGENTA YELLOW

Fields§

§r: f32

Red component

§g: f32

Green component

§b: f32

Blue component

§a: f32

Alpha component

Implementations§

source§

impl Color

source

pub const WHITE: Color = _

White (#FFFFFFFF)

source

pub const BLACK: Color = _

Black (#000000FF)

source

pub const RED: Color = _

Red

source

pub const GREEN: Color = _

Green

source

pub const BLUE: Color = _

Blue

source

pub const CYAN: Color = _

Cyan

source

pub const MAGENTA: Color = _

Magenta

source

pub const YELLOW: Color = _

Yellow

source

pub const fn new(r: f32, g: f32, b: f32, a: f32) -> Self

Create a new Color from four f32’s in the range [0.0-1.0]

source

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

Create a new Color from four u8’s in the range [0-255]

source

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

Create a new Color from three u8’s in the range [0-255], with the alpha component fixed to 255 (opaque)

source

pub fn to_rgba(self) -> (u8, u8, u8, u8)

Return a tuple of four u8’s in the range [0-255] with the Color’s components.

source

pub fn to_rgb(self) -> (u8, u8, u8)

Return a tuple of three u8’s in the range [0-255] with the Color’s components.

source

pub fn from_rgba_u32(c: u32) -> Color

Convert a packed u32 containing 0xRRGGBBAA into a Color

source

pub fn from_rgb_u32(c: u32) -> Color

Convert a packed u32 containing 0x00RRGGBB into a Color. This lets you do things like Color::from_rgb_u32(0xCD09AA) easily if you want.

source

pub fn to_rgba_u32(self) -> u32

Convert a Color into a packed u32, containing 0xRRGGBBAA as bytes.

source

pub fn to_rgb_u32(self) -> u32

Convert a Color into a packed u32, containing 0x00RRGGBB as bytes.

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

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

impl<'de> Deserialize<'de> for Color

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,

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

impl From<[f32; 4]> for Color

source§

fn from(val: [f32; 4]) -> Self

Turns an [R, G, B, A] array of f32's into a Colorwith no format changes. All inputs should be in the range[0.0-1.0]`.

source§

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

source§

fn from(val: (f32, f32, f32)) -> Self

Convert a (R, G, B) tuple of f32’s in the range [0.0-1.0] into a Color, with a value of 1.0 to for the alpha element (ie, no transparency.)

source§

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

source§

fn from(val: (f32, f32, f32, f32)) -> Self

Convert a (R, G, B, A) tuple of f32’s in the range [0.0-1.0] into a Color

source§

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

source§

fn from(val: (u8, u8, u8)) -> Self

Convert a (R, G, B) tuple of u8’s in the range [0-255] into a Color, with a value of 255 for the alpha element (i.e., no transparency.)

source§

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

source§

fn from(val: (u8, u8, u8, u8)) -> Self

Convert a (R, G, B, A) tuple of u8’s in the range [0-255] into a Color

source§

impl From<Color> for [f32; 4]

source§

fn from(color: Color) -> Self

Convert a Color into an [R, G, B, A] array of f32’s in the range of [0.0-1.0].

source§

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

source§

fn from(color: Color) -> Self

Convert a Color into a (R, G, B) tuple of u8’s in the range of [0-255], ignoring the alpha term.

Does the Wrong Thing if the Color’s values are not in the range [0.0,1.0]

source§

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

source§

fn from(color: Color) -> Self

Convert a Color into a (R, G, B, A) tuple of u8’s in the range of [0-255].

Does the Wrong Thing if the Color’s values are not in the range [0.0,1.0]

source§

impl From<Color> for LinearColor

source§

fn from(c: Color) -> Self

Convert an (sRGB) Color into a linear color, per https://en.wikipedia.org/wiki/Srgb#The_reverse_transformation

source§

impl From<LinearColor> for Color

source§

fn from(c: LinearColor) -> Self

Converts to this type from the input type.
source§

impl PartialEq<Color> 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 Serialize for Color

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 Copy for Color

source§

impl StructuralPartialEq for Color

Auto Trait Implementations§

§

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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<S> FromSample<S> for S

§

fn from_sample_(s: S) -> S

source§

impl<T> Has<T> for T

source§

fn retrieve(&self) -> &T

Method to retrieve the context type.
source§

impl<T> HasMut<T> for T

source§

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

Method to retrieve the context type as mutable.
source§

impl<T, U> Into<U> for Twhere 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.

§

impl<F, T> IntoSample<T> for Fwhere T: FromSample<F>,

§

fn into_sample(self) -> T

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

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

Initializes a with the given initializer. Read more
§

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

Dereferences the given pointer. Read more
§

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

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

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

impl<T> ToOwned for Twhere 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
§

impl<T, U> ToSample<U> for Twhere U: FromSample<T>,

§

fn to_sample_(self) -> U

source§

impl<T, U> TryFrom<U> for Twhere 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 Twhere 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.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

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

§

impl<S, T> Duplex<S> for Twhere T: FromSample<S> + ToSample<S>,