docx_reader/documents/elements/
table_cell_margins.rsuse 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
}
}