Struct rltk::RGBA

[]
pub struct RGBA {
    pub r: f32,
    pub g: f32,
    pub b: f32,
    pub a: f32,
}
Expand description

Represents an R/G/B triplet, in the range 0..1 (32-bit float)

Fields

r: f32

The red component (0..1)

g: f32

The green component (0..1)

b: f32

The blue component (0..1)

a: f32

The alpha component (0..1), 0 is transparent, 1 is solid

Implementations

Constructs a new, zeroed (black) RGB triplet.

Constructs a new RGB color, from 3 32-bit floats in the range 0..1

Arguments
  • r - the red component (0..1)
  • g - the green component (0..1)
  • b - the blue component (0..1)
  • a - the alpha component (0..1). 0 is transparent, 1 is solid.
Example
use bracket_color::prelude::*;
let red = RGBA::from_f32(1.0, 0.0, 0.0, 1.0);
let green = RGBA::from_f32(0.0, 1.0, 0.0, 1.0);
let invisible = RGBA::from_f32(0.0, 0.0, 0.0, 0.0);

Constructs a new RGB color, from 3 bytes in the range 0..255

Arguments
  • r - the red component, ranged from 0 to 255
  • g - the green component, ranged from 0 to 255
  • b - the blue component, ranged from 0 to 255
Example
use bracket_color::prelude::*;
let red = RGBA::from_u8(255, 0, 0, 255);
let green = RGBA::from_u8(0, 255, 0, 255);
let invisible = RGBA::from_u8(0, 0, 0, 0);

Construct an RGB color from a tuple of u8, or a named constant

Arguments
  • col a tuple of three u8 values. See from_u8. These are usually provided from the named colors list.
Example
use bracket_color::prelude::*;
let red = RGBA::named(RED);
let green = RGBA::named((0, 255, 0));

Constructs from an HTML color code (e.g. “#eeffeeff”)

Arguments
  • code - an HTML color notation (e.g. “#ffeeffff”)
Example
use bracket_color::prelude::*;
let red = RGBA::from_hex("#FF0000FF");
let green = RGBA::from_hex("#00FF00FF");
Errors

See HtmlColorConversionError

Converts to an RGB, dropping the alpha component

Applies a quick grayscale conversion to the color

Applies a lengthier desaturate (via HSV) to the color

Lerps by a specified percentage (from 0 to 1) between this color and another

Lerps only the alpha channel, by a specified percentage (from 0 to 1) between this color and another

Trait Implementations

Support adding an RGB to a color. The result is clamped via the constructor.

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

Support adding a float to a color. The result is clamped via the constructor.

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.

Support conversion from a color tuple

Converts to this type from the input type.

Support conversion from a color tuple

Converts to this type from the input type.

Support conversion from HSV

Converts to this type from the input type.

Support conversion from RGB

Converts to this type from the input type.

Support conversion from RGBA

Converts to this type from the input type.

Support conversion from RGBA

Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.

Support multiplying a color by another color. The result is clamped via the constructor.

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

Support multiplying a color by a float. The result is clamped via the constructor.

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 ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

Support subtracting an RGB from a color. The result is clamped via the constructor.

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

Support subtracting a float from a color. The result is clamped via the constructor.

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.