FerroUI/ docs

Search guides, controls, Rust APIs, and XAML.

    GitHub ↗

    Color

    struct · ferroui-base · v0.5.0

    struct Color
    

    An ARGB color.

    View source

    Members

    a

    a: u8
    

    The Alpha component of the color.

    Source

    r

    r: u8
    

    The Red component of the color.

    Source

    g

    g: u8
    

    The Green component of the color.

    Source

    b

    b: u8
    

    The Blue component of the color.

    Source

    new

    const fn new(a: u8, r: u8, g: u8, b: u8) -> Self
    

    Initializes a new instance of the Color struct.

    Source

    from_argb

    const fn from_argb(a: u8, r: u8, g: u8, b: u8) -> Color
    

    Creates a Color from alpha, red, green and blue components.

    Source

    from_rgb

    const fn from_rgb(r: u8, g: u8, b: u8) -> Color
    

    Creates an opaque Color from red, green and blue components.

    Source

    from_uint32

    const fn from_uint32(value: u32) -> Color
    

    Creates a Color from an integer in 0xAARRGGBB layout.

    Source

    parse

    fn parse(s: &str) -> Result<Color, FormatError>
    

    Parses a color string: #rgb, #argb, #rrggbb, #aarrggbb, rgb()/rgba(), hsl()/hsla(), hsv()/hsva() or a known color name.

    Source

    try_parse

    fn try_parse(s: &str) -> Option<Color>
    

    Parses a color string, returning None when it is not a valid color.

    Source

    to_string_format

    fn to_string_format(self: &Self, format: Option<&str>, format_provider: Option<&CultureInfo>) -> Result<String, FormatError>
    

    Returns the string representation of the color using a format specifier.

    Supported format specifiers:

    • X: XAML hex with alpha, #AARRGGBB
    • x: hex without alpha, #RRGGBB
    • H: HTML/CSS hex with alpha, #RRGGBBAA
    • R / r: CSS rgba(r, g, b, a) / rgb(r, g, b)
    • R% / r%: CSS rgba(r%, g%, b%, a%) / rgb(r%, g%, b%)
    • L, l, L%, l%: converted to HSL and formatted as such
    • V, v, V%, v%: converted to HSV and formatted as such

    A null or empty format is the same as to_string(). Any other format is an error. format_provider is ignored: color formatting is culture-invariant.

    Source

    to_uint32

    const fn to_uint32(self: &Self) -> u32
    

    Returns the integer representation of the color in 0xAARRGGBB layout.

    Source

    to_hsl

    fn to_hsl(self: &Self) -> HslColor
    

    Returns the HSL color model equivalent of this RGB color.

    Source

    to_hsv

    fn to_hsv(self: &Self) -> HsvColor
    

    Returns the HSV color model equivalent of this RGB color.

    Source

    equals

    const fn equals(self: &Self, other: Color) -> bool
    

    Check if two colors are equal.

    Source

    rgb_to_hsl

    fn rgb_to_hsl(red: u8, green: u8, blue: u8, alpha: u8) -> HslColor
    

    Converts the given RGBA color component values to their HSL color equivalent.

    Source

    normalized_rgb_to_hsl

    fn normalized_rgb_to_hsl(r: f64, g: f64, b: f64, a: f64) -> HslColor
    

    Converts the given RGBA color component values to their HSL color equivalent. Warning: no bounds checks or clamping is done on the input component values; they are assumed to be within the 0..1 range. The result is not clamped either.

    Source

    rgb_to_hsv

    fn rgb_to_hsv(red: u8, green: u8, blue: u8, alpha: u8) -> HsvColor
    

    Converts the given RGBA color component values to their HSV color equivalent.

    Source

    normalized_rgb_to_hsv

    fn normalized_rgb_to_hsv(r: f64, g: f64, b: f64, a: f64) -> HsvColor
    

    Converts the given RGBA color component values to their HSV color equivalent. Warning: no bounds checks or clamping is done on the input component values; they are assumed to be within the 0..1 range. The result is not clamped either.

    Source

    Trait implementations

    Availability

    Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.