Struct RGBA

Source
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§

Source§

impl RGBA

Source

pub fn new() -> RGBA

Constructs a new, zeroed (black) RGB triplet.

Source

pub fn from_f32(r: f32, g: f32, b: f32, a: f32) -> RGBA

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);
Source

pub fn from_u8(r: u8, g: u8, b: u8, a: u8) -> RGBA

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);
Source

pub fn named(col: (u8, u8, u8)) -> RGBA

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));
Source

pub fn from_hex<S>(code: S) -> Result<RGBA, HtmlColorConversionError>
where S: AsRef<str>,

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

Source

pub fn to_rgb(&self) -> RGB

Converts to an RGB, dropping the alpha component

Source

pub fn to_greyscale(&self) -> RGBA

Applies a quick grayscale conversion to the color

Source

pub fn desaturate(&self) -> RGBA

Applies a lengthier desaturate (via HSV) to the color

Source

pub fn lerp(&self, color: RGBA, percent: f32) -> RGBA

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

Source

pub fn lerp_alpha(&self, color: RGBA, percent: f32) -> RGBA

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

Trait Implementations§

Source§

impl Add<f32> for RGBA

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

Source§

type Output = RGBA

The resulting type after applying the + operator.
Source§

fn add(self, rhs: f32) -> RGBA

Performs the + operation. Read more
Source§

impl Add for RGBA

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

Source§

type Output = RGBA

The resulting type after applying the + operator.
Source§

fn add(self, rhs: RGBA) -> RGBA

Performs the + operation. Read more
Source§

impl Clone for RGBA

Source§

fn clone(&self) -> RGBA

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 RGBA

Source§

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

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

impl Default for RGBA

Source§

fn default() -> RGBA

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

impl From<[f32; 4]> for RGBA

Source§

fn from(item: [f32; 4]) -> RGBA

Converts to this type from the input type.
Source§

impl From<(u8, u8, u8)> for RGBA

Support conversion from a color tuple

Source§

fn from(vals: (u8, u8, u8)) -> RGBA

Converts to this type from the input type.
Source§

impl From<(u8, u8, u8, u8)> for RGBA

Support conversion from a color tuple

Source§

fn from(vals: (u8, u8, u8, u8)) -> RGBA

Converts to this type from the input type.
Source§

impl From<HSV> for RGBA

Support conversion from HSV

Source§

fn from(item: HSV) -> RGBA

Converts to this type from the input type.
Source§

impl From<RGB> for RGBA

Support conversion from RGB

Source§

fn from(item: RGB) -> RGBA

Converts to this type from the input type.
Source§

impl From<RGBA> for HSV

Support conversion from RGBA

Source§

fn from(rgba: RGBA) -> HSV

Converts to this type from the input type.
Source§

impl From<RGBA> for RGB

Support conversion from RGBA

Source§

fn from(item: RGBA) -> RGB

Converts to this type from the input type.
Source§

impl From<RGBA> for XpColor

Source§

fn from(rgb: RGBA) -> XpColor

Converts to this type from the input type.
Source§

impl From<XpColor> for RGBA

Source§

fn from(xp: XpColor) -> RGBA

Converts to this type from the input type.
Source§

impl Mul<f32> for RGBA

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

Source§

type Output = RGBA

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: f32) -> RGBA

Performs the * operation. Read more
Source§

impl Mul for RGBA

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

Source§

type Output = RGBA

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: RGBA) -> RGBA

Performs the * operation. Read more
Source§

impl PartialEq for RGBA

Source§

fn eq(&self, other: &RGBA) -> 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 Sub<f32> for RGBA

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

Source§

type Output = RGBA

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: f32) -> RGBA

Performs the - operation. Read more
Source§

impl Sub for RGBA

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

Source§

type Output = RGBA

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: RGBA) -> RGBA

Performs the - operation. Read more
Source§

impl Copy for RGBA

Source§

impl StructuralPartialEq for RGBA

Auto Trait Implementations§

§

impl Freeze for RGBA

§

impl RefUnwindSafe for RGBA

§

impl Send for RGBA

§

impl Sync for RGBA

§

impl Unpin for RGBA

§

impl UnwindSafe for RGBA

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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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, 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.