Struct geng::prelude::Rgba

#[repr(C)]
pub struct Rgba<T>
where T: ColorComponent,
{ pub r: T, pub g: T, pub b: T, pub a: T, }
Expand description

RGBA Color

Fields§

§r: T

Red component

§g: T

Green component

§b: T

Blue component

§a: T

Alpha (opacity) component

Implementations§

§

impl<T> Rgba<T>
where T: ColorComponent,

pub const WHITE: Rgba<T> = _

#FFF

pub const BLACK: Rgba<T> = _

#000

pub const GRAY: Rgba<T> = _

#7F7F7F

pub const TRANSPARENT_WHITE: Rgba<T> = _

rgba(255, 255, 255, 0)

pub const TRANSPARENT_BLACK: Rgba<T> = _

rgba(0, 0, 0, 0)

pub const RED: Rgba<T> = _

#F00

pub const GREEN: Rgba<T> = _

#0F0

pub const BLUE: Rgba<T> = _

#00F

pub const CYAN: Rgba<T> = _

#0FF

pub const MAGENTA: Rgba<T> = _

#F0F

pub const YELLOW: Rgba<T> = _

#FF0

§

impl<T> Rgba<T>
where T: ColorComponent,

pub fn opaque(r: T, g: T, b: T) -> Rgba<T>

Construct Rgba from red, green, and blue components, fully opaque (max alpha).

pub fn new(r: T, g: T, b: T, a: T) -> Rgba<T>

Construct Rgba from red, green, blue, and alpha components.

pub fn to_vec4(self) -> vec4<T>

Convert color into vec4(r, g, b, a)

pub fn from_vec4(_: vec4<T>) -> Rgba<T>

Convert vec4(r, g, b, a) into color

pub fn map_rgb<F, U>(self, f: F) -> Rgba<U>
where F: Fn(T) -> U, U: ColorComponent,

Convert Rgba<T> to Rgba<U> by applying a function to every color component excluding alpha. The resulting alpha is calculated by applying ColorComponent::convert() method.

§Examples
let initial = Rgba::new(0.7, 0.4, 1.0, 1.0);
let f = |component: f32| component / 2.0;
assert_eq!(initial.map_rgb(f), Rgba::new(0.35, 0.2, 0.5, 1.0));

pub fn map<F, U>(self, f: F) -> Rgba<U>
where F: Fn(T) -> U, U: ColorComponent,

Convert Rgba<T> to Rgba<U> by applying a function to every color component.

§Examples
let initial = Rgba::new(0.7, 0.4, 1.0, 1.0);
let f = |component: f32| component / 2.0;
assert_eq!(initial.map(f), Rgba::new(0.35, 0.2, 0.5, 0.5));

pub fn zip_map<F, U, V>(self, other: Rgba<U>, f: F) -> Rgba<V>
where F: Fn(T, U) -> V, U: ColorComponent, V: ColorComponent,

Applies a function to every component of two colors and produces a new color.

§Examples
let a = Rgba::new(0.2, 0.1, 0.3, 0.6);
let b = Rgba::new(0.5, 0.3, 0.2, 0.2);
let f = |a: f32, b: f32| a + b;
assert_eq!(a.zip_map(b, f), Rgba::new(0.7, 0.4, 0.5, 0.8));

pub fn convert<U>(self) -> Rgba<U>
where U: ColorComponent,

Convert Rgba<T> to Rgba<U> by applying ColorComponent::convert() method.

§Examples
assert_eq!(Rgba::opaque(0, 255, 0).convert(), Rgba::opaque(0.0, 1.0, 0.0));

pub fn lerp(start: Rgba<T>, end: Rgba<T>, t: f32) -> Rgba<T>

Linearly interpolate between start and end values.

§Examples
let start = Rgba::opaque(0.0, 0.0, 0.0);
let end = Rgba::opaque(1.0, 1.0, 1.0);
let interpolated = Rgba::lerp(start, end, 0.3);
assert!(interpolated.r - 0.3 < 1e-5);
assert!(interpolated.g - 0.3 < 1e-5);
assert!(interpolated.b - 0.3 < 1e-5);
assert_eq!(interpolated.a, 1.0);

