Struct LinearRgba
#[repr(C)]pub struct LinearRgba {
pub r: f32,
pub g: f32,
pub b: f32,
pub a: f32,
}Expand description
Represents a color in a linear RGBA color space using f32 components.
This struct is the standard color representation within Khora.
Using a linear color space is crucial for correct lighting, shading, and blending.
The f32 components allow for High Dynamic Range (HDR) colors, where component
values can exceed 1.0.
#[repr(C)] ensures a consistent memory layout, which is important when passing
color data to graphics APIs.
Fields§
§r: f32The red component in linear space.
g: f32The green component in linear space.
b: f32The blue component in linear space.
a: f32The alpha (opacity) component (linear, but not gamma-corrected).
Implementations§
§impl LinearRgba
impl LinearRgba
pub const RED: LinearRgba
pub const RED: LinearRgba
Opaque red ([1.0, 0.0, 0.0, 1.0]).
pub const GREEN: LinearRgba
pub const GREEN: LinearRgba
Opaque green ([0.0, 1.0, 0.0, 1.0]).
pub const BLUE: LinearRgba
pub const BLUE: LinearRgba
Opaque blue ([0.0, 0.0, 1.0, 1.0]).
pub const YELLOW: LinearRgba
pub const YELLOW: LinearRgba
Opaque yellow ([1.0, 1.0, 0.0, 1.0]).
pub const CYAN: LinearRgba
pub const CYAN: LinearRgba
Opaque cyan ([0.0, 1.0, 1.0, 1.0]).
pub const MAGENTA: LinearRgba
pub const MAGENTA: LinearRgba
Opaque magenta ([1.0, 0.0, 1.0, 1.0]).
pub const WHITE: LinearRgba
pub const WHITE: LinearRgba
Opaque white ([1.0, 1.0, 1.0, 1.0]).
pub const BLACK: LinearRgba
pub const BLACK: LinearRgba
Opaque black ([0.0, 0.0, 0.0, 1.0]).
pub const TRANSPARENT: LinearRgba
pub const TRANSPARENT: LinearRgba
Fully transparent black ([0.0, 0.0, 0.0, 0.0]).
pub const fn new(r: f32, g: f32, b: f32, a: f32) -> LinearRgba
pub const fn new(r: f32, g: f32, b: f32, a: f32) -> LinearRgba
Creates a new LinearRgba with explicit RGBA values.
pub const fn rgb(r: f32, g: f32, b: f32) -> LinearRgba
pub const fn rgb(r: f32, g: f32, b: f32) -> LinearRgba
Creates a new opaque LinearRgba (alpha = 1.0).
pub const fn gray(value: f32) -> LinearRgba
pub const fn gray(value: f32) -> LinearRgba
Creates an opaque grayscale color where every channel equals
value. Equivalent to LinearRgba::rgb(value, value, value).
§impl LinearRgba
impl LinearRgba
pub fn from_vec4(v: Vec4) -> LinearRgba
pub fn from_vec4(v: Vec4) -> LinearRgba
Creates a LinearRgba from a Vec4.
pub fn from_hex(hex: &str) -> LinearRgba
pub fn from_hex(hex: &str) -> LinearRgba
Creates a LinearRgba from an sRGB hex string (#RRGGBB or #RRGGBBAA).
The RGB channels are converted to linear space. Alpha is normalized but not gamma corrected.
§Panics
Panics if the hex string is malformed.
§Example
use khora_core::math::color::LinearRgba;
let color = LinearRgba::from_hex("#6495ED");pub fn to_hex(&self) -> String
pub fn to_hex(&self) -> String
Converts this linear color to an sRGB hex string (#RRGGBBAA).
The RGB channels are gamma corrected to sRGB. Alpha is kept linear.
pub fn from_srgb(r: f32, g: f32, b: f32) -> LinearRgba
pub fn from_srgb(r: f32, g: f32, b: f32) -> LinearRgba
Creates a LinearRgba by converting from normalized sRGB components.
pub fn to_srgb(&self) -> LinearRgba
pub fn to_srgb(&self) -> LinearRgba
Converts this linear color to sRGB components.
pub fn from_oklch(l: f32, c: f32, h: f32) -> LinearRgba
pub fn from_oklch(l: f32, c: f32, h: f32) -> LinearRgba
Creates a LinearRgba from OKLCH coordinates.
l— perceptual lightness in[0, 1]c— chroma (typically[0, 0.4]; values above ~0.37 may be out of sRGB gamut and get clamped)h— hue in degrees
OKLCH is the perceptual cylindrical form of OKLab — same hue
reads the same brightness across the spectrum. This is the
space the Khora design system is authored in (see
docs/src/design/editor.md and the mdBook CSS).
The output is an opaque color (a = 1.0); use Self::with_alpha
to layer transparency on top.
pub fn from_oklab(l: f32, a: f32, b: f32) -> LinearRgba
pub fn from_oklab(l: f32, a: f32, b: f32) -> LinearRgba
Creates a LinearRgba from OKLab coordinates (l, a, b).
Implements Björn Ottosson’s reference transform
(https://bottosson.github.io/posts/oklab/): OKLab → linear LMS
(cube each axis) → linear sRGB (M2 matrix). The result is the
same as the CSS oklab() function in linear-light space.
pub fn premultiplied(self) -> LinearRgba
pub fn premultiplied(self) -> LinearRgba
Returns the same color premultiplied by its alpha — every RGB
channel is scaled by a. Premultiplied alpha is what most
graphics APIs (and egui) expect at the blending stage.
pub fn unpremultiplied(self) -> LinearRgba
pub fn unpremultiplied(self) -> LinearRgba
Inverse of Self::premultiplied — divides each RGB channel
by a (no-op when a == 0). Use to recover unassociated alpha
from a premultiplied buffer.
§impl LinearRgba
impl LinearRgba
pub fn with_alpha(&self, a: f32) -> LinearRgba
pub fn with_alpha(&self, a: f32) -> LinearRgba
Returns a new color with the same RGB components but a different alpha.
pub fn lerp(start: LinearRgba, end: LinearRgba, t: f32) -> LinearRgba
pub fn lerp(start: LinearRgba, end: LinearRgba, t: f32) -> LinearRgba
Linearly interpolates between two colors.
The factor t is clamped to [0.0, 1.0].
Trait Implementations§
§impl Add for LinearRgba
impl Add for LinearRgba
§fn add(self, rhs: LinearRgba) -> <LinearRgba as Add>::Output
fn add(self, rhs: LinearRgba) -> <LinearRgba as Add>::Output
Adds two colors component-wise.
§type Output = LinearRgba
type Output = LinearRgba
+ operator.§impl<'__de, __Context> BorrowDecode<'__de, __Context> for LinearRgba
impl<'__de, __Context> BorrowDecode<'__de, __Context> for LinearRgba
§fn borrow_decode<__D>(decoder: &mut __D) -> Result<LinearRgba, DecodeError>where
__D: BorrowDecoder<'__de, Context = __Context>,
fn borrow_decode<__D>(decoder: &mut __D) -> Result<LinearRgba, DecodeError>where
__D: BorrowDecoder<'__de, Context = __Context>,
§impl Clone for LinearRgba
impl Clone for LinearRgba
§fn clone(&self) -> LinearRgba
fn clone(&self) -> LinearRgba
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more§impl Debug for LinearRgba
impl Debug for LinearRgba
§impl<__Context> Decode<__Context> for LinearRgba
impl<__Context> Decode<__Context> for LinearRgba
§fn decode<__D>(decoder: &mut __D) -> Result<LinearRgba, DecodeError>where
__D: Decoder<Context = __Context>,
fn decode<__D>(decoder: &mut __D) -> Result<LinearRgba, DecodeError>where
__D: Decoder<Context = __Context>,
§impl Default for LinearRgba
impl Default for LinearRgba
§fn default() -> LinearRgba
fn default() -> LinearRgba
Returns opaque white by default.
§impl<'de> Deserialize<'de> for LinearRgba
impl<'de> Deserialize<'de> for LinearRgba
§fn deserialize<__D>(
__deserializer: __D,
) -> Result<LinearRgba, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<LinearRgba, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
§impl Div<f32> for LinearRgba
impl Div<f32> for LinearRgba
§type Output = LinearRgba
type Output = LinearRgba
/ operator.§impl Encode for LinearRgba
impl Encode for LinearRgba
§impl Mul<f32> for LinearRgba
impl Mul<f32> for LinearRgba
§fn mul(self, scalar: f32) -> <LinearRgba as Mul<f32>>::Output
fn mul(self, scalar: f32) -> <LinearRgba as Mul<f32>>::Output
Multiplies all components by a scalar.
§type Output = LinearRgba
type Output = LinearRgba
* operator.§impl Mul for LinearRgba
impl Mul for LinearRgba
§fn mul(self, rhs: LinearRgba) -> <LinearRgba as Mul>::Output
fn mul(self, rhs: LinearRgba) -> <LinearRgba as Mul>::Output
Multiplies two colors component-wise (modulation).
§type Output = LinearRgba
type Output = LinearRgba
* operator.§impl PartialEq for LinearRgba
impl PartialEq for LinearRgba
§impl Serialize for LinearRgba
impl Serialize for LinearRgba
§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
§impl Sub for LinearRgba
impl Sub for LinearRgba
§fn sub(self, rhs: LinearRgba) -> <LinearRgba as Sub>::Output
fn sub(self, rhs: LinearRgba) -> <LinearRgba as Sub>::Output
Subtracts two colors component-wise.
§type Output = LinearRgba
type Output = LinearRgba
- operator.impl Copy for LinearRgba
impl Pod for LinearRgba
impl StructuralPartialEq for LinearRgba
Auto Trait Implementations§
impl Freeze for LinearRgba
impl RefUnwindSafe for LinearRgba
impl Send for LinearRgba
impl Sync for LinearRgba
impl Unpin for LinearRgba
impl UnsafeUnpin for LinearRgba
impl UnwindSafe for LinearRgba
Blanket Implementations§
§impl<T> AppLifecycle for Twhere
T: ?Sized,
impl<T> AppLifecycle for Twhere
T: ?Sized,
§fn on_start(&mut self, ctx: &mut dyn AppContext)
fn on_start(&mut self, ctx: &mut dyn AppContext)
update. Apps install their theme / fonts here.Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
§type Bits = T
type Bits = T
Self must have the same layout as the specified Bits except for
the possible invalid bit patterns being checked during
is_valid_bit_pattern.§fn is_valid_bit_pattern(_bits: &T) -> bool
fn is_valid_bit_pattern(_bits: &T) -> bool
bits
as &Self.Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSend for T
impl<T> DowncastSend for T
§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().§impl<F, T, S> SimdInto<T, S> for Fwhere
T: SimdFrom<F, S>,
S: Simd,
impl<F, T, S> SimdInto<T, S> for Fwhere
T: SimdFrom<F, S>,
S: Simd,
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.