Skip to main content

umya_spreadsheet/structs/drawing/
effect_style.rs

1use std::{
2    io::Cursor,
3    vec,
4};
5
6use quick_xml::{
7    Reader,
8    Writer,
9    events::{
10        BytesStart,
11        Event,
12    },
13};
14
15use super::{
16    EffectList,
17    Scene3DType,
18    Shape3DType,
19};
20use crate::{
21    reader::driver::xml_read_loop,
22    writer::driver::{
23        write_end_tag,
24        write_start_tag,
25    },
26};
27
28#[derive(Clone, Default, Debug)]
29pub struct EffectStyle {
30    effect_list:   Option<Box<EffectList>>,
31    scene_3d_type: Option<Box<Scene3DType>>,
32    shape_3d_type: Option<Box<Shape3DType>>,
33}
34
35impl EffectStyle {
36    #[inline]
37    #[must_use]
38    pub fn effect_list(&self) -> Option<&EffectList> {
39        self.effect_list.as_deref()
40    }
41
42    #[inline]
43    #[must_use]
44    #[deprecated(since = "3.0.0", note = "Use effect_list()")]
45    pub fn get_effect_list(&self) -> Option<&EffectList> {
46        self.effect_list()
47    }
48
49    #[inline]
50    pub fn effect_list_mut(&mut self) -> Option<&mut EffectList> {
51        self.effect_list.as_deref_mut()
52    }
53
54    #[inline]
55    #[deprecated(since = "3.0.0", note = "Use effect_list_mut()")]
56    pub fn get_effect_list_mut(&mut self) -> Option<&mut EffectList> {
57        self.effect_list_mut()
58    }
59
60    #[inline]
61    pub fn set_effect_list(&mut self, value: EffectList) -> &mut Self {
62        self.effect_list = Some(Box::new(value));
63        self
64    }
65
66    #[inline]
67    #[must_use]
68    pub fn scene_3d_type(&self) -> Option<&Scene3DType> {
69        self.scene_3d_type.as_deref()
70    }
71
72    #[inline]
73    #[must_use]
74    #[deprecated(since = "3.0.0", note = "Use scene_3d_type()")]
75    pub fn get_scene_3d_type(&self) -> Option<&Scene3DType> {
76        self.scene_3d_type()
77    }
78
79    #[inline]
80    pub fn scene_3d_type_mut(&mut self) -> Option<&mut Scene3DType> {
81        self.scene_3d_type.as_deref_mut()
82    }
83
84    #[inline]
85    #[deprecated(since = "3.0.0", note = "Use scene_3d_type_mut()")]
86    pub fn get_scene_3d_type_mut(&mut self) -> Option<&mut Scene3DType> {
87        self.scene_3d_type_mut()
88    }
89
90    #[inline]
91    pub fn set_scene_3d_type(&mut self, value: Scene3DType) -> &mut Self {
92        self.scene_3d_type = Some(Box::new(value));
93        self
94    }
95
96    #[inline]
97    #[must_use]
98    pub fn shape_3d_type(&self) -> Option<&Shape3DType> {
99        self.shape_3d_type.as_deref()
100    }
101
102    #[inline]
103    #[must_use]
104    #[deprecated(since = "3.0.0", note = "Use shape_3d_type()")]
105    pub fn get_shape_3d_type(&self) -> Option<&Shape3DType> {
106        self.shape_3d_type()
107    }
108
109    #[inline]
110    pub fn shape_3d_type_mut(&mut self) -> Option<&mut Shape3DType> {
111        self.shape_3d_type.as_deref_mut()
112    }
113
114    #[inline]
115    #[deprecated(since = "3.0.0", note = "Use shape_3d_type_mut()")]
116    pub fn get_shape_3d_type_mut(&mut self) -> Option<&mut Shape3DType> {
117        self.shape_3d_type_mut()
118    }
119
120    #[inline]
121    pub fn set_shape_3d_type(&mut self, value: Shape3DType) -> &mut Self {
122        self.shape_3d_type = Some(Box::new(value));
123        self
124    }
125
126    pub(crate) fn set_attributes<R: std::io::BufRead>(
127        &mut self,
128        reader: &mut Reader<R>,
129        _e: &BytesStart,
130    ) {
131        xml_read_loop!(
132            reader,
133            ref n @ (Event::Empty(ref e) | Event::Start(ref e)) => {
134                let is_empty = matches!(n, Event::Empty(_));
135                match e.name().into_inner() {
136                b"a:effectLst" => {
137                    let mut obj = EffectList::default();
138                    obj.set_attributes(reader, e, is_empty);
139                    self.effect_list = Some(Box::new(obj));
140                }
141                b"a:scene3d" => {
142                    let mut obj = Scene3DType::default();
143                    obj.set_attributes(reader, e);
144                    self.scene_3d_type = Some(Box::new(obj));
145                }
146                b"a:sp3d" => {
147                    let mut obj = Shape3DType::default();
148                    obj.set_attributes(reader, e);
149                    self.shape_3d_type = Some(Box::new(obj));
150                }
151                _ => (),
152                }
153            },
154            Event::End(ref e) => {
155                if e.name().into_inner() == b"a:effectStyle" {
156                    return
157                }
158            },
159            Event::Eof => panic!("Error: Could not find {} end element", "a:effectStyle")
160        );
161    }
162
163    pub(crate) fn write_to(&self, writer: &mut Writer<Cursor<Vec<u8>>>) {
164        write_start_tag(writer, "a:effectStyle", vec![], false);
165
166        // a:effectLst
167        if let Some(v) = &self.effect_list {
168            v.write_to(writer);
169        }
170
171        // a:scene3d
172        if let Some(v) = &self.scene_3d_type {
173            v.write_to(writer);
174        }
175
176        // a:sp3d
177        if let Some(v) = &self.shape_3d_type {
178            v.write_to(writer);
179        }
180
181        write_end_tag(writer, "a:effectStyle");
182    }
183}