Methods from Deref<Target = [T; 4]>§

1.57.0 · source

pub fn as_slice(&self) -> &[T]

Returns a slice containing the entire array. Equivalent to &s[..].

1.57.0 · source

pub fn as_mut_slice(&mut self) -> &mut [T]

Returns a mutable slice containing the entire array. Equivalent to &mut s[..].

source

pub fn each_ref(&self) -> [&T; N]

🔬This is a nightly-only experimental API. (array_methods)

Borrows each element and returns an array of references with the same size as self.

§Example
#![feature(array_methods)]

let floats = [3.1, 2.7, -1.0];
let float_refs: [&f64; 3] = floats.each_ref();
assert_eq!(float_refs, [&3.1, &2.7, &-1.0]);

This method is particularly useful if combined with other methods, like map. This way, you can avoid moving the original array if its elements are not Copy.

#![feature(array_methods)]

let strings = ["Ferris".to_string(), "♥".to_string(), "Rust".to_string()];
let is_ascii = strings.each_ref().map(|s| s.is_ascii());
assert_eq!(is_ascii, [true, false, true]);

// We can still access the original array: it has not been moved.
assert_eq!(strings.len(), 3);
source

pub fn each_mut(&mut self) -> [&mut T; N]

🔬This is a nightly-only experimental API. (array_methods)

Borrows each element mutably and returns an array of mutable references with the same size as self.

§Example
#![feature(array_methods)]

let mut floats = [3.1, 2.7, -1.0];
let float_refs: [&mut f64; 3] = floats.each_mut();
*float_refs[0] = 0.0;
assert_eq!(float_refs, [&mut 0.0, &mut 2.7, &mut -1.0]);
assert_eq!(floats, [0.0, 2.7, -1.0]);
source

pub fn split_array_ref<const M: usize>(&self) -> (&[T; M], &[T])

🔬This is a nightly-only experimental API. (split_array)

Divides one array reference into two at an index.

The first will contain all indices from [0, M) (excluding the index M itself) and the second will contain all indices from [M, N) (excluding the index N itself).

§Panics

Panics if M > N.

§Examples
#![feature(split_array)]

let v = [1, 2, 3, 4, 5, 6];

{
   let (left, right) = v.split_array_ref::<0>();
   assert_eq!(left, &[]);
   assert_eq!(right, &[1, 2, 3, 4, 5, 6]);
}

{
    let (left, right) = v.split_array_ref::<2>();
    assert_eq!(left, &[1, 2]);
    assert_eq!(right, &[3, 4, 5, 6]);
}

{
    let (left, right) = v.split_array_ref::<6>();
    assert_eq!(left, &[1, 2, 3, 4, 5, 6]);
    assert_eq!(right, &[]);
}
source

pub fn split_array_mut<const M: usize>(&mut self) -> (&mut [T; M], &mut [T])

🔬This is a nightly-only experimental API. (split_array)

Divides one mutable array reference into two at an index.

The first will contain all indices from [0, M) (excluding the index M itself) and the second will contain all indices from [M, N) (excluding the index N itself).

§Panics

Panics if M > N.

§Examples
#![feature(split_array)]

let mut v = [1, 0, 3, 0, 5, 6];
let (left, right) = v.split_array_mut::<2>();
assert_eq!(left, &mut [1, 0][..]);
assert_eq!(right, &mut [3, 0, 5, 6]);
left[1] = 2;
right[1] = 4;
assert_eq!(v, [1, 2, 3, 4, 5, 6]);
source

pub fn rsplit_array_ref<const M: usize>(&self) -> (&[T], &[T; M])

🔬This is a nightly-only experimental API. (split_array)

Divides one array reference into two at an index from the end.

The first will contain all indices from [0, N - M) (excluding the index N - M itself) and the second will contain all indices from [N - M, N) (excluding the index N itself).

§Panics

Panics if M > N.

§Examples
#![feature(split_array)]

let v = [1, 2, 3, 4, 5, 6];

{
   let (left, right) = v.rsplit_array_ref::<0>();
   assert_eq!(left, &[1, 2, 3, 4, 5, 6]);
   assert_eq!(right, &[]);
}

