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

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

#[derive(Serialize, Debug, Clone, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct TableCellProperty {
	width: Option<TableCellWidth>,
	borders: Option<TableCellBorders>,
	grid_span: Option<GridSpan>,
	vertical_merge: Option<VMerge>,
	vertical_align: Option<VAlign>,
	text_direction: Option<TextDirection>,
	shading: Option<Shading>,
}

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

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

	pub fn vertical_merge(mut self, t: VMergeType) -> TableCellProperty {
		self.vertical_merge = Some(VMerge::new(t));
		self
	}

	pub fn vertical_align(mut self, t: VAlignType) -> TableCellProperty {
		self.vertical_align = Some(VAlign::new(t));
		self
	}

	pub fn text_direction(mut self, t: TextDirectionType) -> Self {
		self.text_direction = Some(TextDirection::new(t));
		self
	}

	pub fn grid_span(mut self, v: usize) -> TableCellProperty {
		self.grid_span = Some(GridSpan::new(v));
		self
	}

	pub fn shading(mut self, s: Shading) -> Self {
		self.shading = Some(s);
		self
	}

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

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

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

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

impl Default for TableCellProperty {
	fn default() -> Self {
		TableCellProperty {
			width: None,
			borders: None,
			grid_span: None,
			vertical_merge: None,
			vertical_align: None,
			text_direction: None,
			shading: None,
		}
	}
}