use crate::types::HorizontalAlignment;
#[derive(Debug, Clone, Default)]
pub struct ParagraphStyle {
pub alignment: Option<HorizontalAlignment>,
pub first_line_indent: Option<i32>,
pub left_indent: Option<i32>,
pub right_indent: Option<i32>,
pub space_before: Option<u32>,
pub space_after: Option<u32>,
pub line_spacing: Option<u32>,
}
impl ParagraphStyle {
#[must_use]
pub fn new() -> Self {
Self::default()
}
#[must_use]
pub fn alignment(mut self, alignment: HorizontalAlignment) -> Self {
self.alignment = Some(alignment);
self
}
#[must_use]
pub fn first_line_indent(mut self, indent: i32) -> Self {
self.first_line_indent = Some(indent);
self
}
#[must_use]
pub fn space_after(mut self, space: u32) -> Self {
self.space_after = Some(space);
self
}
#[must_use]
pub fn line_spacing(mut self, spacing: u32) -> Self {
self.line_spacing = Some(spacing);
self
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn default_paragraph_style() {
let s = ParagraphStyle::default();
assert!(s.alignment.is_none());
assert!(s.first_line_indent.is_none());
assert!(s.space_after.is_none());
assert!(s.line_spacing.is_none());
}
#[test]
fn new_equals_default() {
let s = ParagraphStyle::new();
assert!(s.alignment.is_none());
}
#[test]
fn builder_chain() {
let s = ParagraphStyle::new()
.alignment(HorizontalAlignment::Center)
.first_line_indent(480)
.space_after(200)
.line_spacing(360);
assert_eq!(s.alignment, Some(HorizontalAlignment::Center));
assert_eq!(s.first_line_indent, Some(480));
assert_eq!(s.space_after, Some(200));
assert_eq!(s.line_spacing, Some(360));
}
}