docx_reader/documents/elements/
table_property.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
use serde::Serialize;

use super::*;
use crate::types::*;

#[derive(Debug, Clone, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct TableProperty {
	width: TableWidth,
	justification: Justification,
	borders: TableBorders,
	#[serde(skip_serializing_if = "Option::is_none")]
	margins: Option<TableCellMargins>,
	#[serde(skip_serializing_if = "Option::is_none")]
	indent: Option<TableIndent>,
	#[serde(skip_serializing_if = "Option::is_none")]
	style: Option<TableStyle>,
	#[serde(skip_serializing_if = "Option::is_none")]
	layout: Option<TableLayout>,
}

impl Default for TableProperty {
	fn default() -> Self {
		TableProperty {
			width: TableWidth::new(0, WidthType::Auto),
			justification: Justification::new("left"),
			borders: TableBorders::new(),
			margins: None,
			indent: None,
			style: None,
			layout: None,
		}
	}
}

impl TableProperty {
	pub fn new() -> TableProperty {
		Default::default()
	}

	pub fn without_borders() -> TableProperty {
		TableProperty {
			borders: TableBorders::with_empty(),
			..Default::default()
		}
	}

	pub fn indent(mut self, v: i32) -> TableProperty {
		self.indent = Some(TableIndent::new(v, WidthType::Dxa));
		self
	}

	pub fn width(mut self, v: usize, t: WidthType) -> TableProperty {
		self.width = TableWidth::new(v, t);
		self
	}

	pub fn align(mut self, v: TableAlignmentType) -> TableProperty {
		self.justification = Justification::new(v.to_string());
		self
	}

	pub fn set_margins(mut self, margins: TableCellMargins) -> Self {
		self.margins = Some(margins);
		self
	}

	pub fn cell_margin_top(mut self, v: usize, t: WidthType) -> Self {
		if let Some(margins) = self.margins {
			self.margins = Some(margins.margin_top(v, t));
		} else {
			let margins = TableCellMargins::new();
			self.margins = Some(margins.margin_top(v, t));
		}
		self
	}

	pub fn cell_margin_right(mut self, v: usize, t: WidthType) -> Self {
		if let Some(margins) = self.margins {
			self.margins = Some(margins.margin_right(v, t));
		} else {
			let margins = TableCellMargins::new();
			self.margins = Some(margins.margin_right(v, t));
		}
		self
	}

	pub fn cell_margin_bottom(mut self, v: usize, t: WidthType) -> Self {
		if let Some(margins) = self.margins {
			self.margins = Some(margins.margin_bottom(v, t));
		} else {
			let margins = TableCellMargins::new();
			self.margins = Some(margins.margin_bottom(v, t));
		}
		self
	}

	pub fn cell_margin_left(mut self, v: usize, t: WidthType) -> Self {
		if let Some(margins) = self.margins {
			self.margins = Some(margins.margin_left(v, t));
		} else {
			let margins = TableCellMargins::new();
			self.margins = Some(margins.margin_left(v, t));
		}
		self
	}

	pub fn set_borders(mut self, borders: TableBorders) -> Self {
		self.borders = borders;
		self
	}

	pub fn set_border(mut self, border: TableBorder) -> Self {
		self.borders = self.borders.set(border);
		self
	}

	pub fn clear_border(mut self, position: TableBorderPosition) -> Self {
		self.borders = self.borders.clear(position);
		self
	}

	pub fn clear_all_border(mut self) -> Self {
		self.borders = self.borders.clear_all();
		self
	}

	pub fn style(mut self, s: impl Into<String>) -> Self {
		self.style = Some(TableStyle::new(s));
		self
	}

	pub fn layout(mut self, t: TableLayoutType) -> Self {
		self.layout = Some(TableLayout::new(t));
		self
	}
}