#[repr(C)]
pub struct Color { pub r: f32, pub g: f32, pub b: f32, pub a: f32, }
Expand description

An RGBA color.

The components are stored as f32 values, which will generally be in the range of 0.0 to 1.0.

If your data is made up of bytes or hex values, this type provides constructors that will carry out the conversion for you.

The std arithmetic traits are implemented for this type, which allows you to add/subtract/multiply/divide colors.

Serde

Serialization and deserialization of this type (via Serde) can be enabled via the serde_support feature.

Fields

r: f32

The red component of the color.

g: f32

The green component of the color.

b: f32

The blue component of the color.

a: f32

The alpha component of the color.

Implementations

Creates a new Color, with the specified RGB values and the alpha set to 1.0.

Creates a new Color, with the specified RGBA values.

Creates a new Color, with the specified RGB integer (0-255) values and the alpha set to 255.

Creates a new Color, with the specified RGBA (0-255) integer values.

Creates a new Color using a hexidecimal color code, panicking if the input is invalid.

Six and eight digit codes can be used - the former will be interpreted as RGB, and the latter as RGBA. The # prefix (commonly used on the web) will be stripped if present.

Creates a new Color using a hexidecimal color code, returning an error if the input is invalid.

Six and eight digit codes can be used - the former will be interpreted as RGB, and the latter as RGBA. The # prefix (commonly used on the web) will be stripped if present.

Errors

Returns the color with the red component set to the specified value.

Returns the color with the green component set to the specified value.

Returns the color with the blue component set to the specified value.

Returns the color with the alpha component set to the specified value.

Returns the color with all components clamped between 0.0 and 1.0.

Returns the color with the RGB components multiplied by the alpha component.

This can be useful when working with premultiplied alpha blending, if you want to convert a non-premultiplied color into its premultiplied version.

Shortcut for Color::rgb(0.0, 0.0, 1.0)`](Self::rgb).

Trait Implementations

The resulting type after applying the + operator.

Performs the + operation. Read more

The resulting type after applying the + operator.

Performs the + operation. Read more

Performs the += operation. Read more

Performs the += operation. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

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

The resulting type after applying the / operator.

Performs the / operation. Read more

The resulting type after applying the / operator.

Performs the / operation. Read more

Performs the /= operation. Read more

Performs the /= operation. Read more

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

Performs the *= operation. Read more

Performs the *= operation. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

The resulting type after applying the - operator.

Performs the - operation. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

Performs the -= operation. Read more

Performs the -= operation. Read more

Can be accessed as a vec4 in your shader.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

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

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.