pub enum CssColor {
CurrentColor,
RGBA(RGBA),
LAB(Box<LABColor>),
Predefined(Box<PredefinedColor>),
Float(Box<FloatColor>),
LightDark(Box<CssColor>, Box<CssColor>),
System(SystemColor),
}
Expand description
A CSS <color>
value.
CSS supports many different color spaces to represent colors. The most common values
are stored as RGBA using a single byte per component. Less common values are stored
using a Box
to reduce the amount of memory used per color.
Each color space is represented as a struct that implements the From
and Into
traits
for all other color spaces, so it is possible to convert between color spaces easily.
In addition, colors support interpolation as in the color-mix()
function.
Variants§
CurrentColor
The currentColor
keyword.
RGBA(RGBA)
An value in the RGB color space, including values parsed as hex colors, or the rgb()
, hsl()
, and hwb()
functions.
LAB(Box<LABColor>)
A value in a LAB color space, including the lab()
, lch()
, oklab()
, and oklch()
functions.
Predefined(Box<PredefinedColor>)
A value in a predefined color space, e.g. display-p3
.
Float(Box<FloatColor>)
A floating point representation of an RGB, HSL, or HWB color when it contains none
components.
LightDark(Box<CssColor>, Box<CssColor>)
The light-dark()
function.
System(SystemColor)
A system color keyword.
Implementations§
Source§impl CssColor
impl CssColor
Sourcepub fn current_color() -> CssColor
pub fn current_color() -> CssColor
Returns the currentColor
keyword.
Sourcepub fn transparent() -> CssColor
pub fn transparent() -> CssColor
Returns the transparent
keyword.
Sourcepub fn get_necessary_fallbacks(&self, targets: Targets) -> ColorFallbackKind
pub fn get_necessary_fallbacks(&self, targets: Targets) -> ColorFallbackKind
Returns the color fallback types needed for the given browser targets.
Sourcepub fn get_fallback(&self, kind: ColorFallbackKind) -> CssColor
pub fn get_fallback(&self, kind: ColorFallbackKind) -> CssColor
Returns a fallback color for the given fallback type.
Source§impl CssColor
impl CssColor
Sourcepub fn interpolate<T>(
&self,
p1: f32,
other: &CssColor,
p2: f32,
method: HueInterpolationMethod,
) -> Result<CssColor, ()>
pub fn interpolate<T>( &self, p1: f32, other: &CssColor, p2: f32, method: HueInterpolationMethod, ) -> Result<CssColor, ()>
Mixes this color with another color, including the specified amount of each.
Implemented according to the color-mix()
function.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for CssColor
impl<'de> Deserialize<'de> for CssColor
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>,
Source§impl From<SRGBLinear> for CssColor
impl From<SRGBLinear> for CssColor
Source§fn from(color: SRGBLinear) -> CssColor
fn from(color: SRGBLinear) -> CssColor
Source§impl IsCompatible for CssColor
impl IsCompatible for CssColor
Source§fn is_compatible(&self, browsers: Browsers) -> bool
fn is_compatible(&self, browsers: Browsers) -> bool
Source§impl JsonSchema for CssColor
impl JsonSchema for CssColor
Source§fn schema_name() -> String
fn schema_name() -> String
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(gen: &mut SchemaGenerator) -> Schema
fn json_schema(gen: &mut SchemaGenerator) -> Schema
Source§fn is_referenceable() -> bool
fn is_referenceable() -> bool
$ref
keyword. Read moreSource§impl<'i> Parse<'i> for CssColor
impl<'i> Parse<'i> for CssColor
Source§fn parse<'t>(
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i, ParserError<'i>>>
fn parse<'t>( input: &mut Parser<'i, 't>, ) -> Result<Self, ParseError<'i, ParserError<'i>>>
Source§fn parse_string(input: &'i str) -> Result<Self, ParseError<'i, ParserError<'i>>>
fn parse_string(input: &'i str) -> Result<Self, ParseError<'i, ParserError<'i>>>
Source§impl ToCss for CssColor
impl ToCss for CssColor
Source§fn to_css<W>(
&self,
dest: &mut Printer<'_, '_, '_, W>,
) -> Result<(), PrinterError>where
W: Write,
fn to_css<W>(
&self,
dest: &mut Printer<'_, '_, '_, W>,
) -> Result<(), PrinterError>where
W: Write,
self
in CSS syntax, writing to dest
.Source§fn to_css_string(
&self,
options: PrinterOptions<'_>,
) -> Result<String, PrinterError>
fn to_css_string( &self, options: PrinterOptions<'_>, ) -> Result<String, PrinterError>
self
in CSS syntax and return a string. Read moreSource§impl TryFrom<&CssColor> for SRGBLinear
impl TryFrom<&CssColor> for SRGBLinear
Source§impl TryFrom<CssColor> for SRGBLinear
impl TryFrom<CssColor> for SRGBLinear
Source§impl<'i, __T: Visit<'i, __T, __V>, __V: ?Sized + Visitor<'i, __T>> Visit<'i, __T, __V> for CssColor
impl<'i, __T: Visit<'i, __T, __V>, __V: ?Sized + Visitor<'i, __T>> Visit<'i, __T, __V> for CssColor
Source§const CHILD_TYPES: VisitTypes = _
const CHILD_TYPES: VisitTypes = _
visitor
only.impl StructuralPartialEq for CssColor
Auto Trait Implementations§
impl Freeze for CssColor
impl RefUnwindSafe for CssColor
impl Send for CssColor
impl Sync for CssColor
impl Unpin for CssColor
impl UnwindSafe for CssColor
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)Source§impl<F, W, T, D> Deserialize<With<T, W>, D> for F
impl<F, W, T, D> Deserialize<With<T, W>, D> for F
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more