umya_spreadsheet/structs/drawing/
pattern_fill.rs1use super::BackgroundColor;
3use super::ForegroundColor;
4use crate::reader::driver::*;
5use crate::writer::driver::*;
6use quick_xml::events::{BytesStart, Event};
7use quick_xml::Reader;
8use quick_xml::Writer;
9use std::io::Cursor;
10
11#[derive(Clone, Debug)]
12pub struct PatternFill {
13 preset: Box<str>,
14 foreground_color: ForegroundColor,
15 background_color: BackgroundColor,
16}
17
18impl Default for PatternFill {
19 #[inline]
20 fn default() -> Self {
21 Self {
22 preset: "pct5".into(),
23 foreground_color: ForegroundColor::default(),
24 background_color: BackgroundColor::default(),
25 }
26 }
27}
28
29impl PatternFill {
30 #[inline]
31 pub fn get_preset(&self) -> &str {
32 &self.preset
33 }
34
35 #[inline]
36 pub fn set_preset(&mut self, value: String) -> &mut PatternFill {
37 self.preset = value.into_boxed_str();
38 self
39 }
40
41 #[inline]
42 pub fn get_foreground_color(&self) -> &ForegroundColor {
43 &self.foreground_color
44 }
45
46 #[inline]
47 pub fn get_foreground_color_mut(&mut self) -> &mut ForegroundColor {
48 &mut self.foreground_color
49 }
50
51 #[inline]
52 pub fn set_foreground_color(&mut self, value: ForegroundColor) -> &mut PatternFill {
53 self.foreground_color = value;
54 self
55 }
56
57 #[inline]
58 pub fn get_background_color(&self) -> &BackgroundColor {
59 &self.background_color
60 }
61
62 #[inline]
63 pub fn get_background_color_mut(&mut self) -> &mut BackgroundColor {
64 &mut self.background_color
65 }
66
67 #[inline]
68 pub fn set_background_color(&mut self, value: BackgroundColor) -> &mut PatternFill {
69 self.background_color = value;
70 self
71 }
72
73 pub(crate) fn set_attributes<R: std::io::BufRead>(
74 &mut self,
75 reader: &mut Reader<R>,
76 e: &BytesStart,
77 ) {
78 if let Some(v) = get_attribute(e, b"prst") {
79 self.set_preset(v);
80 }
81
82 xml_read_loop!(
83 reader,
84 Event::Start(ref e) => {
85 match e.name().into_inner() {
86 b"a:fgClr" => {
87 self.foreground_color.set_attributes(reader, e);
88 },
89 b"a:bgClr" => {
90 self.background_color.set_attributes(reader, e);
91 },
92 _ => (),
93 }
94 },
95 Event::End(ref e) => {
96 if e.name().into_inner() == b"a:pattFill" {
97 return
98 }
99 },
100 Event::Eof => panic!("Error: Could not find {} end element", "a:pattFill")
101 );
102 }
103
104 pub(crate) fn write_to(&self, writer: &mut Writer<Cursor<Vec<u8>>>) {
105 write_start_tag(writer, "a:pattFill", vec![("prst", &self.preset)], false);
107
108 self.foreground_color.write_to(writer);
110
111 self.background_color.write_to(writer);
113
114 write_end_tag(writer, "a:pattFill");
115 }
116}