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

RGBA color with 32-bit floating point components.

Fields§

§r: f32§g: f32§b: f32§a: f32

Implementations§

source§

impl Color

source

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

source

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

source

pub fn from_hsv(h: f32, s: f32, v: f32) -> Color

source

pub fn from_hsva(h: f32, s: f32, v: f32, a: f32) -> Color

source

pub fn from_html(argb_or_rgb: &str) -> Option<Self>

Parses from a HTML color code, or None on parse error.

Note that unlike most other constructors, this has ARGB and not RGBA format. In particular, from_html("AB123456") would correspond to from_rgba_u32(0x123456AB).

use gdnative::prelude::Color;

let c1 = Color::from_html("#9eb2d90a"); // ARGB format with "#".
let c2 = Color::from_html("9eb2d90a");  // ARGB format.
let c3 = Color::from_html("#b2d90a");   // RGB format with "#".
let c4 = Color::from_html("b2d90a");    // RGB format.

let expected = Color::from_rgba_u8(0xb2, 0xd9, 0x0a, 0x9e);
assert_eq!(c1, Some(expected));
assert_eq!(c2, Some(expected));

let expected = Color::from_rgba_u8(0xb2, 0xd9, 0x0a, 0xff);
assert_eq!(c3, Some(expected));
assert_eq!(c4, Some(expected));

See also the corresponding GDScript method.

source

pub fn from_rgba_u32(rgba: u32) -> Self

Construct a color from a single u32 value, in RGBA format.

Example:

use gdnative::prelude::Color;

// RGBA (178, 217, 10, 158)
let one = Color::from_rgba_u32(0xb2d90a9e);
let piecewise = Color::from_rgba_u8(0xB2, 0xD9, 0x0A, 0x9E);
assert_eq!(one, piecewise);
source

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

Constructs a color from four integer channels, each in range 0-255.

This corresponds to the GDScript method Color8.

source

pub fn h(&self) -> f32

source

pub fn s(&self) -> f32

source

pub fn v(&self) -> f32

source

pub fn lerp(&self, other: Color, weight: f32) -> Color

source

pub fn blend(&self, other: &Color) -> Color

source

pub fn contrasted(&self) -> Color

source

pub fn darkened(&self, amount: f32) -> Color

source

pub fn gray(&self) -> f32

source

pub fn inverted(&self) -> Color

source

pub fn to_html(self, with_alpha: bool) -> GodotString

source

pub fn to_abgr32(self) -> u32

Returns the reverse of the RGBA32 byte representation for this color where each byte represents a component of the ABGR profile. This is the byte information used when storing this color as a part of a texture.

Endianness

On big endian architecture this is stored in ABGR byte order On little endian machines this is stored in RGBA byte order

Example

0x00FF7FFF would be the equivalent to Color::from_rgba(1.0, 0.5, 1.0, 0.0)

source

pub fn to_abgr64(self) -> u64

Returns the reverse of the RGBA64 byte representation for this color where each word represents represents a component of the ABGR profile. This is the byte information used when storing this color as a part of a texture.

Endianness

On big endian architecture this is stored in ABGR word order On little endian machines this is stored in RGBA word order

Example

0x0000FFFF7FFFFFFF would be the equivalent to Color::from_rgba(0.0, 1.0, 0.5, 1.0)

source

pub fn to_argb32(self) -> u32

Returns the ARGB32 format representation representation for this color where each byte represents a component of the ARGB profile. This is the byte information used when storing this color as a part of a texture.

Endianness

On big endian architecture this is stored in the order ARGB byte order On little endian machines this is stored in the order BGRA byte order 0x0000FFFF7FFFFFFF would be the equivalent to Color::from_rgba(1.0, 0.5, 1.0, 0.0)

source

pub fn to_argb64(self) -> u64

Returns the ARGB64 format representation for this color where each word represents a component of the ARGB profile. This is the byte information used when storing this color as a part of a texture.

Endianness

On big endian architecture this is stored in the order ARGB word order On little endian machines this is stored in the order BGRA word order

Example

0x0000FFFF7FFFFFFF would be the equivalent to Color::from_rgba(1.0, 0.5, 1.0, 0.0)

source

pub fn to_rgba32(self) -> u32

Returns the OpenGL Texture format byte representation for this color where each byte represents a component of the RGBA profile. This is the byte information used when storing this color as a part of a texture.

Endianness

On big endian architecture this is stored in RGBA byte order On little endian machines this is stored in ABGR byte order

Example

0x00FF7FFF would be the equivalent to Color::from_rgba(0.0, 1.0, 0.5, 1.0)

source

pub fn to_rgba64(self) -> u64

Returns the OpenGL Texture format byte representation for this color where each byte represents a component of the RGBA profile. This is the byte information used when storing this color as a part of a texture.

Endianness

On big endian architecture this is stored in RGBA word order On little endian machines this is stored in ABGR word order

Example

0x0000FFFF7FFFFFFF would be the equivalent to Color::from_rgba(0.0, 1.0, 0.5, 1.0)

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

source§

impl Debug for Color

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

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

impl Export for Color

§

type Hint = ColorHint

A type-specific hint type that is valid for the type being exported. Read more
source§

fn export_info(hint: Option<Self::Hint>) -> ExportInfo

Returns ExportInfo given an optional typed hint.
source§

impl FromVariant for Color

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

source§

impl Copy for Color

source§

impl PoolElement 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.

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.