docx_rs/documents/elements/
shading.rs1use serde::Serialize;
2use std::io::Write;
3
4use crate::documents::BuildXML;
5use crate::types::*;
6use crate::xml_builder::*;
7
8#[derive(Serialize, Debug, Clone, PartialEq)]
10#[serde(rename_all = "camelCase")]
11pub struct Shading {
12 pub shd_type: ShdType,
13 pub color: String,
14 pub fill: String,
15}
16
17impl Default for Shading {
18 fn default() -> Self {
19 Shading {
20 shd_type: ShdType::Clear,
21 color: "auto".to_owned(),
22 fill: "FFFFFF".to_owned(),
23 }
24 }
25}
26
27impl Shading {
28 pub fn new() -> Shading {
29 Shading::default()
30 }
31
32 pub fn color(mut self, color: impl Into<String>) -> Shading {
33 self.color = color.into();
34 self
35 }
36
37 pub fn fill(mut self, fill: impl Into<String>) -> Shading {
38 self.fill = fill.into();
39 self
40 }
41
42 pub fn shd_type(mut self, shd_type: ShdType) -> Shading {
43 self.shd_type = shd_type;
44 self
45 }
46}
47
48impl BuildXML for Shading {
49 fn build_to<W: Write>(
50 &self,
51 stream: xml::writer::EventWriter<W>,
52 ) -> xml::writer::Result<xml::writer::EventWriter<W>> {
53 XMLBuilder::from(stream)
54 .shd(&self.shd_type.to_string(), &self.color, &self.fill)?
55 .into_inner()
56 }
57}