docx_reader/documents/elements/
paragraph_borders.rsuse serde::Serialize;
use crate::types::*;
#[derive(Serialize, Debug, Clone, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct ParagraphBorder {
position: ParagraphBorderPosition,
pub val: BorderType,
pub size: usize,
pub space: usize,
pub color: String,
}
impl ParagraphBorder {
pub fn new(position: ParagraphBorderPosition) -> Self {
ParagraphBorder {
position,
val: BorderType::Single,
size: 2,
space: 0,
color: "auto".to_owned(),
}
}
pub fn val(mut self, val: BorderType) -> Self {
self.val = val;
self
}
pub fn size(mut self, size: usize) -> Self {
self.size = size;
self
}
pub fn space(mut self, space: usize) -> Self {
self.space = space;
self
}
pub fn color(mut self, color: impl Into<String>) -> Self {
self.color = color.into();
self
}
}
#[derive(Serialize, Debug, Clone, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct ParagraphBorders {
left: Option<ParagraphBorder>,
right: Option<ParagraphBorder>,
top: Option<ParagraphBorder>,
bottom: Option<ParagraphBorder>,
between: Option<ParagraphBorder>,
bar: Option<ParagraphBorder>,
}
impl Default for ParagraphBorders {
fn default() -> Self {
ParagraphBorders {
left: Some(ParagraphBorder::new(ParagraphBorderPosition::Left)),
right: Some(ParagraphBorder::new(ParagraphBorderPosition::Right)),
top: Some(ParagraphBorder::new(ParagraphBorderPosition::Top)),
bottom: Some(ParagraphBorder::new(ParagraphBorderPosition::Bottom)),
between: None,
bar: None,
}
}
}
impl ParagraphBorders {
pub fn new() -> Self {
Self::default()
}
pub fn with_empty() -> Self {
ParagraphBorders {
left: None,
right: None,
top: None,
bottom: None,
between: None,
bar: None,
}
}
pub fn set(mut self, border: ParagraphBorder) -> Self {
match border.position {
ParagraphBorderPosition::Top => self.top = Some(border),
ParagraphBorderPosition::Left => self.left = Some(border),
ParagraphBorderPosition::Bottom => self.bottom = Some(border),
ParagraphBorderPosition::Right => self.right = Some(border),
ParagraphBorderPosition::Between => self.between = Some(border),
ParagraphBorderPosition::Bar => self.bar = Some(border),
};
self
}
pub fn clear(mut self, position: ParagraphBorderPosition) -> Self {
let nil = ParagraphBorder::new(position.clone()).val(BorderType::Nil);
match position {
ParagraphBorderPosition::Top => self.top = Some(nil),
ParagraphBorderPosition::Left => self.left = Some(nil),
ParagraphBorderPosition::Bottom => self.bottom = Some(nil),
ParagraphBorderPosition::Right => self.right = Some(nil),
ParagraphBorderPosition::Between => self.between = Some(nil),
ParagraphBorderPosition::Bar => self.bar = Some(nil),
};
self
}
pub fn clear_all(mut self) -> Self {
self.left = Some(ParagraphBorder::new(ParagraphBorderPosition::Left).val(BorderType::Nil));
self.right =
Some(ParagraphBorder::new(ParagraphBorderPosition::Right).val(BorderType::Nil));
self.top = Some(ParagraphBorder::new(ParagraphBorderPosition::Top).val(BorderType::Nil));
self.bottom =
Some(ParagraphBorder::new(ParagraphBorderPosition::Bottom).val(BorderType::Nil));
self.between =
Some(ParagraphBorder::new(ParagraphBorderPosition::Between).val(BorderType::Nil));
self.bar = Some(ParagraphBorder::new(ParagraphBorderPosition::Bar).val(BorderType::Nil));
self
}
}