pub struct Color {
pub r: u8,
pub g: u8,
pub b: u8,
}Expand description
A color in RGB format.
Fields§
§r: u8Red component (0-255).
g: u8Green component (0-255).
b: u8Blue component (0-255).
Implementations§
Source§impl Color
impl Color
Sourcepub fn to_ansi_fg(&self) -> String
pub fn to_ansi_fg(&self) -> String
Convert to ANSI 24-bit foreground escape code.
Sourcepub fn to_ansi_bg(&self) -> String
pub fn to_ansi_bg(&self) -> String
Convert to ANSI 24-bit background escape code.
Sourcepub fn luminance(&self) -> f64
pub fn luminance(&self) -> f64
Calculate relative luminance for contrast calculations.
Uses the WCAG formula for relative luminance.
Sourcepub fn contrast_ratio(&self, other: &Color) -> f64
pub fn contrast_ratio(&self, other: &Color) -> f64
Calculate WCAG contrast ratio between this color and another.
Returns a value between 1.0 (no contrast) and 21.0 (max contrast). WCAG AA requires 4.5:1 for normal text, 3:1 for large text.
Trait Implementations§
impl Copy for Color
impl Eq 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 UnsafeUnpin 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