Skip to main content

umya_spreadsheet/structs/drawing/
system_color.rs

1// a:sysClr
2use std::io::Cursor;
3
4use quick_xml::{
5    Reader,
6    Writer,
7    events::{
8        BytesStart,
9        Event,
10    },
11};
12
13use super::{
14    super::super::{
15        EnumValue,
16        StringValue,
17    },
18    SystemColorValues,
19};
20use crate::{
21    reader::driver::{
22        get_attribute,
23        set_string_from_xml,
24        xml_read_loop,
25    },
26    writer::driver::write_start_tag,
27};
28
29#[derive(Clone, Default, Debug)]
30pub struct SystemColor {
31    val:        EnumValue<SystemColorValues>,
32    last_color: StringValue,
33}
34
35impl SystemColor {
36    #[inline]
37    #[must_use]
38    pub fn val(&self) -> &SystemColorValues {
39        self.val.value()
40    }
41
42    #[inline]
43    #[must_use]
44    #[deprecated(since = "3.0.0", note = "Use val()")]
45    pub fn get_val(&self) -> &SystemColorValues {
46        self.val()
47    }
48
49    #[inline]
50    pub fn set_val(&mut self, value: SystemColorValues) -> &mut Self {
51        self.val.set_value(value);
52        self
53    }
54
55    #[inline]
56    #[must_use]
57    pub fn last_color(&self) -> &str {
58        self.last_color.value_str()
59    }
60
61    #[inline]
62    #[must_use]
63    #[deprecated(since = "3.0.0", note = "Use last_color()")]
64    pub fn get_last_color(&self) -> &str {
65        self.last_color()
66    }
67
68    #[inline]
69    pub fn set_last_color<S: Into<String>>(&mut self, value: S) {
70        self.last_color.set_value(value.into());
71    }
72
73    #[inline]
74    pub(crate) fn set_attributes<R: std::io::BufRead>(
75        &mut self,
76        reader: &mut Reader<R>,
77        e: &BytesStart,
78        empty_flag: bool,
79    ) {
80        set_string_from_xml!(self, e, val, "val");
81        set_string_from_xml!(self, e, last_color, "lastClr");
82
83        if empty_flag {
84            return;
85        }
86
87        xml_read_loop!(
88            reader,
89            Event::End(ref e) => {
90                if e.name().into_inner() == b"a:sysClr" {
91                    return;
92                }
93            },
94            Event::Eof => panic!("Error: Could not find {} end element", "a:sysClr")
95        );
96    }
97
98    pub(crate) fn write_to(&self, writer: &mut Writer<Cursor<Vec<u8>>>) {
99        // a:srgbClr
100        let mut attributes: crate::structs::AttrCollection = Vec::new();
101        let val = self.val.value_string();
102        if self.val.has_value() {
103            attributes.push(("val", val).into());
104        }
105        let last_color = self.last_color.value_str();
106        if self.last_color.has_value() {
107            attributes.push(("lastClr", last_color).into());
108        }
109        write_start_tag(writer, "a:sysClr", attributes, true);
110    }
111}