/* 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/. */
//! Generic types for color properties.
usecrate::color::{mix::ColorInterpolationMethod, AbsoluteColor, ColorFunction}; usecrate::values::specified::percentage::ToPercentage; use std::fmt::{self, Write}; use style_traits::{CssWriter, ToCss};
/// This struct represents a combined color from a numeric color and /// the current foreground color (currentcolor keyword). #[derive(Clone, Debug, MallocSizeOf, PartialEq, ToAnimatedValue, ToShmem)] #[repr(C)] pubenum GenericColor<Percentage> { /// The actual numeric color.
Absolute(AbsoluteColor), /// A unresolvable color.
ColorFunction(Box<ColorFunction<Self>>), /// The `CurrentColor` keyword.
CurrentColor, /// The color-mix() function.
ColorMix(Box<GenericColorMix<Self, Percentage>>),
}
/// Flags used to modify the calculation of a color mix result. #[derive(Clone, Copy, Debug, Default, MallocSizeOf, PartialEq, ToShmem)] #[repr(C)] pubstruct ColorMixFlags(u8);
bitflags! { impl ColorMixFlags : u8 { /// Normalize the weights of the mix. const NORMALIZE_WEIGHTS = 1 << 0; /// The result should always be converted to the modern color syntax. const RESULT_IN_MODERN_SYNTAX = 1 << 1;
}
}
/// A restricted version of the css `color-mix()` function, which only supports /// percentages. /// /// https://drafts.csswg.org/css-color-5/#color-mix #[derive(
Clone,
Debug,
MallocSizeOf,
PartialEq,
ToAnimatedValue,
ToComputedValue,
ToResolvedValue,
ToShmem,
)] #[allow(missing_docs)] #[repr(C)] pubstruct GenericColorMix<Color, Percentage> { pub interpolation: ColorInterpolationMethod, pub left: Color, pub left_percentage: Percentage, pub right: Color, pub right_percentage: Percentage, pub flags: ColorMixFlags,
}
impl<Percentage> ColorMix<GenericColor<Percentage>, Percentage> { /// Mix the colors so that we get a single color. If any of the 2 colors are /// not mixable (perhaps not absolute?), then return None. pubfn mix_to_absolute(&self) -> Option<AbsoluteColor> where
Percentage: ToPercentage,
{ let left = self.left.as_absolute()?; let right = self.right.as_absolute()?;
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.