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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
use dioxus::prelude::*;
// * ๐งช cargo test --package icons --lib --features dioxus
#[derive(Debug, Clone)]
pub enum SvgElement {
Path { d: String },
Circle { cx: String, cy: String, r: String },
Rect { x: String, y: String, width: String, height: String, rx: Option<String>, ry: Option<String> },
Ellipse { cx: String, cy: String, rx: String, ry: String },
Line { x1: String, y1: String, x2: String, y2: String },
Polyline { points: String },
Polygon { points: String },
// Add more SVG elements as needed (g, defs, etc.)
}
impl SvgElement {
pub fn to_dioxus_element(&self) -> Element {
match self {
SvgElement::Path { d } => rsx! {
path { d: "{d}" }
},
SvgElement::Circle { cx, cy, r } => rsx! {
circle { cx: "{cx}", cy: "{cy}", r: "{r}" }
},
SvgElement::Rect { x, y, width, height, rx, ry } => match (rx, ry) {
(Some(rx), Some(ry)) => rsx! {
rect {
x: "{x}",
y: "{y}",
width: "{width}",
height: "{height}",
rx: "{rx}",
ry: "{ry}",
}
},
(Some(rx), None) => rsx! {
rect {
x: "{x}",
y: "{y}",
width: "{width}",
height: "{height}",
rx: "{rx}",
}
},
(None, Some(ry)) => rsx! {
rect {
x: "{x}",
y: "{y}",
width: "{width}",
height: "{height}",
ry: "{ry}",
}
},
(None, None) => rsx! {
rect {
x: "{x}",
y: "{y}",
width: "{width}",
height: "{height}",
}
},
},
SvgElement::Ellipse { cx, cy, rx, ry } => rsx! {
ellipse {
cx: "{cx}",
cy: "{cy}",
rx: "{rx}",
ry: "{ry}",
}
},
SvgElement::Line { x1, y1, x2, y2 } => rsx! {
line {
x1: "{x1}",
y1: "{y1}",
x2: "{x2}",
y2: "{y2}",
}
},
SvgElement::Polyline { points } => rsx! {
polyline { points: "{points}" }
},
SvgElement::Polygon { points } => rsx! {
polygon { points: "{points}" }
},
}
}
}