pub struct Color {
pub r: f32,
pub g: f32,
pub b: f32,
pub a: f32,
}Expand description
RGBA color with values in the range [0.0, 1.0].
§Examples
use presentar_core::Color;
let color = Color::new(0.5, 0.5, 0.5, 1.0);
assert_eq!(color.r, 0.5);
assert_eq!(color.a, 1.0);Fields§
§r: f32Red component [0.0, 1.0]
g: f32Green component [0.0, 1.0]
b: f32Blue component [0.0, 1.0]
a: f32Alpha component [0.0, 1.0]
Implementations§
Source§impl Color
impl Color
Sourcepub const TRANSPARENT: Self
pub const TRANSPARENT: Self
Transparent color
Sourcepub fn new(r: f32, g: f32, b: f32, a: f32) -> Self
pub fn new(r: f32, g: f32, b: f32, a: f32) -> Self
Create a new color, clamping values to [0.0, 1.0].
Sourcepub fn from_hex(hex: &str) -> Result<Self, ColorParseError>
pub fn from_hex(hex: &str) -> Result<Self, ColorParseError>
Parse a hex color string (e.g., “#ff0000” or “ff0000”).
Supports 6-character RGB and 8-character RGBA formats.
§Errors
Returns an error if the string is not a valid hex color.
Sourcepub fn to_hex_with_alpha(&self) -> String
pub fn to_hex_with_alpha(&self) -> String
Convert to hex string with alpha.
Sourcepub fn relative_luminance(&self) -> f32
pub fn relative_luminance(&self) -> f32
Calculate relative luminance per WCAG 2.1.
Sourcepub fn contrast_ratio(&self, other: &Self) -> f32
pub fn contrast_ratio(&self, other: &Self) -> f32
Calculate contrast ratio between two colors per WCAG 2.1.
Returns a value between 1.0 (no contrast) and 21.0 (maximum contrast).
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Color
impl<'de> Deserialize<'de> for Color
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl Copy for Color
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> 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
Mutably borrows from an owned value. Read more