Struct sfml::graphics::Color

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

Utility type for manpulating RGBA colors

Color is a simple color type composed of 4 components: Red, Green, Blue, Alpha

Example

There are 3 basic ways to construct a color

use sfml::graphics::Color;
let color1 = Color::rgb(255, 0, 0); // from red/green/blue values
let color2 = Color::rgba(255, 255, 255, 128); // from red/green/blue/alpha (transparency)
let color3 = Color::GREEN; // from one of the associated color constants

Fields§

§r: u8

Red component

§g: u8

Green component

§b: u8

Blue component

§a: u8

Alpha component (transparency)

Implementations§

Construct a color from its 3 RGB components

Arguments
  • red - Red component (0 .. 255)
  • green - -Green component (0 .. 255)
  • blue - Blue component (0 .. 255)

Return Color object constructed from the components

Construct a color from its 4 RGBA components

Arguments
  • red - Red component (0 .. 255)
  • green - -Green component (0 .. 255)
  • blue - Blue component (0 .. 255)
  • alpha - Alpha component (0 .. 255)

Return Color object constructed from the components

Black predefined color

White predefined color

Red predefined color

Green predefined color

Blue predefined color

Yellow predefined color

Magenta predefined color

Cyan predifined color

Tranparent predefined color

Trait Implementations§

Calculate the component-wise saturated addition of two colors.

The resulting type after applying the + operator.
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
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.

Construct the color from 32-bit unsigned integer.

The number should contain the components in RGBA order.

Calculate the component-wise modulated multiplication of two colors.

For each X in rgba, result.X = a.X * b.X / 255.

The resulting type after applying the * operator.
Performs the *= operation. Read more
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Component-wise subtraction of two colors. Components below 0 are clamped to 0.

The resulting type after applying the - operator.
Performs the -= operation. Read more

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 resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
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.