umya_spreadsheet/structs/drawing/
system_color.rs1use super::super::super::EnumValue;
3use super::super::super::StringValue;
4use super::SystemColorValues;
5use crate::reader::driver::*;
6use crate::writer::driver::*;
7use quick_xml::events::{BytesStart, Event};
8use quick_xml::Reader;
9use quick_xml::Writer;
10use std::io::Cursor;
11
12#[derive(Clone, Default, Debug)]
13pub struct SystemColor {
14 val: EnumValue<SystemColorValues>,
15 last_color: StringValue,
16}
17
18impl SystemColor {
19 #[inline]
20 pub fn get_val(&self) -> &SystemColorValues {
21 self.val.get_value()
22 }
23
24 #[inline]
25 pub fn set_val(&mut self, value: SystemColorValues) -> &mut Self {
26 self.val.set_value(value);
27 self
28 }
29
30 #[inline]
31 pub fn get_last_color(&self) -> &str {
32 self.last_color.get_value_str()
33 }
34
35 #[inline]
36 pub fn set_last_color<S: Into<String>>(&mut self, value: S) {
37 self.last_color.set_value(value.into());
38 }
39
40 #[inline]
41 pub(crate) fn set_attributes<R: std::io::BufRead>(
42 &mut self,
43 reader: &mut Reader<R>,
44 e: &BytesStart,
45 empty_flag: bool,
46 ) {
47 set_string_from_xml!(self, e, val, "val");
48 set_string_from_xml!(self, e, last_color, "lastClr");
49
50 if empty_flag {
51 return;
52 }
53
54 xml_read_loop!(
55 reader,
56 Event::End(ref e) => {
57 if e.name().into_inner() == b"a:sysClr" {
58 return;
59 }
60 },
61 Event::Eof => panic!("Error: Could not find {} end element", "a:sysClr")
62 );
63 }
64
65 pub(crate) fn write_to(&self, writer: &mut Writer<Cursor<Vec<u8>>>) {
66 let mut attributes: Vec<(&str, &str)> = Vec::new();
68 let val = self.val.get_value_string();
69 if self.val.has_value() {
70 attributes.push(("val", val));
71 }
72 let last_color = self.last_color.get_value_str();
73 if self.last_color.has_value() {
74 attributes.push(("lastClr", last_color));
75 }
76 write_start_tag(writer, "a:sysClr", attributes, true);
77 }
78}