godot::prelude

Struct Color

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

Color built-in type, in floating-point RGBA format.

Channel values are typically in the range of 0 to 1, but this is not a requirement, and values outside this range are explicitly allowed for e.g. High Dynamic Range (HDR).

To access its HSVA representation, use Color::to_hsv.

§Godot docs

Color (stable)

Fields§

§r: f32

The color’s red component.

§g: f32

The color’s green component.

§b: f32

The color’s blue component.

§a: f32

The color’s alpha component. A value of 0 means that the color is fully transparent. A value of 1 means that the color is fully opaque.

Implementations§

Source§

impl Color

Source

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

Constructs a new Color with the given components.

Source

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

Constructs a new Color with the given color components, and the alpha channel set to 1.

Source

pub fn from_rgba8(r: u8, g: u8, b: u8, a: u8) -> Color

Constructs a new Color with the given components as bytes. 0 is mapped to 0.0, 255 is mapped to 1.0.

Godot equivalent: the global Color8 function

Source

pub fn from_rgba16(r: u16, g: u16, b: u16, a: u16) -> Color

Constructs a new Color with the given components as u16 words. 0 is mapped to 0.0, 65535 (0xffff) is mapped to 1.0.

Source

pub fn from_u32_rgba(u: u32, order: ColorChannelOrder) -> Color

Constructs a new Color from a 32-bits value with the given channel order.

Godot equivalent: Color.hex, if ColorChannelOrder::Rgba is used

Source

pub fn from_u64_rgba(u: u64, order: ColorChannelOrder) -> Color

Constructs a new Color from a 64-bits value with the given channel order.

Godot equivalent: Color.hex64, if ColorChannelOrder::Rgba is used

Source

pub fn from_html<S>(html: S) -> Option<Color>
where S: AsArg<GString>,

Constructs a Color from an HTML color code string. Valid values for the string are:

  • #RRGGBBAA and RRGGBBAA where each of RR, GG, BB and AA stands for two hex digits (case insensitive).
  • #RRGGBB and RRGGBB. Equivalent to #RRGGBBff.
  • #RGBA and RGBA where each of R, G, B and A stands for a single hex digit. Equivalent to #RRGGBBAA, i.e. each digit is repeated twice.
  • #RGB and RGB. Equivalent to #RRGGBBff.

Returns None if the format is invalid.

Source

pub fn from_string(string: impl AsArg<GString>) -> Option<Color>

Constructs a Color from a string, which can be either:

  • An HTML color code as accepted by Color::from_html.
  • The name of a built-in color constant, such as BLUE or lawn-green. Matching is case-insensitive and hyphens can be used interchangeably with underscores. See the list of color constants in the Godot API documentation, or the visual cheat sheet for the full list.

Returns None if the string is neither a valid HTML color code nor an existing color name.

Most color constants have an alpha of 1; use Color::with_alpha to change it.

Source

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

Constructs a Color from an HSV profile using Godot’s builtin method. The hue (h), saturation (s), and value (v) are typically between 0.0 and 1.0. Alpha is set to 1; use Color::with_alpha to change it.

See also: ColorHsv::to_rgb for fast conversion on Rust side.

Source

pub fn from_ok_hsl(h: f64, s: f64, l: f64) -> Color

Constructs a Color from an OK HSL profile. The hue (h), saturation (s), and lightness (l) are typically between 0.0 and 1.0. Alpha is set to 1; use Color::with_alpha to change it.

Source

pub fn from_rgbe9995(rgbe: u32) -> Color

Constructs a Color from an RGBE9995 format integer. This is a special OpenGL texture format where the three color components have 9 bits of precision and all three share a single 5-bit exponent.

Source

pub fn with_alpha(self, a: f32) -> Color

Returns a copy of this color with the given alpha value. Useful for chaining with constructors like Color::from_string and Color::from_hsv.

Source

pub fn r8(self) -> u8

Returns the red channel value as a byte. If self.r is outside the range from 0 to 1, the returned byte is clamped.

Source

pub fn g8(self) -> u8

