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
//! Whether a blur clips its output to a shape, and how it reads past the
//! edge of its source.
use crate::{LayerShape, tile_mode::TileMode};
/// Controls blur behavior outside source bounds.
///
/// This mirrors Compose's `BlurredEdgeTreatment`:
/// - bounded treatment (`shape != None`) clips blur output and uses `TileMode::Clamp`
/// - unbounded treatment (`shape == None`) does not clip and uses `TileMode::Decal`
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct BlurredEdgeTreatment {
shape: Option<LayerShape>,
}
impl BlurredEdgeTreatment {
/// Bounded treatment that clips to a rectangle.
pub const RECTANGLE: Self = Self {
shape: Some(LayerShape::Rectangle),
};
/// Unbounded treatment that does not clip blurred output.
pub const UNBOUNDED: Self = Self { shape: None };
/// Bounded treatment with a specific clip shape.
pub const fn with_shape(shape: LayerShape) -> Self {
Self { shape: Some(shape) }
}
/// The shape the blurred output is clipped to, or `None` for the unbounded treatment.
pub fn shape(self) -> Option<LayerShape> {
self.shape
}
/// Whether the blurred output is clipped, which is the case when a clip shape is set.
pub fn clip(self) -> bool {
self.shape.is_some()
}
/// The tile mode blur uses at the edge: `Clamp` when bounded and `Decal` when unbounded.
pub fn tile_mode(self) -> TileMode {
if self.clip() {
TileMode::Clamp
} else {
TileMode::Decal
}
}
}
impl Default for BlurredEdgeTreatment {
fn default() -> Self {
Self::RECTANGLE
}
}