Skip to main content

umya_spreadsheet/structs/drawing/
source_rectangle.rs

1// a:srcRect
2use std::io::Cursor;
3
4use quick_xml::{
5    Reader,
6    Writer,
7    events::BytesStart,
8};
9
10use crate::{
11    StringValue,
12    reader::driver::get_attribute_value,
13    writer::driver::write_start_tag,
14};
15
16#[derive(Clone, Default, Debug)]
17pub struct SourceRectangle {
18    t: StringValue,
19    l: StringValue,
20    r: StringValue,
21    b: StringValue,
22}
23impl SourceRectangle {
24    #[inline]
25    pub fn set_t<S: Into<String>>(&mut self, value: S) {
26        self.t.set_value(value);
27    }
28
29    #[inline]
30    #[must_use]
31    pub fn t(&self) -> Option<&str> {
32        self.t.value()
33    }
34
35    #[inline]
36    #[must_use]
37    #[deprecated(since = "3.0.0", note = "Use t()")]
38    pub fn get_t(&self) -> Option<&str> {
39        self.t()
40    }
41
42    #[inline]
43    pub fn set_l<S: Into<String>>(&mut self, value: S) {
44        self.l.set_value(value);
45    }
46
47    #[inline]
48    #[must_use]
49    pub fn l(&self) -> Option<&str> {
50        self.l.value()
51    }
52
53    #[inline]
54    #[must_use]
55    #[deprecated(since = "3.0.0", note = "Use l()")]
56    pub fn get_l(&self) -> Option<&str> {
57        self.l()
58    }
59
60    #[inline]
61    pub fn set_r<S: Into<String>>(&mut self, value: S) {
62        self.r.set_value(value);
63    }
64
65    #[inline]
66    #[must_use]
67    pub fn r(&self) -> Option<&str> {
68        self.r.value()
69    }
70
71    #[inline]
72    #[must_use]
73    #[deprecated(since = "3.0.0", note = "Use r()")]
74    pub fn get_r(&self) -> Option<&str> {
75        self.r()
76    }
77
78    #[inline]
79    pub fn set_b<S: Into<String>>(&mut self, value: S) {
80        self.b.set_value(value);
81    }
82
83    #[inline]
84    #[must_use]
85    pub fn b(&self) -> Option<&str> {
86        self.b.value()
87    }
88
89    #[inline]
90    #[must_use]
91    #[deprecated(since = "3.0.0", note = "Use b()")]
92    pub fn get_b(&self) -> Option<&str> {
93        self.b()
94    }
95
96    pub(crate) fn set_attributes<R: std::io::BufRead>(
97        &mut self,
98        _reader: &mut Reader<R>,
99        e: &BytesStart,
100    ) {
101        for attr in e.attributes().with_checks(false).flatten() {
102            match attr.key.0 {
103                b"t" => self.set_t(get_attribute_value(&attr).unwrap()),
104                b"l" => self.set_l(get_attribute_value(&attr).unwrap()),
105                b"r" => self.set_r(get_attribute_value(&attr).unwrap()),
106                b"b" => self.set_b(get_attribute_value(&attr).unwrap()),
107                _ => {}
108            }
109        }
110    }
111
112    pub(crate) fn write_to(&self, writer: &mut Writer<Cursor<Vec<u8>>>) {
113        // a:srcRect
114        let mut attributes: crate::structs::AttrCollection = Vec::new();
115
116        if let Some(v) = self.t.value() {
117            attributes.push(("t", v).into());
118        }
119        if let Some(v) = self.l.value() {
120            attributes.push(("l", v).into());
121        }
122        if let Some(v) = self.r.value() {
123            attributes.push(("r", v).into());
124        }
125        if let Some(v) = self.b.value() {
126            attributes.push(("b", v).into());
127        }
128        write_start_tag(writer, "a:srcRect", attributes, true);
129    }
130}