Returns the green channel value as a byte. If self.g is outside the range from 0 to 1, the returned byte is clamped.

Source

pub fn b8(self) -> u8

Returns the blue channel value as a byte. If self.b is outside the range from 0 to 1, the returned byte is clamped.

Source

pub fn a8(self) -> u8

Returns the alpha channel value as a byte. If self.a is outside the range from 0 to 1, the returned byte is clamped.

Source

pub fn set_r8(&mut self, r: u8)

Sets the red channel value as a byte, mapped to the range from 0 to 1.

Source

pub fn set_g8(&mut self, g: u8)

Sets the green channel value as a byte, mapped to the range from 0 to 1.

Source

pub fn set_b8(&mut self, b: u8)

Sets the blue channel value as a byte, mapped to the range from 0 to 1.

Source

pub fn set_a8(&mut self, a: u8)

Sets the alpha channel value as a byte, mapped to the range from 0 to 1.

Source

pub fn luminance(self) -> f64

Returns the light intensity of the color, as a value between 0.0 and 1.0 (inclusive). This is useful when determining whether a color is light or dark. Colors with a luminance smaller than 0.5 can be generally considered dark.

Note: luminance relies on the color being in the linear color space to return an accurate relative luminance value. If the color is in the sRGB color space, use Color::srgb_to_linear to convert it to the linear color space first.

Source

pub fn blend(self, over: Color) -> Color

Blends the given color on top of this color, taking its alpha into account.

Source

pub fn lerp(self, to: Color, weight: f64) -> Color

Returns the linear interpolation between self’s components and to’s components. The interpolation factor weight should be between 0.0 and 1.0 (inclusive).

Source

pub fn clamp(self, min: Color, max: Color) -> Color

Returns a new color with all components clamped between the components of min and max.

Source

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

Creates a new color resulting by making this color darker by the specified amount (ratio from 0.0 to 1.0). See also lightened.

Source

pub fn lightened(self, amount: f64) -> Color

Creates a new color resulting by making this color lighter by the specified amount, which should be a ratio from 0.0 to 1.0. See also darkened.

Source

pub fn inverted(self) -> Color

Returns the color with its r, g, and b components inverted: Color::from_rgba(1 - r, 1 - g, 1 - b, a).

Source

pub fn linear_to_srgb(self) -> Color

Returns the color converted to the sRGB color space. This method assumes the original color is in the linear color space. See also Color::srgb_to_linear which performs the opposite operation.

Source

pub fn srgb_to_linear(self) -> Color

Returns the color converted to the linear color space. This method assumes the original color is in the sRGB color space. See also Color::linear_to_srgb which performs the opposite operation.

Source

pub fn to_html(self) -> GString

Returns the HTML color code representation of this color, as 8 lowercase hex digits in the order RRGGBBAA, without the # prefix.

Source

pub fn to_html_without_alpha(self) -> GString

Returns the HTML color code representation of this color, as 6 lowercase hex digits in the order RRGGBB, without the # prefix. The alpha channel is ignored.

Source

pub fn to_u32(self, order: ColorChannelOrder) -> u32

Returns the color converted to a 32-bit integer (each component is 8 bits) with the given order of channels (from most to least significant byte).

Source

pub fn to_u64(self, order: ColorChannelOrder) -> u64

Returns the color converted to a 64-bit integer (each component is 16 bits) with the given order of channels (from most to least significant word).

Source

pub fn to_hsv(self) -> ColorHsv

⚠️ Convert Color into ColorHsv.

§Panics

Method will panic if the RGBA values are outside the valid range 0.0..=1.0. You can use Color::normalized to ensure that they are in range, or use Color::try_to_hsv.

Source

pub fn try_to_hsv(self) -> Result<ColorHsv, String>

Fallible Color conversion into ColorHsv. See also Color::to_hsv.

Source

pub fn normalized(self) -> Color

Clamps all components to a usually valid range 0.0..=1.0.

Useful for transformations between different color representations.

Source§

impl Color

Godot’s predefined colors.

