diff --git a/src/builtin/color.rs b/src/builtin/color.rs index aa9b81c..6523b7d 100644 --- a/src/builtin/color.rs +++ b/src/builtin/color.rs @@ -39,4 +39,16 @@ pub(crate) fn register(f: &mut BTreeMap) { _ => todo!("non-color given to builtin function `blue()`") } }); + decl!(f "opacity", |args, _| { + match arg!(args, 0, "color") { + Value::Color(c) => Some(Value::Dimension(BigRational::from_integer(BigInt::from(c.alpha())), Unit::None)), + _ => todo!("non-color given to builtin function `opacity()`") + } + }); + decl!(f "alpha", |args, _| { + match arg!(args, 0, "color") { + Value::Color(c) => Some(Value::Dimension(BigRational::from_integer(BigInt::from(c.alpha())), Unit::None)), + _ => todo!("non-color given to builtin function `alpha()`") + } + }); } diff --git a/src/color/mod.rs b/src/color/mod.rs index b591dd3..0aecd2f 100644 --- a/src/color/mod.rs +++ b/src/color/mod.rs @@ -36,6 +36,10 @@ impl Color { self.green } + pub const fn alpha(&self) -> u16 { + self.alpha + } + pub fn from_values(red: u16, green: u16, blue: u16, alpha: u16) -> Self { let repr = if alpha >= 1 { format!("#{:0>2x}{:0>2x}{:0>2x}", red, green, blue)