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