#[repr(C)]pub struct ColorU {
pub r: u8,
pub g: u8,
pub b: u8,
pub a: u8,
}Expand description
u8-based color, range 0 to 255 (similar to webrenders ColorU)
Fields§
§r: u8§g: u8§b: u8§a: u8Implementations§
Source§impl ColorU
impl ColorU
pub const ALPHA_TRANSPARENT: u8 = 0
pub const ALPHA_OPAQUE: u8 = 255
pub const RED: ColorU
pub const GREEN: ColorU
pub const BLUE: ColorU
pub const WHITE: ColorU
pub const BLACK: ColorU
pub const TRANSPARENT: ColorU
pub const YELLOW: ColorU
pub const CYAN: ColorU
pub const MAGENTA: ColorU
pub const ORANGE: ColorU
pub const PINK: ColorU
pub const PURPLE: ColorU
pub const BROWN: ColorU
pub const GRAY: ColorU
pub const LIGHT_GRAY: ColorU
pub const DARK_GRAY: ColorU
pub const NAVY: ColorU
pub const TEAL: ColorU
pub const OLIVE: ColorU
pub const MAROON: ColorU
pub const LIME: ColorU
pub const AQUA: ColorU
pub const SILVER: ColorU
pub const FUCHSIA: ColorU
pub const INDIGO: ColorU
pub const GOLD: ColorU
pub const CORAL: ColorU
pub const SALMON: ColorU
pub const TURQUOISE: ColorU
pub const VIOLET: ColorU
pub const CRIMSON: ColorU
pub const CHOCOLATE: ColorU
pub const SKY_BLUE: ColorU
pub const FOREST_GREEN: ColorU
pub const SEA_GREEN: ColorU
pub const SLATE_GRAY: ColorU
pub const MIDNIGHT_BLUE: ColorU
pub const DARK_RED: ColorU
pub const DARK_GREEN: ColorU
pub const DARK_BLUE: ColorU
pub const LIGHT_BLUE: ColorU
pub const LIGHT_GREEN: ColorU
pub const LIGHT_YELLOW: ColorU
pub const LIGHT_PINK: ColorU
pub fn red() -> Self
pub fn green() -> Self
pub fn blue() -> Self
pub fn white() -> Self
pub fn black() -> Self
pub fn transparent() -> Self
pub fn yellow() -> Self
pub fn cyan() -> Self
pub fn magenta() -> Self
pub fn orange() -> Self
pub fn pink() -> Self
pub fn purple() -> Self
pub fn brown() -> Self
pub fn gray() -> Self
pub fn light_gray() -> Self
pub fn dark_gray() -> Self
pub fn teal() -> Self
pub fn olive() -> Self
pub fn maroon() -> Self
pub fn lime() -> Self
pub fn aqua() -> Self
pub fn silver() -> Self
pub fn fuchsia() -> Self
pub fn indigo() -> Self
pub fn gold() -> Self
pub fn coral() -> Self
pub fn salmon() -> Self
pub fn turquoise() -> Self
pub fn violet() -> Self
pub fn crimson() -> Self
pub fn chocolate() -> Self
pub fn sky_blue() -> Self
pub fn forest_green() -> Self
pub fn sea_green() -> Self
pub fn slate_gray() -> Self
pub fn midnight_blue() -> Self
pub fn dark_red() -> Self
pub fn dark_green() -> Self
pub fn dark_blue() -> Self
pub fn light_blue() -> Self
pub fn light_green() -> Self
pub fn light_yellow() -> Self
pub fn light_pink() -> Self
Sourcepub const fn rgb(r: u8, g: u8, b: u8) -> Self
pub const fn rgb(r: u8, g: u8, b: u8) -> Self
Creates a new color with RGB values (alpha = 255).
Sourcepub const fn new(r: u8, g: u8, b: u8, a: u8) -> Self
pub const fn new(r: u8, g: u8, b: u8, a: u8) -> Self
Alias for rgba - kept for internal compatibility, not exposed in FFI.
Sourcepub const fn new_rgb(r: u8, g: u8, b: u8) -> Self
pub const fn new_rgb(r: u8, g: u8, b: u8) -> Self
Alias for rgb - kept for internal compatibility, not exposed in FFI.
pub fn interpolate(&self, other: &Self, t: f32) -> Self
Sourcepub fn lighten(&self, amount: f32) -> Self
pub fn lighten(&self, amount: f32) -> Self
Lighten a color by a percentage (0.0 to 1.0). Returns a new color blended towards white.
Sourcepub fn darken(&self, amount: f32) -> Self
pub fn darken(&self, amount: f32) -> Self
Darken a color by a percentage (0.0 to 1.0). Returns a new color blended towards black.
Sourcepub fn mix(&self, other: &Self, ratio: f32) -> Self
pub fn mix(&self, other: &Self, ratio: f32) -> Self
Mix two colors together with a given ratio (0.0 = self, 1.0 = other).
Sourcepub fn hover_variant(&self) -> Self
pub fn hover_variant(&self) -> Self
Create a hover variant (slightly lighter for dark colors, darker for light colors). This is useful for button hover states.
Sourcepub fn active_variant(&self) -> Self
pub fn active_variant(&self) -> Self
Create an active/pressed variant (darker than hover). This is useful for button active states.
Sourcepub fn luminance(&self) -> f32
pub fn luminance(&self) -> f32
Calculate relative luminance (0.0 = black, 1.0 = white). Uses the sRGB luminance formula.
Sourcepub fn contrast_text(&self) -> Self
pub fn contrast_text(&self) -> Self
Returns white or black text color for best contrast on this background.
Sourcepub fn relative_luminance(&self) -> f32
pub fn relative_luminance(&self) -> f32
Calculate relative luminance per WCAG 2.1 specification. Returns a value between 0.0 (darkest) and 1.0 (lightest). Uses the sRGB to linear conversion for accurate results.
Sourcepub fn contrast_ratio(&self, other: &Self) -> f32
pub fn contrast_ratio(&self, other: &Self) -> f32
Calculate the contrast ratio between this color and another. Returns a value between 1.0 (no contrast) and 21.0 (max contrast).
WCAG 2.1 requirements:
- AA normal text: >= 4.5:1
- AA large text: >= 3.0:1
- AAA normal text: >= 7.0:1
- AAA large text: >= 4.5:1
Sourcepub fn meets_wcag_aa(&self, other: &Self) -> bool
pub fn meets_wcag_aa(&self, other: &Self) -> bool
Check if the contrast ratio meets WCAG AA requirements for normal text (>= 4.5:1).
Sourcepub fn meets_wcag_aa_large(&self, other: &Self) -> bool
pub fn meets_wcag_aa_large(&self, other: &Self) -> bool
Check if the contrast ratio meets WCAG AA requirements for large text (>= 3.0:1). Large text is defined as 18pt+ or 14pt+ bold.
Sourcepub fn meets_wcag_aaa(&self, other: &Self) -> bool
pub fn meets_wcag_aaa(&self, other: &Self) -> bool
Check if the contrast ratio meets WCAG AAA requirements for normal text (>= 7.0:1).
Sourcepub fn meets_wcag_aaa_large(&self, other: &Self) -> bool
pub fn meets_wcag_aaa_large(&self, other: &Self) -> bool
Check if the contrast ratio meets WCAG AAA requirements for large text (>= 4.5:1).
Sourcepub fn is_light(&self) -> bool
pub fn is_light(&self) -> bool
Returns true if this color is considered “light” (luminance > 0.5). Useful for determining if dark or light text should be used.
Sourcepub fn is_dark(&self) -> bool
pub fn is_dark(&self) -> bool
Returns true if this color is considered “dark” (luminance <= 0.5).
Sourcepub fn best_contrast_text(&self) -> Self
pub fn best_contrast_text(&self) -> Self
Suggest the best text color (black or white) for this background, ensuring WCAG AA compliance for normal text.
If neither black nor white meets AA requirements (unlikely), returns the one with higher contrast.
Sourcepub fn ensure_contrast(&self, background: &Self, min_ratio: f32) -> Self
pub fn ensure_contrast(&self, background: &Self, min_ratio: f32) -> Self
Adjust the color to ensure it meets the minimum contrast ratio against a background. Lightens or darkens the color as needed.
Returns the original color if it already meets the requirement, otherwise returns an adjusted color that meets the minimum contrast.
Sourcepub fn apca_contrast(&self, background: &Self) -> f32
pub fn apca_contrast(&self, background: &Self) -> f32
Calculate the APCA (Accessible Perceptual Contrast Algorithm) contrast. This is a newer algorithm that may replace WCAG contrast in future standards. Returns a value between -108 (white on black) and 106 (black on white).
Note: The sign indicates polarity (negative = light text on dark bg). For most purposes, use the absolute value.
Sourcepub fn meets_apca_body(&self, background: &Self) -> bool
pub fn meets_apca_body(&self, background: &Self) -> bool
Check if the APCA contrast meets the recommended minimum for body text (|Lc| >= 60).
Sourcepub fn meets_apca_large(&self, background: &Self) -> bool
pub fn meets_apca_large(&self, background: &Self) -> bool
Check if the APCA contrast meets the minimum for large text (|Lc| >= 45).
Sourcepub fn with_alpha(&self, a: u8) -> Self
pub fn with_alpha(&self, a: u8) -> Self
Set the alpha channel while keeping RGB values.
Sourcepub fn with_alpha_f32(&self, a: f32) -> Self
pub fn with_alpha_f32(&self, a: f32) -> Self
Set the alpha as a float (0.0 to 1.0).
Sourcepub fn to_grayscale(&self) -> Self
pub fn to_grayscale(&self) -> Self
Convert to grayscale using luminance weights.
pub const fn has_alpha(&self) -> bool
pub fn to_hash(&self) -> String
Sourcepub fn strawberry(shade: usize) -> Self
pub fn strawberry(shade: usize) -> Self
Strawberry color palette (shade: 100, 300, 500, 700, 900)
Sourcepub fn palette_orange(shade: usize) -> Self
pub fn palette_orange(shade: usize) -> Self
Orange color palette (shade: 100, 300, 500, 700, 900)
Sourcepub fn palette_lime(shade: usize) -> Self
pub fn palette_lime(shade: usize) -> Self
Lime color palette (shade: 100, 300, 500, 700, 900)
Sourcepub fn blueberry(shade: usize) -> Self
pub fn blueberry(shade: usize) -> Self
Blueberry color palette (shade: 100, 300, 500, 700, 900)
Sourcepub fn bubblegum(shade: usize) -> Self
pub fn bubblegum(shade: usize) -> Self
Bubblegum color palette (shade: 100, 300, 500, 700, 900)
Sourcepub fn palette_silver(shade: usize) -> Self
pub fn palette_silver(shade: usize) -> Self
Silver color palette (shade: 100, 300, 500, 700, 900)
Sourcepub fn apple_red_dark() -> Self
pub fn apple_red_dark() -> Self
Apple Red (dark mode)
Sourcepub fn apple_orange() -> Self
pub fn apple_orange() -> Self
Apple Orange (light mode)
Sourcepub fn apple_orange_dark() -> Self
pub fn apple_orange_dark() -> Self
Apple Orange (dark mode)
Sourcepub fn apple_yellow() -> Self
pub fn apple_yellow() -> Self
Apple Yellow (light mode)
Sourcepub fn apple_yellow_dark() -> Self
pub fn apple_yellow_dark() -> Self
Apple Yellow (dark mode)
Sourcepub fn apple_green() -> Self
pub fn apple_green() -> Self
Apple Green (light mode)
Sourcepub fn apple_green_dark() -> Self
pub fn apple_green_dark() -> Self
Apple Green (dark mode)
Sourcepub fn apple_mint() -> Self
pub fn apple_mint() -> Self
Apple Mint (light mode)
Sourcepub fn apple_mint_dark() -> Self
pub fn apple_mint_dark() -> Self
Apple Mint (dark mode)
Sourcepub fn apple_teal() -> Self
pub fn apple_teal() -> Self
Apple Teal (light mode)
Sourcepub fn apple_teal_dark() -> Self
pub fn apple_teal_dark() -> Self
Apple Teal (dark mode)
Sourcepub fn apple_cyan() -> Self
pub fn apple_cyan() -> Self
Apple Cyan (light mode)
Sourcepub fn apple_cyan_dark() -> Self
pub fn apple_cyan_dark() -> Self
Apple Cyan (dark mode)
Sourcepub fn apple_blue() -> Self
pub fn apple_blue() -> Self
Apple Blue (light mode)
Sourcepub fn apple_blue_dark() -> Self
pub fn apple_blue_dark() -> Self
Apple Blue (dark mode)
Sourcepub fn apple_indigo() -> Self
pub fn apple_indigo() -> Self
Apple Indigo (light mode)
Sourcepub fn apple_indigo_dark() -> Self
pub fn apple_indigo_dark() -> Self
Apple Indigo (dark mode)
Sourcepub fn apple_purple() -> Self
pub fn apple_purple() -> Self
Apple Purple (light mode)
Sourcepub fn apple_purple_dark() -> Self
pub fn apple_purple_dark() -> Self
Apple Purple (dark mode)
Sourcepub fn apple_pink() -> Self
pub fn apple_pink() -> Self
Apple Pink (light mode)
Sourcepub fn apple_pink_dark() -> Self
pub fn apple_pink_dark() -> Self
Apple Pink (dark mode)
Sourcepub fn apple_brown() -> Self
pub fn apple_brown() -> Self
Apple Brown (light mode)
Sourcepub fn apple_brown_dark() -> Self
pub fn apple_brown_dark() -> Self
Apple Brown (dark mode)
Sourcepub fn apple_gray() -> Self
pub fn apple_gray() -> Self
Apple Gray (light mode)
Sourcepub fn apple_gray_dark() -> Self
pub fn apple_gray_dark() -> Self
Apple Gray (dark mode)
Sourcepub fn bootstrap_primary() -> Self
pub fn bootstrap_primary() -> Self
Primary button color (blue) - used for main actions
pub fn bootstrap_primary_hover() -> Self
pub fn bootstrap_primary_active() -> Self
Sourcepub fn bootstrap_secondary() -> Self
pub fn bootstrap_secondary() -> Self
Secondary button color (gray) - used for secondary actions
pub fn bootstrap_secondary_hover() -> Self
pub fn bootstrap_secondary_active() -> Self
Sourcepub fn bootstrap_success() -> Self
pub fn bootstrap_success() -> Self
Success button color (green) - used for confirmations
pub fn bootstrap_success_hover() -> Self
pub fn bootstrap_success_active() -> Self
Sourcepub fn bootstrap_danger() -> Self
pub fn bootstrap_danger() -> Self
Danger button color (red) - used for destructive actions
pub fn bootstrap_danger_hover() -> Self
pub fn bootstrap_danger_active() -> Self
Sourcepub fn bootstrap_warning() -> Self
pub fn bootstrap_warning() -> Self
Warning button color (yellow) - used for warnings, uses BLACK text
pub fn bootstrap_warning_hover() -> Self
pub fn bootstrap_warning_active() -> Self
Sourcepub fn bootstrap_info() -> Self
pub fn bootstrap_info() -> Self
Info button color (teal/cyan) - used for informational actions
pub fn bootstrap_info_hover() -> Self
pub fn bootstrap_info_active() -> Self
Sourcepub fn bootstrap_light() -> Self
pub fn bootstrap_light() -> Self
Light button color - used for light-themed buttons
pub fn bootstrap_light_hover() -> Self
pub fn bootstrap_light_active() -> Self
Sourcepub fn bootstrap_dark() -> Self
pub fn bootstrap_dark() -> Self
Dark button color - used for dark-themed buttons
pub fn bootstrap_dark_hover() -> Self
pub fn bootstrap_dark_active() -> Self
Sourcepub fn bootstrap_link() -> Self
pub fn bootstrap_link() -> Self
Link button text color