easydoc_core/style/
paragraph.rs1use crate::types::HorizontalAlignment;
2
3#[derive(Debug, Clone, Default)]
7pub struct ParagraphStyle {
8 pub alignment: Option<HorizontalAlignment>,
10 pub first_line_indent: Option<i32>,
12 pub left_indent: Option<i32>,
14 pub right_indent: Option<i32>,
16 pub space_before: Option<u32>,
18 pub space_after: Option<u32>,
20 pub line_spacing: Option<u32>,
22}
23
24impl ParagraphStyle {
25 #[must_use]
27 pub fn new() -> Self {
28 Self::default()
29 }
30
31 #[must_use]
33 pub fn alignment(mut self, alignment: HorizontalAlignment) -> Self {
34 self.alignment = Some(alignment);
35 self
36 }
37
38 #[must_use]
40 pub fn first_line_indent(mut self, indent: i32) -> Self {
41 self.first_line_indent = Some(indent);
42 self
43 }
44
45 #[must_use]
47 pub fn space_after(mut self, space: u32) -> Self {
48 self.space_after = Some(space);
49 self
50 }
51
52 #[must_use]
54 pub fn line_spacing(mut self, spacing: u32) -> Self {
55 self.line_spacing = Some(spacing);
56 self
57 }
58}
59
60#[cfg(test)]
61mod tests {
62 use super::*;
63
64 #[test]
65 fn default_paragraph_style() {
66 let s = ParagraphStyle::default();
67 assert!(s.alignment.is_none());
68 assert!(s.first_line_indent.is_none());
69 assert!(s.space_after.is_none());
70 assert!(s.line_spacing.is_none());
71 }
72
73 #[test]
74 fn new_equals_default() {
75 let s = ParagraphStyle::new();
76 assert!(s.alignment.is_none());
77 }
78
79 #[test]
80 fn builder_chain() {
81 let s = ParagraphStyle::new()
82 .alignment(HorizontalAlignment::Center)
83 .first_line_indent(480)
84 .space_after(200)
85 .line_spacing(360);
86 assert_eq!(s.alignment, Some(HorizontalAlignment::Center));
87 assert_eq!(s.first_line_indent, Some(480));
88 assert_eq!(s.space_after, Some(200));
89 assert_eq!(s.line_spacing, Some(360));
90 }
91}