skia_safe/modules/svg/fe/
types.rs1use std::fmt;
2
3use crate::interop;
4use skia_bindings as sb;
5
6pub type InputType = sb::SkSVGFeInputType_Type;
7variant_name!("InputType::SourceGraphic");
8
9#[repr(C)]
10#[derive(Clone)]
11pub struct Input {
12 kind: InputType,
13 id: interop::String,
14}
15native_transmutable!(sb::SkSVGFeInputType, Input, svg_fe_input_layout);
16
17impl fmt::Debug for Input {
18 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
19 f.debug_struct("SvgFeInput")
20 .field("kind", &self.kind())
21 .field("id", &self.id())
22 .finish()
23 }
24}
25
26impl Input {
27 pub fn kind(&self) -> InputType {
28 self.kind
29 }
30
31 pub fn id(&self) -> Option<&str> {
32 if self.kind == InputType::FilterPrimitiveReference {
33 Some(self.id.as_str())
34 } else {
35 None
36 }
37 }
38
39 pub fn source_graphic() -> Self {
40 Self {
41 kind: InputType::SourceGraphic,
42 id: interop::String::default(),
43 }
44 }
45
46 pub fn source_alpha() -> Self {
47 Self {
48 kind: InputType::SourceAlpha,
49 id: interop::String::default(),
50 }
51 }
52
53 pub fn background_image() -> Self {
54 Self {
55 kind: InputType::BackgroundImage,
56 id: interop::String::default(),
57 }
58 }
59
60 pub fn background_alpha() -> Self {
61 Self {
62 kind: InputType::BackgroundAlpha,
63 id: interop::String::default(),
64 }
65 }
66
67 pub fn fill_paint() -> Self {
68 Self {
69 kind: InputType::FillPaint,
70 id: interop::String::default(),
71 }
72 }
73
74 pub fn stroke_paint() -> Self {
75 Self {
76 kind: InputType::StrokePaint,
77 id: interop::String::default(),
78 }
79 }
80
81 pub fn unspecified() -> Self {
82 Self {
83 kind: InputType::Unspecified,
84 id: interop::String::default(),
85 }
86 }
87
88 pub fn new<T: AsRef<str>>(id: T) -> Self {
89 Self {
90 kind: InputType::FilterPrimitiveReference,
91 id: interop::String::from_str(id.as_ref()),
92 }
93 }
94}