umya_spreadsheet/structs/drawing/
gradient_stop_list.rs

1// a:gsLst
2use super::GradientStop;
3use crate::reader::driver::*;
4use crate::writer::driver::*;
5use quick_xml::events::{BytesStart, Event};
6use quick_xml::Reader;
7use quick_xml::Writer;
8use std::io::Cursor;
9use thin_vec::ThinVec;
10
11#[derive(Clone, Default, Debug)]
12pub struct GradientStopList {
13    gradient_stop: ThinVec<GradientStop>,
14}
15
16impl GradientStopList {
17    #[inline]
18    pub fn get_gradient_stop(&self) -> &[GradientStop] {
19        &self.gradient_stop
20    }
21
22    #[inline]
23    pub fn get_gradient_stop_mut(&mut self) -> &mut ThinVec<GradientStop> {
24        &mut self.gradient_stop
25    }
26
27    #[inline]
28    pub fn set_gradient_stop(
29        &mut self,
30        value: impl Into<ThinVec<GradientStop>>,
31    ) -> &mut GradientStopList {
32        self.gradient_stop = value.into();
33        self
34    }
35
36    #[inline]
37    pub fn add_gradient_stop(&mut self, value: GradientStop) -> &mut GradientStopList {
38        self.gradient_stop.push(value);
39        self
40    }
41
42    pub(crate) fn set_attributes<R: std::io::BufRead>(
43        &mut self,
44        reader: &mut Reader<R>,
45        _e: &BytesStart,
46    ) {
47        xml_read_loop!(
48            reader,
49            Event::Start(ref e) => {
50                if e.name().into_inner() == b"a:gs" {
51                    let mut obj = GradientStop::default();
52                    obj.set_attributes(reader, e);
53                    self.add_gradient_stop(obj);
54                }
55            },
56            Event::End(ref e) => {
57                if e.name().into_inner() == b"a:gsLst" {
58                    return
59                }
60            },
61            Event::Eof => panic!("Error: Could not find {} end element", "a:gsLst")
62        );
63    }
64
65    pub(crate) fn write_to(&self, writer: &mut Writer<Cursor<Vec<u8>>>) {
66        // a:gsLst
67        write_start_tag(writer, "a:gsLst", vec![], false);
68
69        // a:gs
70        for v in &self.gradient_stop {
71            v.write_to(writer);
72        }
73
74        write_end_tag(writer, "a:gsLst");
75    }
76}