This visual cheat sheet shows how the colors look.

Source

pub const TRANSPARENT_BLACK: Color

Transparent black.

This color is not provided by Godot, so Color::from_string("TRANSPARENT_BLACK") will be None.

Source

pub const TRANSPARENT_WHITE: Color

Transparent white.

This color is not provided by Godot, so Color::from_string("TRANSPARENT_WHITE") will be None. Use Color::from_string("TRANSPARENT") instead.

Godot equivalent: Color.TRANSPARENT

Source

pub const BLACK: Color

Black color. This is the default value.

Source

pub const WHITE: Color

Source

pub const ALICE_BLUE: Color

Source

pub const ANTIQUE_WHITE: Color

Source

pub const AQUA: Color

Source

pub const AQUAMARINE: Color

Source

pub const AZURE: Color

Source

pub const BEIGE: Color

Source

pub const BISQUE: Color

Source

pub const BLANCHED_ALMOND: Color

Source

pub const BLUE: Color

Source

pub const BLUE_VIOLET: Color

Source

pub const BROWN: Color

Source

pub const BURLYWOOD: Color

Source

pub const CADET_BLUE: Color

Source

pub const CHARTREUSE: Color

Source

pub const CHOCOLATE: Color

Source

pub const CORAL: Color

Source

pub const CORNFLOWER_BLUE: Color

Source

pub const CORNSILK: Color

Source

pub const CRIMSON: Color

Source

pub const CYAN: Color

Source

pub const DARK_BLUE: Color

Source

pub const DARK_CYAN: Color

Source

pub const DARK_GOLDENROD: Color

Source

pub const DARK_GRAY: Color

Source

pub const DARK_GREEN: Color

Source

pub const DARK_KHAKI: Color

Source

pub const DARK_MAGENTA: Color

Source

pub const DARK_OLIVE_GREEN: Color

Source

pub const DARK_ORANGE: Color

Source

pub const DARK_ORCHID: Color

Source

pub const DARK_RED: Color

Source

pub const DARK_SALMON: Color

Source

pub const DARK_SEA_GREEN: Color

Source

pub const DARK_SLATE_BLUE: Color

Source

pub const DARK_SLATE_GRAY: Color

Source

pub const DARK_TURQUOISE: Color

Source

pub const DARK_VIOLET: Color

Source

pub const DEEP_PINK: Color

Source

pub const DEEP_SKY_BLUE: Color

Source

pub const DIM_GRAY: Color

Source

pub const DODGER_BLUE: Color

Source

pub const FIREBRICK: Color

Source

pub const FLORAL_WHITE: Color

Source

pub const FOREST_GREEN: Color

Source

pub const FUCHSIA: Color

Source

pub const GAINSBORO: Color

Source

pub const GHOST_WHITE: Color

Source

pub const GOLD: Color

Source

pub const GOLDENROD: Color

Source

pub const GRAY: Color

Source

pub const GREEN: Color

Source

pub const GREEN_YELLOW: Color

Source

pub const HONEYDEW: Color

Source

pub const HOT_PINK: Color

Source

pub const INDIAN_RED: Color

Source

pub const INDIGO: Color

Source

pub const IVORY: Color

Source

pub const KHAKI: Color

Source

pub const LAVENDER: Color

Source

pub const LAVENDER_BLUSH: Color

Source

pub const LAWN_GREEN: Color

Source

pub const LEMON_CHIFFON: Color

Source

pub const LIGHT_BLUE: Color

Source

pub const LIGHT_CORAL: Color

Source

pub const LIGHT_CYAN: Color

Source

pub const LIGHT_GOLDENROD: Color

Source

pub const LIGHT_GRAY: Color

Source

pub const LIGHT_GREEN: Color

Source

pub const LIGHT_PINK: Color

Source

pub const LIGHT_SALMON: Color

Source

pub const LIGHT_SEA_GREEN: Color

Source

pub const LIGHT_SKY_BLUE: Color

Source

pub const LIGHT_SLATE_GRAY: Color

Source

