docx_reader/documents/elements/
table_cell_property.rs

1use serde::Serialize;
2
3use super::*;
4use crate::types::*;
5
6#[derive(Serialize, Debug, Clone, PartialEq)]
7#[serde(rename_all = "camelCase")]
8pub struct TableCellProperty {
9	width: Option<TableCellWidth>,
10	borders: Option<TableCellBorders>,
11	grid_span: Option<GridSpan>,
12	vertical_merge: Option<VMerge>,
13	vertical_align: Option<VAlign>,
14	text_direction: Option<TextDirection>,
15	shading: Option<Shading>,
16}
17
18impl TableCellProperty {
19	pub fn new() -> TableCellProperty {
20		Default::default()
21	}
22
23	pub fn width(mut self, v: usize, t: WidthType) -> TableCellProperty {
24		self.width = Some(TableCellWidth::new(v, t));
25		self
26	}
27
28	pub fn vertical_merge(mut self, t: VMergeType) -> TableCellProperty {
29		self.vertical_merge = Some(VMerge::new(t));
30		self
31	}
32
33	pub fn vertical_align(mut self, t: VAlignType) -> TableCellProperty {
34		self.vertical_align = Some(VAlign::new(t));
35		self
36	}
37
38	pub fn text_direction(mut self, t: TextDirectionType) -> Self {
39		self.text_direction = Some(TextDirection::new(t));
40		self
41	}
42
43	pub fn grid_span(mut self, v: usize) -> TableCellProperty {
44		self.grid_span = Some(GridSpan::new(v));
45		self
46	}
47
48	pub fn shading(mut self, s: Shading) -> Self {
49		self.shading = Some(s);
50		self
51	}
52
53	pub fn set_borders(mut self, borders: TableCellBorders) -> Self {
54		self.borders = Some(borders);
55		self
56	}
57
58	pub fn set_border(mut self, border: TableCellBorder) -> Self {
59		self.borders = Some(self.borders.unwrap_or_default().set(border));
60		self
61	}
62
63	pub fn clear_border(mut self, position: TableCellBorderPosition) -> Self {
64		self.borders = Some(self.borders.unwrap_or_default().clear(position));
65		self
66	}
67
68	pub fn clear_all_border(mut self) -> Self {
69		self.borders = Some(self.borders.unwrap_or_default().clear_all());
70		self
71	}
72}
73
74impl Default for TableCellProperty {
75	fn default() -> Self {
76		TableCellProperty {
77			width: None,
78			borders: None,
79			grid_span: None,
80			vertical_merge: None,
81			vertical_align: None,
82			text_direction: None,
83			shading: None,
84		}
85	}
86}