Color
struct · ferroui-base · v0.5.0
struct Color
An ARGB color.
Members
argbnewfrom_argbfrom_rgbfrom_uint32parsetry_parseto_string_formatto_uint32to_hslto_hsvequalsrgb_to_hslnormalized_rgb_to_hslrgb_to_hsvnormalized_rgb_to_hsv
a
a: u8
The Alpha component of the color.
r
r: u8
The Red component of the color.
g
g: u8
The Green component of the color.
b
b: u8
The Blue component of the color.
new
const fn new(a: u8, r: u8, g: u8, b: u8) -> Self
Initializes a new instance of the Color struct.
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.
from_rgb
const fn from_rgb(r: u8, g: u8, b: u8) -> Color
Creates an opaque Color from red, green and blue components.
from_uint32
const fn from_uint32(value: u32) -> Color
Creates a Color from an integer in 0xAARRGGBB layout.
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.
try_parse
fn try_parse(s: &str) -> Option<Color>
Parses a color string, returning None when it is not a valid color.
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,#AARRGGBBx: hex without alpha,#RRGGBBH: HTML/CSS hex with alpha,#RRGGBBAAR/r: CSSrgba(r, g, b, a)/rgb(r, g, b)R%/r%: CSSrgba(r%, g%, b%, a%)/rgb(r%, g%, b%)L,l,L%,l%: converted to HSL and formatted as suchV,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.
to_uint32
const fn to_uint32(self: &Self) -> u32
Returns the integer representation of the color in 0xAARRGGBB layout.
to_hsl
fn to_hsl(self: &Self) -> HslColor
Returns the HSL color model equivalent of this RGB color.
to_hsv
fn to_hsv(self: &Self) -> HsvColor
Returns the HSV color model equivalent of this RGB color.
equals
const fn equals(self: &Self, other: Color) -> bool
Check if two colors are equal.
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.
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.
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.
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.
Trait implementations
SendSyncFreezeUnsafeUnpinUnpinUnwindSafeRefUnwindSafeResourceKeyObjectPropertyValueAnyValueClassDefaultsBorrow<T>BorrowMut<T>CloneToUninitInto<U>From<T>TryInto<U>TryFrom<U>AnyToOwnedToStringErasedDestructorIntoEitherTransition<Color>CloneCopyDebugStructuralPartialEqPartialEqEqHashDefaultFromStrDisplayFrom<HslColor>From<HsvColor>From<Color>IInterpolator<Color>ExpressionVariantValueServerPropertyValueBatchValueMarkupTypedValueTypeRegistration
Availability
Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.