umya_spreadsheet/structs/drawing/charts/
manual_layout.rs1use std::io::Cursor;
3
4use quick_xml::{
5 Reader,
6 Writer,
7 events::{
8 BytesStart,
9 Event,
10 },
11};
12
13use super::{
14 Height,
15 HeightMode,
16 LayoutTarget,
17 Left,
18 LeftMode,
19 Top,
20 TopMode,
21 Width,
22 WidthMode,
23};
24use crate::{
25 writer::driver::{
26 write_end_tag,
27 write_start_tag,
28 },
29 xml_read_loop,
30};
31
32#[derive(Clone, Default, Debug)]
33pub struct ManualLayout {
34 height: Option<Height>,
35 height_mode: Option<HeightMode>,
36 layout_target: Option<LayoutTarget>,
37 left: Option<Left>,
38 left_mode: Option<LeftMode>,
39 top: Option<Top>,
40 top_mode: Option<TopMode>,
41 width: Option<Width>,
42 width_mode: Option<WidthMode>,
43}
44
45impl ManualLayout {
46 #[must_use]
47 pub fn height(&self) -> Option<&Height> {
48 self.height.as_ref()
49 }
50
51 #[must_use]
52 #[deprecated(since = "3.0.0", note = "Use height()")]
53 pub fn get_height(&self) -> Option<&Height> {
54 self.height()
55 }
56
57 pub fn height_mut(&mut self) -> Option<&mut Height> {
58 self.height.as_mut()
59 }
60
61 #[deprecated(since = "3.0.0", note = "Use height_mut()")]
62 pub fn get_height_mut(&mut self) -> Option<&mut Height> {
63 self.height_mut()
64 }
65
66 pub fn set_height(&mut self, value: Height) -> &mut ManualLayout {
67 self.height = Some(value);
68 self
69 }
70
71 #[must_use]
72 pub fn height_mode(&self) -> Option<&HeightMode> {
73 self.height_mode.as_ref()
74 }
75
76 #[must_use]
77 #[deprecated(since = "3.0.0", note = "Use height_mode()")]
78 pub fn get_height_mode(&self) -> Option<&HeightMode> {
79 self.height_mode()
80 }
81
82 pub fn height_mode_mut(&mut self) -> Option<&mut HeightMode> {
83 self.height_mode.as_mut()
84 }
85
86 #[deprecated(since = "3.0.0", note = "Use height_mode_mut()")]
87 pub fn get_height_mode_mut(&mut self) -> Option<&mut HeightMode> {
88 self.height_mode_mut()
89 }
90
91 pub fn set_height_mode(&mut self, value: HeightMode) -> &mut ManualLayout {
92 self.height_mode = Some(value);
93 self
94 }
95
96 #[must_use]
97 pub fn layout_target(&self) -> Option<&LayoutTarget> {
98 self.layout_target.as_ref()
99 }
100
101 #[must_use]
102 #[deprecated(since = "3.0.0", note = "Use layout_target()")]
103 pub fn get_layout_target(&self) -> Option<&LayoutTarget> {
104 self.layout_target()
105 }
106
107 pub fn layout_target_mut(&mut self) -> Option<&mut LayoutTarget> {
108 self.layout_target.as_mut()
109 }
110
111 #[deprecated(since = "3.0.0", note = "Use layout_target_mut()")]
112 pub fn get_layout_target_mut(&mut self) -> Option<&mut LayoutTarget> {
113 self.layout_target_mut()
114 }
115
116 pub fn set_layout_target(&mut self, value: LayoutTarget) -> &mut ManualLayout {
117 self.layout_target = Some(value);
118 self
119 }
120
121 #[must_use]
122 pub fn left(&self) -> Option<&Left> {
123 self.left.as_ref()
124 }
125
126 #[must_use]
127 #[deprecated(since = "3.0.0", note = "Use left()")]
128 pub fn get_left(&self) -> Option<&Left> {
129 self.left()
130 }
131
132 pub fn left_mut(&mut self) -> Option<&mut Left> {
133 self.left.as_mut()
134 }
135
136 #[deprecated(since = "3.0.0", note = "Use left_mut()")]
137 pub fn get_left_mut(&mut self) -> Option<&mut Left> {
138 self.left_mut()
139 }
140
141 pub fn set_left(&mut self, value: Left) -> &mut ManualLayout {
142 self.left = Some(value);
143 self
144 }
145
146 #[must_use]
147 pub fn left_mode(&self) -> Option<&LeftMode> {
148 self.left_mode.as_ref()
149 }
150
151 #[must_use]
152 #[deprecated(since = "3.0.0", note = "Use left_mode()")]
153 pub fn get_left_mode(&self) -> Option<&LeftMode> {
154 self.left_mode()
155 }
156
157 pub fn left_mode_mut(&mut self) -> Option<&mut LeftMode> {
158 self.left_mode.as_mut()
159 }
160
161 #[deprecated(since = "3.0.0", note = "Use left_mode_mut()")]
162 pub fn get_left_mode_mut(&mut self) -> Option<&mut LeftMode> {
163 self.left_mode_mut()
164 }
165
166 pub fn set_left_mode(&mut self, value: LeftMode) -> &mut ManualLayout {
167 self.left_mode = Some(value);
168 self
169 }
170
171 #[must_use]
172 pub fn top(&self) -> Option<&Top> {
173 self.top.as_ref()
174 }
175
176 #[must_use]
177 #[deprecated(since = "3.0.0", note = "Use top()")]
178 pub fn get_top(&self) -> Option<&Top> {
179 self.top()
180 }
181
182 pub fn top_mut(&mut self) -> Option<&mut Top> {
183 self.top.as_mut()
184 }
185
186 #[deprecated(since = "3.0.0", note = "Use top_mut()")]
187 pub fn get_top_mut(&mut self) -> Option<&mut Top> {
188 self.top_mut()
189 }
190
191 pub fn set_top(&mut self, value: Top) -> &mut ManualLayout {
192 self.top = Some(value);
193 self
194 }
195
196 #[must_use]
197 pub fn top_mode(&self) -> Option<&TopMode> {
198 self.top_mode.as_ref()
199 }
200
201 #[must_use]
202 #[deprecated(since = "3.0.0", note = "Use top_mode()")]
203 pub fn get_top_mode(&self) -> Option<&TopMode> {
204 self.top_mode()
205 }
206
207 pub fn top_mode_mut(&mut self) -> Option<&mut TopMode> {
208 self.top_mode.as_mut()
209 }
210
211 #[deprecated(since = "3.0.0", note = "Use top_mode_mut()")]
212 pub fn get_top_mode_mut(&mut self) -> Option<&mut TopMode> {
213 self.top_mode_mut()
214 }
215
216 pub fn set_top_mode(&mut self, value: TopMode) -> &mut ManualLayout {
217 self.top_mode = Some(value);
218 self
219 }
220
221 #[must_use]
222 pub fn width(&self) -> Option<&Width> {
223 self.width.as_ref()
224 }
225
226 #[must_use]
227 #[deprecated(since = "3.0.0", note = "Use width()")]
228 pub fn get_width(&self) -> Option<&Width> {
229 self.width()
230 }
231
232 pub fn width_mut(&mut self) -> Option<&mut Width> {
233 self.width.as_mut()
234 }
235
236 #[deprecated(since = "3.0.0", note = "Use width_mut()")]
237 pub fn get_width_mut(&mut self) -> Option<&mut Width> {
238 self.width_mut()
239 }
240
241 pub fn set_width(&mut self, value: Width) -> &mut ManualLayout {
242 self.width = Some(value);
243 self
244 }
245
246 #[must_use]
247 pub fn width_mode(&self) -> Option<&WidthMode> {
248 self.width_mode.as_ref()
249 }
250
251 #[must_use]
252 #[deprecated(since = "3.0.0", note = "Use width_mode()")]
253 pub fn get_width_mode(&self) -> Option<&WidthMode> {
254 self.width_mode()
255 }
256
257 pub fn width_mode_mut(&mut self) -> Option<&mut WidthMode> {
258 self.width_mode.as_mut()
259 }
260
261 #[deprecated(since = "3.0.0", note = "Use width_mode_mut()")]
262 pub fn get_width_mode_mut(&mut self) -> Option<&mut WidthMode> {
263 self.width_mode_mut()
264 }
265
266 pub fn set_width_mode(&mut self, value: WidthMode) -> &mut ManualLayout {
267 self.width_mode = Some(value);
268 self
269 }
270
271 #[must_use]
272 pub fn is_empty(&self) -> bool {
273 self.height.is_none()
274 && self.height_mode.is_none()
275 && self.layout_target.is_none()
276 && self.left.is_none()
277 && self.left_mode.is_none()
278 && self.top.is_none()
279 && self.top_mode.is_none()
280 && self.width.is_none()
281 && self.width_mode.is_none()
282 }
283
284 pub(crate) fn set_attributes<R: std::io::BufRead>(
285 &mut self,
286 reader: &mut Reader<R>,
287 _e: &BytesStart,
288 ) {
289 xml_read_loop!(
290 reader,
291 Event::Empty(ref e) => match e.name().0 {
292 b"c:h" => {
293 let mut obj = Height::default();
294 obj.set_attributes(reader, e);
295 self.set_height(obj);
296 }
297 b"c:hMode" => {
298 let mut obj = HeightMode::default();
299 obj.set_attributes(reader, e);
300 self.set_height_mode(obj);
301 }
302 b"c:layoutTarget" => {
303 let mut obj = LayoutTarget::default();
304 obj.set_attributes(reader, e);
305 self.set_layout_target(obj);
306 }
307 b"c:x" => {
308 let mut obj = Left::default();
309 obj.set_attributes(reader, e);
310 self.set_left(obj);
311 }
312 b"c:xMode" => {
313 let mut obj = LeftMode::default();
314 obj.set_attributes(reader, e);
315 self.set_left_mode(obj);
316 }
317 b"c:y" => {
318 let mut obj = Top::default();
319 obj.set_attributes(reader, e);
320 self.set_top(obj);
321 }
322 b"c:yMode" => {
323 let mut obj = TopMode::default();
324 obj.set_attributes(reader, e);
325 self.set_top_mode(obj);
326 }
327 b"c:w" => {
328 let mut obj = Width::default();
329 obj.set_attributes(reader, e);
330 self.set_width(obj);
331 }
332 b"c:wMode" => {
333 let mut obj = WidthMode::default();
334 obj.set_attributes(reader, e);
335 self.set_width_mode(obj);
336 }
337 _ => (),
338 },
339 Event::End(ref e) => {
340 if e.name().0 == b"c:manualLayout" {
341 return;
342 }
343 },
344 Event::Eof => panic!("Error: Could not find {} end element", "c:manualLayout"),
345 );
346 }
347
348 pub(crate) fn write_to(&self, writer: &mut Writer<Cursor<Vec<u8>>>) {
349 write_start_tag(writer, "c:manualLayout", vec![], false);
351
352 if let Some(v) = &self.height_mode {
354 v.write_to(writer);
355 }
356
357 if let Some(v) = &self.left_mode {
359 v.write_to(writer);
360 }
361
362 if let Some(v) = &self.top_mode {
364 v.write_to(writer);
365 }
366
367 if let Some(v) = &self.width_mode {
369 v.write_to(writer);
370 }
371
372 if let Some(v) = &self.height {
374 v.write_to(writer);
375 }
376
377 if let Some(v) = &self.left {
379 v.write_to(writer);
380 }
381
382 if let Some(v) = &self.top {
384 v.write_to(writer);
385 }
386
387 if let Some(v) = &self.width {
389 v.write_to(writer);
390 }
391
392 if let Some(v) = &self.layout_target {
394 v.write_to(writer);
395 }
396
397 write_end_tag(writer, "c:manualLayout");
398 }
399}