Struct speedy2d::color::Color

source ·
pub struct Color { /* private fields */ }
Expand description

A struct representing a color with red, green, blue, and alpha components. Each component is stored as a float.

Implementations§

source§

impl Color

source

pub const TRANSPARENT: Color = _

Color constant for transparency, with the alpha value set to zero.

source

pub const BLACK: Color = _

Constant for the color black.

source

pub const WHITE: Color = _

Constant for the color white.

source

pub const RED: Color = _

Constant for the color red.

source

pub const GREEN: Color = _

Constant for the color green.

source

pub const BLUE: Color = _

Constant for the color blue.

source

pub const YELLOW: Color = _

Constant for the color yellow.

source

pub const CYAN: Color = _

Constant for the color cyan.

source

pub const MAGENTA: Color = _

Constant for the color magenta.

source

pub const GRAY: Color = _

Constant for the color gray.

source

pub const LIGHT_GRAY: Color = _

Constant for the color light gray.

source

pub const DARK_GRAY: Color = _

Constant for the color dark gray.

source

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

Creates a color with the specified components, including an alpha component. Each component should be in the range 0.0 to 1.0.

source

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

Creates a color with the specified components. The alpha component will be set to 1.0 (full opacity). Each component should be in the range 0.0 to 1.0.

source

pub fn from_int_rgba(r: u8, g: u8, b: u8, a: u8) -> Self

Creates a color with the specified components, including an alpha component. Each component should be in the range 0 to 255.

source

pub fn from_int_rgb(r: u8, g: u8, b: u8) -> Self

Creates a color with the specified components. The alpha component will be set to 255 (full opacity). Each component should be in the range 0 to 255.

source

pub fn from_hex_argb(argb: u32) -> Self

Creates a color from the specified integer value, including an alpha component.

For example, the input value 0xAABBCCDD will result in a color with:

  • Alpha = 0xAA
  • Red = 0xBB
  • Green = 0xCC
  • Blue = 0xDD

Note: If you don’t specify the alpha component, the color will be transparent.

source

pub fn from_hex_rgb(rgb: u32) -> Self

Creates a color from the specified integer value, with the alpha component set to 255 (full opacity).

For example, the input value 0xAABBCC will result in a color with:

  • Alpha = 0xFF
  • Red = 0xAA
  • Green = 0xBB
  • Blue = 0xCC

Note: if an alpha component is specified in the high bits of the integer, it will be ignored. See Color::from_hex_argb if you wish to specify the alpha component.

source

pub const fn from_gray(brightness: f32) -> Self

Creates a shade of gray from the specified float value, between 0.0 and 1.0. All three RGB components will be set to this value.

source

pub const fn r(&self) -> f32

Returns the red component of the color, as a value in the range 0.0 to 1.0.

source

pub const fn g(&self) -> f32

Returns the green component of the color, as a value in the range 0.0 to 1.0.

source

pub const fn b(&self) -> f32

Returns the blue component of the color, as a value in the range 0.0 to 1.0.

source

pub const fn a(&self) -> f32

Returns the alpha component of the color, as a value in the range 0.0 to 1.0. The value 0.0 is fully transparent, and the value 1.0 is fully opaque.

source

pub fn subjective_brightness(&self) -> f32

Returns the brightness of the color as perceived by a human, as a value in the range 0.0 to 1.0.

This is calculated using the following formula:

red * 0.299 + green * 0.587 + blue * 0.114

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 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 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,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere
    U: From<T>,

const: unstable · 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<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
source§

impl<T, U> TryFrom<U> for Twhere
    U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · 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.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.