1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
use super::Drawable;
use crate::primitives::{
Ellipsize,
FontStyle,
FontWeight,
Paint,
TextAlign,
TextWrap,
};
/// Capability for configuring text appearance and typography on a node.
pub trait Textual: Drawable {
/// Sets the text color.
///
/// # Arguments
/// - `value`: The [`Paint`] value applied to the text.
///
/// # Returns
/// - [`Self`]
fn color<T>(mut self, value: T) -> Self
where
T: Into<Paint>,
{
let color = value.into();
self.typography_mut().color = Some(color.clone());
self.add_resources(color);
self
}
/// Sets the font family of text.
///
/// # Arguments
/// - `family`: The font family name.
///
/// # Returns
/// - [`Self`]
fn font_family<T, S>(mut self, family: T) -> Self
where
T: Into<Option<S>>,
S: Into<String>,
{
self.typography_mut().family = family.into().map(Into::into);
self
}
/// Sets the font size of text.
///
/// # Arguments
/// - `font_size`: The font size.
///
/// # Returns
/// - [`Self`]
fn font_size<T>(mut self, font_size: T) -> Self
where
T: Into<Option<f32>>,
{
self.typography_mut().size = font_size.into();
self
}
/// Sets the line height of text.
///
/// # Arguments
/// - `line_height`: The line height.
///
/// # Returns
/// - [`Self`]
fn line_height<T>(mut self, line_height: T) -> Self
where
T: Into<Option<f32>>,
{
self.typography_mut().line_height = line_height.into();
self
}
/// Sets the font weight of text.
///
/// # Arguments
/// - `font_weight`: The [`FontWeight`] to apply.
///
/// # Returns
/// - [`Self`]
fn font_weight<T>(mut self, font_weight: T) -> Self
where
T: Into<Option<FontWeight>>,
{
self.typography_mut().weight = font_weight.into();
self
}
/// Sets the letter spacing applied between text glyphs.
///
/// # Arguments
/// - `letter_spacing`: The spacing between characters.
///
/// # Returns
/// - [`Self`]
fn letter_spacing<T>(mut self, letter_spacing: T) -> Self
where
T: Into<Option<f32>>,
{
self.typography_mut().letter_spacing = letter_spacing.into();
self
}
/// Sets the font style of text.
///
/// # Arguments
/// - `font_style`: The [`FontStyle`] to apply.
///
/// # Returns
/// - [`Self`]
fn font_style<T>(mut self, font_style: T) -> Self
where
T: Into<Option<FontStyle>>,
{
self.typography_mut().style = font_style.into();
self
}
/// Sets the horizontal alignment of text within its container.
///
/// # Arguments
/// - `text_align`: The [`TextAlign`] behavior to apply.
///
/// # Returns
/// - [`Self`]
fn text_align<T>(mut self, text_align: T) -> Self
where
T: Into<Option<TextAlign>>,
{
self.typography_mut().align = text_align.into();
self
}
/// Sets the text wrapping behavior.
///
/// # Arguments
/// - `text_wrap`: The [`TextWrap`] behavior to apply.
///
/// # Returns
/// - [`Self`]
fn text_wrap<T>(mut self, text_wrap: T) -> Self
where
T: Into<Option<TextWrap>>,
{
self.typography_mut().wrap = text_wrap.into();
self
}
/// Sets the ellipsis behavior of text.
///
/// # Arguments
/// - `value`: The [`Ellipsize`] behavior to apply.
///
/// # Returns
/// - [`Self`]
fn ellipsize<T>(mut self, value: T) -> Self
where
T: Into<Option<Ellipsize>>,
{
self.typography_mut().ellipsize = value.into();
self
}
}