{
    let (left, right) = v.rsplit_array_ref::<2>();
    assert_eq!(left, &[1, 2, 3, 4]);
    assert_eq!(right, &[5, 6]);
}

{
    let (left, right) = v.rsplit_array_ref::<6>();
    assert_eq!(left, &[]);
    assert_eq!(right, &[1, 2, 3, 4, 5, 6]);
}
source

pub fn rsplit_array_mut<const M: usize>(&mut self) -> (&mut [T], &mut [T; M])

🔬This is a nightly-only experimental API. (split_array)

Divides one mutable array reference into two at an index from the end.

The first will contain all indices from [0, N - M) (excluding the index N - M itself) and the second will contain all indices from [N - M, N) (excluding the index N itself).

§Panics

Panics if M > N.

§Examples
#![feature(split_array)]

let mut v = [1, 0, 3, 0, 5, 6];
let (left, right) = v.rsplit_array_mut::<4>();
assert_eq!(left, &mut [1, 0]);
assert_eq!(right, &mut [3, 0, 5, 6][..]);
left[1] = 2;
right[1] = 4;
assert_eq!(v, [1, 2, 3, 4, 5, 6]);
source

pub fn as_ascii(&self) -> Option<&[AsciiChar; N]>

🔬This is a nightly-only experimental API. (ascii_char)

Converts this array of bytes into a array of ASCII characters, or returns None if any of the characters is non-ASCII.

§Examples
#![feature(ascii_char)]
#![feature(const_option)]

const HEX_DIGITS: [std::ascii::Char; 16] =
    *b"0123456789abcdef".as_ascii().unwrap();

assert_eq!(HEX_DIGITS[1].as_str(), "1");
assert_eq!(HEX_DIGITS[10].as_str(), "a");
source

pub unsafe fn as_ascii_unchecked(&self) -> &[AsciiChar; N]

🔬This is a nightly-only experimental API. (ascii_char)

Converts this array of bytes into a array of ASCII characters, without checking whether they’re valid.

§Safety

Every byte in the array must be in 0..=127, or else this is UB.

Trait Implementations§

§

impl<T> Approx for Rgba<T>

§

fn approx_distance_to(&self, other: &Rgba<T>) -> f32

Get an approximated distance between two values
§

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

Check if values are approximately equal using DEFAULT_EPS
§

fn approx_eq_eps(&self, other: &Self, eps: f32) -> bool

Check if values are approximately equal using supplied eps value
§

impl<T> Clone for Rgba<T>
where T: Clone + ColorComponent,

§

fn clone(&self) -> Rgba<T>

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
§

impl<T> Debug for Rgba<T>
where T: Debug + ColorComponent,

§

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

Formats the value using the given formatter. Read more
§

impl<T> Deref for Rgba<T>
where T: ColorComponent,

§

type Target = [T; 4]

The resulting type after dereferencing.
§

fn deref(&self) -> &[T; 4]

Dereferences the value.
§

impl<T> DerefMut for Rgba<T>
where T: ColorComponent,

§

fn deref_mut(&mut self) -> &mut [T; 4]

Mutably dereferences the value.
§

impl<'de, T> Deserialize<'de> for Rgba<T>
where T: ColorComponent + Deserialize<'de>,

§

fn deserialize<__D>( __deserializer: __D ) -> Result<Rgba<T>, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
§

impl<T> Display for Rgba<T>
where T: ColorComponent,

§

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

Formats the value using the given formatter. Read more
§

impl<C1, C2> From<Hsla<C1>> for Rgba<C2>

§

fn from(hsl: Hsla<C1>) -> Rgba<C2>

Converts to this type from the input type.
§

impl<C1, C2> From<Hsva<C1>> for Rgba<C2>

§

fn from(hsv: Hsva<C1>) -> Rgba<C2>

Converts to this type from the input type.
§

impl<C1, C2> From<Rgba<C1>> for Hsla<C2>

§

fn from(rgb: Rgba<C1>) -> Hsla<C2>

Converts to this type from the input type.
§

