docx_reader/documents/elements/
table_cell_margins.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 crate::types::*;

#[derive(Debug, Clone, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
struct CellMargin {
	pub val: usize,
	pub width_type: WidthType,
}

impl CellMargin {
	pub fn new(val: usize, t: WidthType) -> Self {
		Self { val, width_type: t }
	}
}

impl Default for CellMargin {
	fn default() -> CellMargin {
		CellMargin {
			val: 55,
			width_type: WidthType::Dxa,
		}
	}
}

#[derive(Debug, Clone, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct TableCellMargins {
	top: CellMargin,
	left: CellMargin,
	bottom: CellMargin,
	right: CellMargin,
}

impl Default for TableCellMargins {
	fn default() -> TableCellMargins {
		TableCellMargins {
			top: CellMargin {
				val: 0,
				width_type: WidthType::Dxa,
			},
			left: CellMargin::default(),
			bottom: CellMargin {
				val: 0,
				width_type: WidthType::Dxa,
			},
			right: CellMargin::default(),
		}
	}
}

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

	pub fn margin(self, top: usize, right: usize, bottom: usize, left: usize) -> TableCellMargins {
		TableCellMargins {
			top: CellMargin::new(top, WidthType::Dxa),
			left: CellMargin::new(left, WidthType::Dxa),
			bottom: CellMargin::new(bottom, WidthType::Dxa),
			right: CellMargin::new(right, WidthType::Dxa),
		}
	}

	pub fn margin_top(mut self, v: usize, t: WidthType) -> Self {
		self.top = CellMargin::new(v, t);
		self
	}

	pub fn margin_right(mut self, v: usize, t: WidthType) -> Self {
		self.right = CellMargin::new(v, t);
		self
	}

	pub fn margin_left(mut self, v: usize, t: WidthType) -> Self {
		self.left = CellMargin::new(v, t);
		self
	}

	pub fn margin_bottom(mut self, v: usize, t: WidthType) -> Self {
		self.bottom = CellMargin::new(v, t);
		self
	}
}