paperforge_layout/
text.rs1use paperforge_core::{Color, Point};
2
3#[derive(Debug, Clone, Copy, PartialEq)]
4pub enum Style {
5 Normal,
6 Bold,
7 Italic,
8 BoldItalic,
9 Underline,
10 Strikethrough,
11}
12
13#[derive(Debug, Clone)]
14pub struct Span {
15 pub text: String,
16 pub style: Style,
17 pub color: Color,
18 pub font_size: f64,
19}
20
21impl Span {
22 pub fn new(text: &str) -> Self {
23 Self {
24 text: text.to_string(),
25 style: Style::Normal,
26 color: Color::black(),
27 font_size: 12.0,
28 }
29 }
30
31 pub fn normal(mut self) -> Self {
32 self.style = Style::Normal;
33 self
34 }
35
36 pub fn bold(mut self) -> Self {
37 self.style = Style::Bold;
38 self
39 }
40
41 pub fn italic(mut self) -> Self {
42 self.style = Style::Italic;
43 self
44 }
45
46 pub fn underline(mut self) -> Self {
47 self.style = Style::Underline;
48 self
49 }
50
51 pub fn color(mut self, color: Color) -> Self {
52 self.color = color;
53 self
54 }
55
56 pub fn font_size(mut self, size: f64) -> Self {
57 self.font_size = size;
58 self
59 }
60}
61
62#[derive(Debug, Clone)]
63pub struct TextBuilder {
64 pub position: Point,
65 pub font_size: f64,
66 pub color: Color,
67 pub text: String,
68}
69
70impl TextBuilder {
71 pub fn new() -> Self {
72 Self {
73 position: Point::new(0.0, 0.0),
74 font_size: 12.0,
75 color: Color::black(),
76 text: String::new(),
77 }
78 }
79
80 pub fn at(mut self, x: f64, y: f64) -> Self {
81 self.position = Point::new(x, y);
82 self
83 }
84
85 pub fn font_size(mut self, size: f64) -> Self {
86 self.font_size = size;
87 self
88 }
89
90 pub fn color(mut self, color: Color) -> Self {
91 self.color = color;
92 self
93 }
94
95 pub fn write(mut self, text: &str) -> Self {
96 self.text = text.to_string();
97 self
98 }
99}
100
101impl Default for TextBuilder {
102 fn default() -> Self {
103 Self::new()
104 }
105}