impl<C1, C2> From<Rgba<C1>> for Hsva<C2>

§

fn from(rgb: Rgba<C1>) -> Hsva<C2>

Converts to this type from the input type.
§

impl<T> From<Rgba<T>> for String
where T: ColorComponent,

§

fn from(color: Rgba<T>) -> String

Converts to this type from the input type.
§

impl<T> Hash for Rgba<T>
where T: Hash + ColorComponent,

§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
§

impl<T> Mul for Rgba<T>
where T: ColorComponent,

§

type Output = Rgba<T>

The resulting type after applying the * operator.
§

fn mul(self, rhs: Rgba<T>) -> Rgba<T>

Performs the * operation. Read more
§

impl<T> PartialEq for Rgba<T>

§

fn eq(&self, other: &Rgba<T>) -> 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 RenderbufferPixel for Rgba<f32>

source§

const GL_FORMAT: u32 = 6_408u32

§

impl<T> Serialize for Rgba<T>

§

fn serialize<__S>( &self, __serializer: __S ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl TexturePixel for Rgba<f32>

source§

const INTERNAL_FORMAT: u32 = 6_408u32

source§

const FORMAT: u32 = 6_408u32

source§

const TYPE: u32 = 5_121u32

§

impl<T> TryFrom<&str> for Rgba<T>
where T: ColorComponent,

§

type Error = Error

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

fn try_from(value: &str) -> Result<Rgba<T>, <Rgba<T> as TryFrom<&str>>::Error>

Performs the conversion.
§

impl<T> TryFrom<String> for Rgba<T>
where T: ColorComponent,

§

type Error = Error

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

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

Performs the conversion.
source§

impl Uniform for Rgba<f32>

source§

fn apply(&self, gl: &Context, info: &UniformInfo)

source§

impl VertexAttribute for Rgba<f32>

§

impl<T> Copy for Rgba<T>
where T: Copy + ColorComponent,

§

impl<T> Eq for Rgba<T>
where T: Eq + ColorComponent,

§

impl<T> StructuralEq for Rgba<T>
where T: ColorComponent,

§

impl<T> StructuralPartialEq for Rgba<T>
where T: ColorComponent,

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for Rgba<T>
where T: RefUnwindSafe,

§

impl<T> Send for Rgba<T>
where T: Send,

§

impl<T> Sync for Rgba<T>
where T: Sync,

§

impl<T> Unpin for Rgba<T>
where T: Unpin,

§

impl<T> UnwindSafe for Rgba<T>
where T: UnwindSafe,

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
§

impl<T> CompatExt for T

§

fn compat(self) -> Compat<T>

Applies the [Compat] adapter by value. Read more
§

fn compat_ref(&self) -> Compat<&T>

Applies the [Compat] adapter by shared reference. Read more
§

fn compat_mut(&mut self) -> Compat<&mut T>

Applies the [Compat] adapter by mutable reference. Read more
source§

impl<T> Configurable for T
where T: ToString + Clone,

§

type Config = ShowValue<T>

source§

fn config(theme: &Rc<Theme>, value: T) -> ShowValue<T>

§

impl<T> Diff for T
where T: Debug + Serialize + DeserializeOwned + Sync + Send + Copy + PartialEq + 'static + Unpin,

§

type Delta = T

Object representing the difference between two states of Self
§

fn diff(&self, to: &T) -> T

Calculate the difference between two states
§

fn update(&mut self, new_value: &T)

Update the state using the delta Read more
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
source§

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

source§

fn __clone_box(&self, _: Private) -> *mut ()

§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<S> FromSample<S> for S

§

fn from_sample_(s: S) -> S

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.

§

impl<I> IntoResettable<String> for I
where I: Into<String>,

§

fn into_resettable(self) -> Resettable<String>

Convert to the intended resettable type
§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

§

fn into_sample(self) -> T

§

impl<T> Pointable for T

§

const ALIGN: usize = _

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> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where 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
§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

§

fn to_sample_(self) -> U

source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

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

§

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

§

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

source§

impl<T> Message for T
where T: Debug + Serialize + for<'de> Deserialize<'de> + Send + 'static + Unpin,