zen_rs/components/
text.rs1pub mod h;
10
11use crate::aspects::{
12 BackgroundColor, DefaultFontFamily, FontStyle, ForegroundColor, Link, Size, Weight,
13};
14
15#[inline]
17pub fn text() -> Text {
18 Text::default()
19}
20
21#[derive(Debug, Default, Clone, PartialEq, PartialOrd)]
23pub struct Text {
24 content: String,
26 foreground_color: ForegroundColor,
28 background_color: BackgroundColor,
30 font_style: FontStyle,
32 link: Link,
34}
35
36impl Text {
37 #[inline]
39 pub fn link(mut self, link: impl ToString) -> Self {
40 self.link = Some(link.to_string());
41 self
42 }
43
44 #[inline]
46 pub fn content(mut self, content: impl ToString) -> Self {
47 self.content = content.to_string();
48 self
49 }
50
51 #[inline]
53 pub fn foreground_color(mut self, foreground_color: ForegroundColor) -> Self {
54 self.foreground_color = foreground_color;
55 self
56 }
57
58 #[inline]
60 pub fn background_color(mut self, background_color: BackgroundColor) -> Self {
61 self.background_color = background_color;
62 self
63 }
64
65 #[inline]
67 pub fn size(mut self, size: Size) -> Self {
68 self.font_style.0 = size;
69 self
70 }
71
72 #[inline]
74 pub fn is_strikeout(mut self) -> Self {
75 self.font_style.2 = !self.font_style.2;
76 self
77 }
78
79 #[inline]
81 pub fn is_underline(mut self) -> Self {
82 self.font_style.3 = !self.font_style.3;
83 self
84 }
85
86 #[inline]
88 pub fn is_italic(mut self) -> Self {
89 self.font_style.4 = !self.font_style.4;
90 self
91 }
92
93 #[inline]
104 pub fn font_weight(mut self, weight: Weight) -> Self {
105 self.font_style.1 = weight;
106 self
107 }
108
109 #[inline]
111 pub fn font_custom(mut self, name: impl ToString) -> Self {
112 self.font_style.5 .0 = name.to_string();
113 self
114 }
115
116 #[inline]
124 pub fn font_default(mut self, def: DefaultFontFamily) -> Self {
125 self.font_style.5 .1 = def;
126 self
127 }
128
129 #[inline]
131 pub fn font_style(mut self, font: FontStyle) -> Self {
132 self.font_style = font;
133 self
134 }
135
136 #[inline]
138 pub fn get_content(&self) -> &str {
139 self.content.as_str()
140 }
141
142 #[inline]
144 pub fn get_foreground_color(&self) -> ForegroundColor {
145 self.foreground_color
146 }
147
148 #[inline]
150 pub fn get_background_color(&self) -> BackgroundColor {
151 self.background_color
152 }
153
154 #[inline]
156 pub fn get_size(&self) -> Size {
157 self.font_style.0
158 }
159
160 #[inline]
162 pub fn get_font(&self) -> &FontStyle {
163 &self.font_style
164 }
165
166 #[inline]
168 pub fn get_link(&self) -> &Link {
169 &self.link
170 }
171}