umya_spreadsheet/structs/drawing/
preset_color.rs

1// a:prstClr
2use super::alpha::Alpha;
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;
9
10#[derive(Clone, Default, Debug)]
11pub struct PresetColor {
12    val: Box<str>,
13    alpha: Option<Alpha>,
14}
15
16impl PresetColor {
17    #[inline]
18    pub fn get_val(&self) -> &str {
19        &self.val
20    }
21
22    #[inline]
23    pub fn set_val<S: Into<String>>(&mut self, value: S) {
24        self.val = value.into().into_boxed_str();
25    }
26
27    #[inline]
28    pub fn get_alpha(&self) -> Option<&Alpha> {
29        self.alpha.as_ref()
30    }
31
32    #[inline]
33    pub fn get_alpha_mut(&mut self) -> Option<&mut Alpha> {
34        self.alpha.as_mut()
35    }
36
37    #[inline]
38    pub fn set_alpha(&mut self, value: Alpha) {
39        self.alpha = Some(value);
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        self.set_val(get_attribute(e, b"val").unwrap());
48
49        xml_read_loop!(
50            reader,
51            Event::Empty(ref e) => {
52                if e.name().into_inner() == b"a:alpha" {
53                    let mut alpha = Alpha::default();
54                    alpha.set_attributes(reader, e);
55                    self.set_alpha(alpha);
56                }
57            },
58            Event::End(ref e) => {
59                if e.name().into_inner() == b"a:prstClr" {
60                    return
61                }
62            },
63            Event::Eof => panic!("Error: Could not find {} end element", "a:prstClr")
64        );
65    }
66
67    pub(crate) fn write_to(&self, writer: &mut Writer<Cursor<Vec<u8>>>) {
68        // a:prstClr
69        write_start_tag(writer, "a:prstClr", vec![("val", &self.val)], false);
70
71        // a:alpha
72        if let Some(v) = &self.alpha {
73            v.write_to(writer)
74        }
75
76        write_end_tag(writer, "a:prstClr");
77    }
78}