docx_reader/documents/elements/
paragraph_borders.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
use serde::Serialize;

use crate::types::*;

#[derive(Serialize, Debug, Clone, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct ParagraphBorder {
	position: ParagraphBorderPosition,
	pub val: BorderType,
	pub size: usize,
	pub space: usize,
	pub color: String,
	// pub shadow: Option<bool>,
	// pub theme_color: Option<String>,
	// pub theme_shade: Option<String>,
	// pub theme_tint: Option<String>,
	// pub frame: Option<bool>,
}

impl ParagraphBorder {
	pub fn new(position: ParagraphBorderPosition) -> Self {
		ParagraphBorder {
			position,
			val: BorderType::Single,
			size: 2,
			space: 0,
			color: "auto".to_owned(),
			// shadow: None,
			// theme_color: None,
			// theme_shade: None,
			// theme_tint: None,
			// frame: None,
		}
	}
	pub fn val(mut self, val: BorderType) -> Self {
		self.val = val;
		self
	}

	pub fn size(mut self, size: usize) -> Self {
		self.size = size;
		self
	}

	pub fn space(mut self, space: usize) -> Self {
		self.space = space;
		self
	}

	pub fn color(mut self, color: impl Into<String>) -> Self {
		self.color = color.into();
		self
	}

	// pub fn shadow(mut self, shadow: bool) -> Self {
	//     self.shadow = Some(shadow);
	//     self
	// }
	//
	// pub fn theme_color(mut self, theme_color: impl Into<String>) -> Self {
	//     self.theme_color = Some(theme_color.into());
	//     self
	// }
	//
	// pub fn theme_shade(mut self, theme_shade: impl Into<String>) -> Self {
	//     self.theme_shade = Some(theme_shade.into());
	//     self
	// }
	//
	// pub fn theme_tint(mut self, theme_tint: impl Into<String>) -> Self {
	//     self.theme_tint = Some(theme_tint.into());
	//     self
	// }
	//
	// pub fn frame(mut self, frame: bool) -> Self {
	//     self.frame = Some(frame);
	//     self
	// }
}

#[derive(Serialize, Debug, Clone, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct ParagraphBorders {
	left: Option<ParagraphBorder>,
	right: Option<ParagraphBorder>,
	top: Option<ParagraphBorder>,
	bottom: Option<ParagraphBorder>,
	between: Option<ParagraphBorder>,
	bar: Option<ParagraphBorder>,
}

impl Default for ParagraphBorders {
	fn default() -> Self {
		ParagraphBorders {
			left: Some(ParagraphBorder::new(ParagraphBorderPosition::Left)),
			right: Some(ParagraphBorder::new(ParagraphBorderPosition::Right)),
			top: Some(ParagraphBorder::new(ParagraphBorderPosition::Top)),
			bottom: Some(ParagraphBorder::new(ParagraphBorderPosition::Bottom)),
			between: None,
			bar: None,
		}
	}
}

impl ParagraphBorders {
	pub fn new() -> Self {
		Self::default()
	}

	pub fn with_empty() -> Self {
		ParagraphBorders {
			left: None,
			right: None,
			top: None,
			bottom: None,
			between: None,
			bar: None,
		}
	}

	pub fn set(mut self, border: ParagraphBorder) -> Self {
		match border.position {
			ParagraphBorderPosition::Top => self.top = Some(border),
			ParagraphBorderPosition::Left => self.left = Some(border),
			ParagraphBorderPosition::Bottom => self.bottom = Some(border),
			ParagraphBorderPosition::Right => self.right = Some(border),
			ParagraphBorderPosition::Between => self.between = Some(border),
			ParagraphBorderPosition::Bar => self.bar = Some(border),
		};
		self
	}

	pub fn clear(mut self, position: ParagraphBorderPosition) -> Self {
		let nil = ParagraphBorder::new(position.clone()).val(BorderType::Nil);
		match position {
			ParagraphBorderPosition::Top => self.top = Some(nil),
			ParagraphBorderPosition::Left => self.left = Some(nil),
			ParagraphBorderPosition::Bottom => self.bottom = Some(nil),
			ParagraphBorderPosition::Right => self.right = Some(nil),
			ParagraphBorderPosition::Between => self.between = Some(nil),
			ParagraphBorderPosition::Bar => self.bar = Some(nil),
		};
		self
	}

	pub fn clear_all(mut self) -> Self {
		self.left = Some(ParagraphBorder::new(ParagraphBorderPosition::Left).val(BorderType::Nil));
		self.right =
			Some(ParagraphBorder::new(ParagraphBorderPosition::Right).val(BorderType::Nil));
		self.top = Some(ParagraphBorder::new(ParagraphBorderPosition::Top).val(BorderType::Nil));
		self.bottom =
			Some(ParagraphBorder::new(ParagraphBorderPosition::Bottom).val(BorderType::Nil));
		self.between =
			Some(ParagraphBorder::new(ParagraphBorderPosition::Between).val(BorderType::Nil));
		self.bar = Some(ParagraphBorder::new(ParagraphBorderPosition::Bar).val(BorderType::Nil));
		self
	}
}