docx_reader/documents/elements/
paragraph_borders.rs

1use serde::Serialize;
2
3use crate::types::*;
4
5#[derive(Serialize, Debug, Clone, PartialEq)]
6#[serde(rename_all = "camelCase")]
7pub struct ParagraphBorder {
8	position: ParagraphBorderPosition,
9	pub val: BorderType,
10	pub size: usize,
11	pub space: usize,
12	pub color: String,
13	// pub shadow: Option<bool>,
14	// pub theme_color: Option<String>,
15	// pub theme_shade: Option<String>,
16	// pub theme_tint: Option<String>,
17	// pub frame: Option<bool>,
18}
19
20impl ParagraphBorder {
21	pub fn new(position: ParagraphBorderPosition) -> Self {
22		ParagraphBorder {
23			position,
24			val: BorderType::Single,
25			size: 2,
26			space: 0,
27			color: "auto".to_owned(),
28			// shadow: None,
29			// theme_color: None,
30			// theme_shade: None,
31			// theme_tint: None,
32			// frame: None,
33		}
34	}
35	pub fn val(mut self, val: BorderType) -> Self {
36		self.val = val;
37		self
38	}
39
40	pub fn size(mut self, size: usize) -> Self {
41		self.size = size;
42		self
43	}
44
45	pub fn space(mut self, space: usize) -> Self {
46		self.space = space;
47		self
48	}
49
50	pub fn color(mut self, color: impl Into<String>) -> Self {
51		self.color = color.into();
52		self
53	}
54
55	// pub fn shadow(mut self, shadow: bool) -> Self {
56	//     self.shadow = Some(shadow);
57	//     self
58	// }
59	//
60	// pub fn theme_color(mut self, theme_color: impl Into<String>) -> Self {
61	//     self.theme_color = Some(theme_color.into());
62	//     self
63	// }
64	//
65	// pub fn theme_shade(mut self, theme_shade: impl Into<String>) -> Self {
66	//     self.theme_shade = Some(theme_shade.into());
67	//     self
68	// }
69	//
70	// pub fn theme_tint(mut self, theme_tint: impl Into<String>) -> Self {
71	//     self.theme_tint = Some(theme_tint.into());
72	//     self
73	// }
74	//
75	// pub fn frame(mut self, frame: bool) -> Self {
76	//     self.frame = Some(frame);
77	//     self
78	// }
79}
80
81#[derive(Serialize, Debug, Clone, PartialEq)]
82#[serde(rename_all = "camelCase")]
83pub struct ParagraphBorders {
84	left: Option<ParagraphBorder>,
85	right: Option<ParagraphBorder>,
86	top: Option<ParagraphBorder>,
87	bottom: Option<ParagraphBorder>,
88	between: Option<ParagraphBorder>,
89	bar: Option<ParagraphBorder>,
90}
91
92impl Default for ParagraphBorders {
93	fn default() -> Self {
94		ParagraphBorders {
95			left: Some(ParagraphBorder::new(ParagraphBorderPosition::Left)),
96			right: Some(ParagraphBorder::new(ParagraphBorderPosition::Right)),
97			top: Some(ParagraphBorder::new(ParagraphBorderPosition::Top)),
98			bottom: Some(ParagraphBorder::new(ParagraphBorderPosition::Bottom)),
99			between: None,
100			bar: None,
101		}
102	}
103}
104
105impl ParagraphBorders {
106	pub fn new() -> Self {
107		Self::default()
108	}
109
110	pub fn with_empty() -> Self {
111		ParagraphBorders {
112			left: None,
113			right: None,
114			top: None,
115			bottom: None,
116			between: None,
117			bar: None,
118		}
119	}
120
121	pub fn set(mut self, border: ParagraphBorder) -> Self {
122		match border.position {
123			ParagraphBorderPosition::Top => self.top = Some(border),
124			ParagraphBorderPosition::Left => self.left = Some(border),
125			ParagraphBorderPosition::Bottom => self.bottom = Some(border),
126			ParagraphBorderPosition::Right => self.right = Some(border),
127			ParagraphBorderPosition::Between => self.between = Some(border),
128			ParagraphBorderPosition::Bar => self.bar = Some(border),
129		};
130		self
131	}
132
133	pub fn clear(mut self, position: ParagraphBorderPosition) -> Self {
134		let nil = ParagraphBorder::new(position.clone()).val(BorderType::Nil);
135		match position {
136			ParagraphBorderPosition::Top => self.top = Some(nil),
137			ParagraphBorderPosition::Left => self.left = Some(nil),
138			ParagraphBorderPosition::Bottom => self.bottom = Some(nil),
139			ParagraphBorderPosition::Right => self.right = Some(nil),
140			ParagraphBorderPosition::Between => self.between = Some(nil),
141			ParagraphBorderPosition::Bar => self.bar = Some(nil),
142		};
143		self
144	}
145
146	pub fn clear_all(mut self) -> Self {
147		self.left = Some(ParagraphBorder::new(ParagraphBorderPosition::Left).val(BorderType::Nil));
148		self.right =
149			Some(ParagraphBorder::new(ParagraphBorderPosition::Right).val(BorderType::Nil));
150		self.top = Some(ParagraphBorder::new(ParagraphBorderPosition::Top).val(BorderType::Nil));
151		self.bottom =
152			Some(ParagraphBorder::new(ParagraphBorderPosition::Bottom).val(BorderType::Nil));
153		self.between =
154			Some(ParagraphBorder::new(ParagraphBorderPosition::Between).val(BorderType::Nil));
155		self.bar = Some(ParagraphBorder::new(ParagraphBorderPosition::Bar).val(BorderType::Nil));
156		self
157	}
158}