encre_css/plugins/effect/opacity/
mod.rs

1#![doc = include_str!("README.md")]
2#![doc(alias = "effect")]
3use crate::prelude::build_plugin::*;
4
5#[derive(Debug)]
6pub(crate) struct PluginDefinition;
7
8impl Plugin for PluginDefinition {
9    fn can_handle(&self, context: ContextCanHandle) -> bool {
10        matches!(context.modifier, Modifier::Builtin { value, .. } if value.parse::<usize>().is_ok_and(|v| v <= 100))
11    }
12
13    fn handle(&self, context: &mut ContextHandle) {
14        if let Modifier::Builtin { value, .. } = context.modifier {
15            #[allow(clippy::cast_precision_loss)]
16            context.buffer.line(format_args!(
17                "opacity: {};",
18                value.parse::<usize>().unwrap() as f32 / 100.,
19            ));
20        }
21    }
22}