pub const LIGHT_STEEL_BLUE: Color

Source

pub const LIGHT_YELLOW: Color

Source

pub const LIME: Color

Source

pub const LIME_GREEN: Color

Source

pub const LINEN: Color

Source

pub const MAGENTA: Color

Source

pub const MAROON: Color

Source

pub const MEDIUM_AQUAMARINE: Color

Source

pub const MEDIUM_BLUE: Color

Source

pub const MEDIUM_ORCHID: Color

Source

pub const MEDIUM_PURPLE: Color

Source

pub const MEDIUM_SEA_GREEN: Color

Source

pub const MEDIUM_SLATE_BLUE: Color

Source

pub const MEDIUM_SPRING_GREEN: Color

Source

pub const MEDIUM_TURQUOISE: Color

Source

pub const MEDIUM_VIOLET_RED: Color

Source

pub const MIDNIGHT_BLUE: Color

Source

pub const MINT_CREAM: Color

Source

pub const MISTY_ROSE: Color

Source

pub const MOCCASIN: Color

Source

pub const NAVAJO_WHITE: Color

Source

pub const NAVY_BLUE: Color

Source

pub const OLD_LACE: Color

Source

pub const OLIVE: Color

Source

pub const OLIVE_DRAB: Color

Source

pub const ORANGE: Color

Source

pub const ORANGE_RED: Color

Source

pub const ORCHID: Color

Source

pub const PALE_GOLDENROD: Color

Source

pub const PALE_GREEN: Color

Source

pub const PALE_TURQUOISE: Color

Source

pub const PALE_VIOLET_RED: Color

Source

pub const PAPAYA_WHIP: Color

Source

pub const PEACH_PUFF: Color

Source

pub const PERU: Color

Source

pub const PINK: Color

Source

pub const PLUM: Color

Source

pub const POWDER_BLUE: Color

Source

pub const PURPLE: Color

Source

pub const REBECCA_PURPLE: Color

Source

pub const RED: Color

Source

pub const ROSY_BROWN: Color

Source

pub const ROYAL_BLUE: Color

Source

pub const SADDLE_BROWN: Color

Source

pub const SALMON: Color

Source

pub const SANDY_BROWN: Color

Source

pub const SEA_GREEN: Color

Source

pub const SEASHELL: Color

Source

pub const SIENNA: Color

Source

pub const SILVER: Color

Source

pub const SKY_BLUE: Color

Source

pub const SLATE_BLUE: Color

Source

pub const SLATE_GRAY: Color

Source

pub const SNOW: Color

Source

pub const SPRING_GREEN: Color

Source

pub const STEEL_BLUE: Color

Source

pub const TAN: Color

Source

pub const TEAL: Color

Source

pub const THISTLE: Color

Source

pub const TOMATO: Color

Source

pub const TURQUOISE: Color

Source

pub const VIOLET: Color

Source

pub const WEB_GRAY: Color

Source

pub const WEB_GREEN: Color

Source

pub const WEB_MAROON: Color

Source

pub const WEB_PURPLE: Color

Source

pub const WHEAT: Color

Source

pub const WHITE_SMOKE: Color

Source

pub const YELLOW: Color

Source

pub const YELLOW_GREEN: Color

Trait Implementations§

Source§

impl Add for Color

Source§

type Output = Color

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Color) -> <Color as Add>::Output

Performs the + operation. Read more
Source§

impl AddAssign for Color

Source§

fn add_assign(&mut self, rhs: Color)

Performs the += operation. Read more
Source§

impl ApproxEq for Color

Source§

fn approx_eq(&self, other: &Color) -> bool

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<(), Error>

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

impl Default for Color

Constructs a default Color which is opaque black.

Source§

fn default() -> Color

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

impl Display for Color

Source§

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

Formats Color to match Godot’s string representation.

§Example
use godot::prelude::*;
let color = Color::from_rgba(1.0, 1.0, 1.0, 1.0);
assert_eq!(format!("{}", color), "(1, 1, 1, 1)");
Source§

impl Div for Color

Source§

