/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
//! Computed color values.
usecrate::color::AbsoluteColor; usecrate::values::animated::ToAnimatedZero; usecrate::values::computed::percentage::Percentage; usecrate::values::generics::color::{
GenericCaretColor, GenericColor, GenericColorMix, GenericColorOrAuto,
}; use std::fmt::{self, Write}; use style_traits::{CssWriter, ToCss};
/// The computed value of the `color` property. pubtype ColorPropertyValue = AbsoluteColor;
/// A computed value for `<color>`. pubtype Color = GenericColor<Percentage>;
/// A computed color-mix(). pubtype ColorMix = GenericColorMix<Color, Percentage>;
impl ToCss for Color { fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where
W: fmt::Write,
{ match *self { Self::Absolute(ref c) => c.to_css(dest), Self::ColorFunction(ref color_function) => color_function.to_css(dest), Self::CurrentColor => dest.write_str("currentcolor"), Self::ColorMix(ref m) => m.to_css(dest),
}
}
}
impl Color { /// A fully transparent color. pubconst TRANSPARENT_BLACK: Self = Self::Absolute(AbsoluteColor::TRANSPARENT_BLACK);
/// An opaque black color. pubconst BLACK: Self = Self::Absolute(AbsoluteColor::BLACK);
/// An opaque white color. pubconst WHITE: Self = Self::Absolute(AbsoluteColor::WHITE);
/// Create a new computed [`Color`] from a given color-mix, simplifying it to an absolute color /// if possible. pubfn from_color_mix(color_mix: ColorMix) -> Self { iflet Some(absolute) = color_mix.mix_to_absolute() { Self::Absolute(absolute)
} else { Self::ColorMix(Box::new(color_mix))
}
}
/// Combine this complex color with the given foreground color into an /// absolute color. pubfn resolve_to_absolute(&self, current_color: &AbsoluteColor) -> AbsoluteColor { usecrate::values::specified::percentage::ToPercentage;
match *self { Self::Absolute(c) => c, Self::ColorFunction(ref color_function) => {
color_function.resolve_to_absolute(current_color)
}, Self::CurrentColor => *current_color, Self::ColorMix(ref mix) => { let left = mix.left.resolve_to_absolute(current_color); let right = mix.right.resolve_to_absolute(current_color); crate::color::mix::mix(
mix.interpolation,
&left,
mix.left_percentage.to_percentage(),
&right,
mix.right_percentage.to_percentage(),
mix.flags,
)
},
}
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.