Enum lightningcss::values::color::CssColor
source · pub enum CssColor {
CurrentColor,
RGBA(RGBA),
LAB(Box<LABColor>),
Predefined(Box<PredefinedColor>),
Float(Box<FloatColor>),
}
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.
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: Browsers) -> ColorFallbackKind
pub fn get_necessary_fallbacks(&self, targets: Browsers) -> 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<'a, T>(
&'a self,
p1: f32,
other: &'a CssColor,
p2: f32,
method: HueInterpolationMethod
) -> CssColorwhere
T: 'static + From<&'a CssColor> + Interpolate + Into<CssColor> + Into<OKLCH> + ColorGamut + Into<OKLAB> + From<OKLCH> + Copy,
pub fn interpolate<'a, T>( &'a self, p1: f32, other: &'a CssColor, p2: f32, method: HueInterpolationMethod ) -> CssColorwhere T: 'static + From<&'a CssColor> + Interpolate + Into<CssColor> + Into<OKLCH> + ColorGamut + Into<OKLAB> + From<OKLCH> + Copy,
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<&CssColor> for SRGBLinear
impl From<&CssColor> for SRGBLinear
source§fn from(color: &CssColor) -> SRGBLinear
fn from(color: &CssColor) -> SRGBLinear
source§impl From<CssColor> for SRGBLinear
impl From<CssColor> for SRGBLinear
source§fn from(color: CssColor) -> SRGBLinear
fn from(color: CssColor) -> SRGBLinear
source§impl From<SRGBLinear> for CssColor
impl From<SRGBLinear> for CssColor
source§fn from(color: SRGBLinear) -> CssColor
fn from(color: SRGBLinear) -> CssColor
source§impl JsonSchema for CssColor
impl JsonSchema for CssColor
source§fn schema_name() -> String
fn schema_name() -> String
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 PartialEq<CssColor> for CssColor
impl PartialEq<CssColor> for CssColor
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<'i, __T: Visit<'i, __T, __V>, __V: Visitor<'i, __T>> Visit<'i, __T, __V> for CssColor
impl<'i, __T: Visit<'i, __T, __V>, __V: Visitor<'i, __T>> Visit<'i, __T, __V> for CssColor
source§const CHILD_TYPES: VisitTypes = _
const CHILD_TYPES: VisitTypes = _
visitor
only.