Skip to main content

umya_spreadsheet/structs/drawing/
background_fill_style_list.rs

1use std::io::Cursor;
2
3use quick_xml::{
4    Reader,
5    Writer,
6    events::{
7        BytesStart,
8        Event,
9    },
10};
11
12use super::{
13    GradientFill,
14    SolidFill,
15};
16use crate::{
17    reader::driver::xml_read_loop,
18    writer::driver::{
19        write_end_tag,
20        write_start_tag,
21    },
22};
23
24#[derive(Clone, Default, Debug)]
25pub struct BackgroundFillStyleList {
26    solid_fill:               Vec<SolidFill>,
27    gradient_fill_collection: Vec<GradientFill>,
28}
29
30impl BackgroundFillStyleList {
31    #[inline]
32    #[must_use]
33    pub fn solid_fill(&self) -> &[SolidFill] {
34        &self.solid_fill
35    }
36
37    #[inline]
38    #[must_use]
39    #[deprecated(since = "3.0.0", note = "Use solid_fill()")]
40    pub fn get_solid_fill(&self) -> &[SolidFill] {
41        self.solid_fill()
42    }
43
44    #[inline]
45    pub fn solid_fill_mut(&mut self) -> &mut Vec<SolidFill> {
46        &mut self.solid_fill
47    }
48
49    #[inline]
50    #[deprecated(since = "3.0.0", note = "Use solid_fill_mut()")]
51    pub fn get_solid_fill_mut(&mut self) -> &mut Vec<SolidFill> {
52        self.solid_fill_mut()
53    }
54
55    #[inline]
56    pub fn set_solid_fill(&mut self, value: impl Into<Vec<SolidFill>>) -> &mut Self {
57        self.solid_fill = value.into();
58        self
59    }
60
61    #[inline]
62    pub fn add_solid_fill(&mut self, value: SolidFill) -> &mut Self {
63        self.solid_fill.push(value);
64        self
65    }
66
67    #[inline]
68    #[must_use]
69    pub fn gradient_fill_collection(&self) -> &[GradientFill] {
70        &self.gradient_fill_collection
71    }
72
73    #[inline]
74    #[must_use]
75    #[deprecated(since = "3.0.0", note = "Use gradient_fill_collection()")]
76    pub fn get_gradient_fill_collection(&self) -> &[GradientFill] {
77        self.gradient_fill_collection()
78    }
79
80    #[inline]
81    pub fn gradient_fill_collectionl_mut(&mut self) -> &mut Vec<GradientFill> {
82        &mut self.gradient_fill_collection
83    }
84
85    #[inline]
86    #[deprecated(since = "3.0.0", note = "Use gradient_fill_collectionl_mut()")]
87    pub fn get_gradient_fill_collectionl_mut(&mut self) -> &mut Vec<GradientFill> {
88        self.gradient_fill_collectionl_mut()
89    }
90
91    #[inline]
92    pub fn set_gradient_fill_collection(
93        &mut self,
94        value: impl Into<Vec<GradientFill>>,
95    ) -> &mut Self {
96        self.gradient_fill_collection = value.into();
97        self
98    }
99
100    #[inline]
101    pub fn add_gradient_fill_collection(&mut self, value: GradientFill) -> &mut Self {
102        self.gradient_fill_collection.push(value);
103        self
104    }
105
106    pub(crate) fn set_attributes<R: std::io::BufRead>(
107        &mut self,
108        reader: &mut Reader<R>,
109        _e: &BytesStart,
110    ) {
111        xml_read_loop!(
112            reader,
113            Event::Start(ref e) => {
114                match e.name().into_inner() {
115                b"a:solidFill" => {
116                    let mut obj = SolidFill::default();
117                    obj.set_attributes(reader, e);
118                    self.solid_fill.push(obj);
119                }
120                b"a:gradFill" => {
121                    let mut obj = GradientFill::default();
122                    obj.set_attributes(reader, e);
123                    self.gradient_fill_collection.push(obj);
124                }
125                _ => (),
126                }
127            },
128            Event::End(ref e) => {
129                if  e.name().into_inner() == b"a:bgFillStyleLst" {
130                    return
131                }
132            },
133            Event::Eof => panic!("Error: Could not find {} end element", "bgFillStyleLst")
134        );
135    }
136
137    pub(crate) fn write_to(&self, writer: &mut Writer<Cursor<Vec<u8>>>) {
138        // a:bgFillStyleLst
139        write_start_tag(writer, "a:bgFillStyleLst", vec![], false);
140
141        // a:solidFill
142        for v in &self.solid_fill {
143            v.write_to(writer);
144        }
145
146        // a:gradFill
147        for v in &self.gradient_fill_collection {
148            v.write_to(writer);
149        }
150
151        write_end_tag(writer, "a:bgFillStyleLst");
152    }
153}