colorimetry_plot/
layer.rs1use std::ops::Deref;
9
10use svg::{node::element::Group, Node};
11
12#[derive(Debug, Clone, Default)]
13pub struct Layer(pub(crate) Group);
14
15impl Layer {
16 pub fn new() -> Self {
17 Layer(Group::new())
18 }
19
20 pub fn add_layer(self, node: impl Into<Box<dyn Node>>) -> Self {
21 Layer(self.0.add(node))
22 }
23
24 pub fn set(self, key: &str, value: impl Into<String>) -> Self {
25 Layer(self.0.set(key, value.into()))
26 }
27
28 }
41
42impl From<Layer> for Box<dyn Node> {
43 fn from(layer: Layer) -> Self {
44 Box::new(layer.0)
45 }
46}
47
48impl std::fmt::Display for Layer {
49 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
50 write!(f, "{}", self.0)
51 }
52}
53
54impl Deref for Layer {
55 type Target = Group;
56
57 fn deref(&self) -> &Self::Target {
58 &self.0
59 }
60}
61
62impl std::ops::DerefMut for Layer {
63 fn deref_mut(&mut self) -> &mut Self::Target {
64 &mut self.0
65 }
66}