type Output = Color

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Color) -> <Color as Div>::Output

Performs the / operation. Read more
Source§

impl DivAssign for Color

Source§

fn div_assign(&mut self, rhs: Color)

Performs the /= operation. Read more
Source§

impl Export for Color

Source§

fn export_hint() -> PropertyHintInfo

The export info to use for an exported field of this type, if no other export info is specified.
Source§

impl Extend<Color> for PackedColorArray

Extends aPackedColorArray with the contents of an iterator

Source§

fn extend<I>(&mut self, iter: I)
where I: IntoIterator<Item = Color>,

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl FromGodot for Color

Source§

fn try_from_godot( via: <Color as GodotConvert>::Via, ) -> Result<Color, ConvertError>

Converts the Godot representation to this type, returning Err on failure.
Source§

fn from_godot(via: Self::Via) -> Self

⚠️ Converts the Godot representation to this type. Read more
Source§

fn try_from_variant(variant: &Variant) -> Result<Self, ConvertError>

Performs the conversion from a Variant, returning Err on failure.
Source§

fn from_variant(variant: &Variant) -> Self

⚠️ Performs the conversion from a Variant. Read more
Source§

impl FromIterator<Color> for PackedColorArray

Creates a PackedColorArray from an iterator.

Source§

fn from_iter<I>(iter: I) -> PackedColorArray
where I: IntoIterator<Item = Color>,

Creates a value from an iterator. Read more
Source§

impl GodotConvert for Color

Source§

type Via = Color

The type through which Self is represented in Godot.
Source§

impl Mul<f32> for Color

Source§

type Output = Color

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: f32) -> <Color as Mul<f32>>::Output

Performs the * operation. Read more
Source§

impl Mul for Color

Source§

type Output = Color

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Color) -> <Color as Mul>::Output

Performs the * operation. Read more
Source§

impl MulAssign<f32> for Color

Source§

fn mul_assign(&mut self, f: f32)

Performs the *= operation. Read more
Source§

impl MulAssign for Color

Source§

fn mul_assign(&mut self, rhs: Color)

Performs the *= operation. Read more
Source§

impl Neg for Color

Source§

type Output = Color

The resulting type after applying the - operator.
Source§

fn neg(self) -> Color

Performs the unary - operation. Read more
Source§

impl ParamType for Color

Source§

fn owned_to_arg<'v>(self) -> <Color as ParamType>::Arg<'v>

Converts an owned value to the canonical argument type, which can be passed to impl AsArg<T>. Read more
Source§

impl PartialEq for Color

Source§

fn eq(&self, other: &Color) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Color

Source§

fn partial_cmp(&self, other: &Color) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Sub for Color

Source§

type Output = Color

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Color) -> <Color as Sub>::Output

Performs the - operation. Read more
Source§

impl SubAssign for Color

Source§

fn sub_assign(&mut self, rhs: Color)

Performs the -= operation. Read more
Source§

impl ToGodot for Color

Source§

type ToVia<'v> = <Color as GodotConvert>::Via

Target type of to_godot(), which can differ from Via for pass-by-reference types. Read more
Source§

fn to_godot(&self) -> <Color as ToGodot>::ToVia<'_>

Converts this type to the Godot type by reference, usually by cloning.
Source§

fn to_variant(&self) -> Variant

Converts this type to a Variant.
Source§

impl Var for Color

Source§

fn get_property(&self) -> <Color as GodotConvert>::Via

Source§

fn set_property(&mut self, value: <Color as GodotConvert>::Via)

Source§

fn var_hint() -> PropertyHintInfo

Specific property hints, only override if they deviate from GodotType::property_info, e.g. for enums/newtypes.
Source§

impl ArrayElement for Color

Source§

impl AsArg<Color> for Color

Source§

impl Copy for Color

Source§

impl GodotType for Color

Source§

impl PackedArrayElement for Color

Source§

impl StructuralPartialEq for Color

Auto Trait Implementations§

§

impl Freeze for Color

§

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 T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

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 T
where T: Clone,

Source§

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.