Skip to main content

umya_spreadsheet/structs/drawing/
theme_elements.rs

1// a:themeElements
2use std::io::Cursor;
3
4use quick_xml::{
5    Reader,
6    Writer,
7    events::{
8        BytesStart,
9        Event,
10    },
11};
12
13use super::{
14    ColorScheme,
15    FontScheme,
16    FormatScheme,
17};
18use crate::{
19    reader::driver::xml_read_loop,
20    writer::driver::{
21        write_end_tag,
22        write_start_tag,
23    },
24};
25
26#[derive(Clone, Default, Debug)]
27pub struct ThemeElements {
28    color_scheme:  ColorScheme,
29    font_scheme:   FontScheme,
30    format_scheme: FormatScheme,
31}
32
33impl ThemeElements {
34    #[inline]
35    #[must_use]
36    pub fn color_scheme(&self) -> &ColorScheme {
37        &self.color_scheme
38    }
39
40    #[inline]
41    #[must_use]
42    #[deprecated(since = "3.0.0", note = "Use color_scheme()")]
43    pub fn get_color_scheme(&self) -> &ColorScheme {
44        self.color_scheme()
45    }
46
47    #[inline]
48    pub fn color_scheme_mut(&mut self) -> &mut ColorScheme {
49        &mut self.color_scheme
50    }
51
52    #[inline]
53    #[deprecated(since = "3.0.0", note = "Use color_scheme_mut()")]
54    pub fn get_color_scheme_mut(&mut self) -> &mut ColorScheme {
55        self.color_scheme_mut()
56    }
57
58    #[inline]
59    pub fn set_color_scheme(&mut self, value: ColorScheme) -> &mut Self {
60        self.color_scheme = value;
61        self
62    }
63
64    #[inline]
65    #[must_use]
66    pub fn font_scheme(&self) -> &FontScheme {
67        &self.font_scheme
68    }
69
70    #[inline]
71    #[must_use]
72    #[deprecated(since = "3.0.0", note = "Use font_scheme()")]
73    pub fn get_font_scheme(&self) -> &FontScheme {
74        self.font_scheme()
75    }
76
77    #[inline]
78    pub fn font_scheme_mut(&mut self) -> &mut FontScheme {
79        &mut self.font_scheme
80    }
81
82    #[inline]
83    #[deprecated(since = "3.0.0", note = "Use font_scheme_mut()")]
84    pub fn get_font_scheme_mut(&mut self) -> &mut FontScheme {
85        self.font_scheme_mut()
86    }
87
88    #[inline]
89    pub fn set_font_scheme(&mut self, value: FontScheme) -> &mut Self {
90        self.font_scheme = value;
91        self
92    }
93
94    #[inline]
95    #[must_use]
96    pub fn format_scheme(&self) -> &FormatScheme {
97        &self.format_scheme
98    }
99
100    #[inline]
101    #[must_use]
102    #[deprecated(since = "3.0.0", note = "Use format_scheme()")]
103    pub fn get_format_scheme(&self) -> &FormatScheme {
104        self.format_scheme()
105    }
106
107    #[inline]
108    pub fn format_scheme_mut(&mut self) -> &mut FormatScheme {
109        &mut self.format_scheme
110    }
111
112    #[inline]
113    #[deprecated(since = "3.0.0", note = "Use format_scheme_mut()")]
114    pub fn get_format_scheme_mut(&mut self) -> &mut FormatScheme {
115        self.format_scheme_mut()
116    }
117
118    #[inline]
119    pub fn set_format_scheme(&mut self, value: FormatScheme) -> &mut Self {
120        self.format_scheme = value;
121        self
122    }
123
124    pub(crate) fn set_attributes<R: std::io::BufRead>(
125        &mut self,
126        reader: &mut Reader<R>,
127        _e: &BytesStart,
128    ) {
129        xml_read_loop!(
130            reader,
131            Event::Start(ref e) => {
132                match e.name().into_inner() {
133                    b"a:clrScheme" => {
134                        self.color_scheme.set_attributes(reader, e);
135                    }
136                    b"a:fontScheme" => {
137                        self.font_scheme.set_attributes(reader, e);
138                    }
139                    b"a:fmtScheme" => {
140                        self.format_scheme.set_attributes(reader, e);
141                    }
142                    _ => (),
143                }
144            },
145            Event::End(ref e) => {
146                if e.name().into_inner() == b"a:themeElements" {
147                    return
148                }
149            },
150            Event::Eof => panic!("Error: Could not find {} end element", "a:themeElements")
151        );
152    }
153
154    pub(crate) fn write_to(&self, writer: &mut Writer<Cursor<Vec<u8>>>) {
155        // a:themeElements
156        write_start_tag(writer, "a:themeElements", vec![], false);
157
158        // a:clrScheme
159        self.color_scheme.write_to(writer);
160
161        // a:fontScheme
162        self.font_scheme.write_to(writer);
163
164        // a:fmtScheme
165        self.format_scheme.write_to(writer);
166
167        write_end_tag(writer, "a:themeElements");
168    }
169}