docx_reader/documents/elements/
table_cell_margins.rs

1use serde::Serialize;
2
3use crate::types::*;
4
5#[derive(Debug, Clone, PartialEq, Serialize)]
6#[serde(rename_all = "camelCase")]
7struct CellMargin {
8	pub val: usize,
9	pub width_type: WidthType,
10}
11
12impl CellMargin {
13	pub fn new(val: usize, t: WidthType) -> Self {
14		Self { val, width_type: t }
15	}
16}
17
18impl Default for CellMargin {
19	fn default() -> CellMargin {
20		CellMargin {
21			val: 55,
22			width_type: WidthType::Dxa,
23		}
24	}
25}
26
27#[derive(Debug, Clone, PartialEq, Serialize)]
28#[serde(rename_all = "camelCase")]
29pub struct TableCellMargins {
30	top: CellMargin,
31	left: CellMargin,
32	bottom: CellMargin,
33	right: CellMargin,
34}
35
36impl Default for TableCellMargins {
37	fn default() -> TableCellMargins {
38		TableCellMargins {
39			top: CellMargin {
40				val: 0,
41				width_type: WidthType::Dxa,
42			},
43			left: CellMargin::default(),
44			bottom: CellMargin {
45				val: 0,
46				width_type: WidthType::Dxa,
47			},
48			right: CellMargin::default(),
49		}
50	}
51}
52
53impl TableCellMargins {
54	pub fn new() -> TableCellMargins {
55		Default::default()
56	}
57
58	pub fn margin(self, top: usize, right: usize, bottom: usize, left: usize) -> TableCellMargins {
59		TableCellMargins {
60			top: CellMargin::new(top, WidthType::Dxa),
61			left: CellMargin::new(left, WidthType::Dxa),
62			bottom: CellMargin::new(bottom, WidthType::Dxa),
63			right: CellMargin::new(right, WidthType::Dxa),
64		}
65	}
66
67	pub fn margin_top(mut self, v: usize, t: WidthType) -> Self {
68		self.top = CellMargin::new(v, t);
69		self
70	}
71
72	pub fn margin_right(mut self, v: usize, t: WidthType) -> Self {
73		self.right = CellMargin::new(v, t);
74		self
75	}
76
77	pub fn margin_left(mut self, v: usize, t: WidthType) -> Self {
78		self.left = CellMargin::new(v, t);
79		self
80	}
81
82	pub fn margin_bottom(mut self, v: usize, t: WidthType) -> Self {
83		self.bottom = CellMargin::new(v, t);
84		self
85	}
86}