1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use crate::filters::{
FilterRegion,
FilterRegionConfig,
HasFilterRegion,
context::{
FilterContext,
PrimitiveNode,
},
primitives::FilterPrimitive,
};
/// The fluent builder for constructing and configuring a single filter
/// primitive.
///
/// A primitive is only added to the filter graph when [`finish`] is called.
///
/// [`finish`]: Self::finish
#[derive(Debug)]
pub struct PrimitiveBuilder<'a, T>
where
T: Into<FilterPrimitive> + HasFilterRegion,
{
pub(crate) ctx: &'a FilterContext,
pub(crate) inner: T,
}
impl<'a, T> PrimitiveBuilder<'a, T>
where
T: Into<FilterPrimitive> + HasFilterRegion,
{
/// Creates a new [`PrimitiveBuilder`] wrapping the given primitive.
///
/// # Arguments
/// - `ctx`: The [`FilterContext`] that owns the filter graph.
/// - `inner`: The concrete filter primitive being configured.
///
/// # Returns
/// - `Self`
pub(crate) fn new(ctx: &'a FilterContext, inner: T) -> Self {
Self { ctx, inner }
}
/// Finalizes the primitive and registers it with the filter context.
///
/// # Returns
/// - [`PrimitiveNode`] referencing the finalized filter primitive. This can
/// be used as an input to filter primitives.
pub fn finish(self) -> PrimitiveNode {
self.ctx.get_or_add_primitive(self.inner.into())
}
}
impl<'a, T> HasFilterRegion for PrimitiveBuilder<'a, T>
where
T: Into<FilterPrimitive> + HasFilterRegion,
{
fn region_mut(&mut self) -> &mut FilterRegion {
self.inner.region_mut()
}
}
impl<'a, T> FilterRegionConfig for PrimitiveBuilder<'a, T> where
T: Into<FilterPrimitive> + HasFilterRegion
{
}