Implement built in functions opacity
and alpha
This commit is contained in:
parent
4585558266
commit
04d2c4ab74
@ -39,4 +39,16 @@ pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
|
|||||||
_ => todo!("non-color given to builtin function `blue()`")
|
_ => 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()`")
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,10 @@ impl Color {
|
|||||||
self.green
|
self.green
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub const fn alpha(&self) -> u16 {
|
||||||
|
self.alpha
|
||||||
|
}
|
||||||
|
|
||||||
pub fn from_values(red: u16, green: u16, blue: u16, alpha: u16) -> Self {
|
pub fn from_values(red: u16, green: u16, blue: u16, alpha: u16) -> Self {
|
||||||
let repr = if alpha >= 1 {
|
let repr = if alpha >= 1 {
|
||||||
format!("#{:0>2x}{:0>2x}{:0>2x}", red, green, blue)
|
format!("#{:0>2x}{:0>2x}{:0>2x}", red, green, blue)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user