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
use core::{Result, Font, FontInfo, RenderContext};
#[must_use]
#[derive(Clone)]
pub struct FontBuilder<'a> {
info : FontInfo,
context : &'a RenderContext,
file : Option<&'a str>,
}
impl<'a> FontBuilder<'a> {
pub fn family(mut self: Self, family: &str) -> Self {
self.info.family = family.to_string();
self
}
pub fn file(mut self: Self, file: &'a str) -> Self {
self.file = Some(file);
self
}
pub fn italic(mut self: Self) -> Self {
self.info.italic = true;
self
}
pub fn oblique(mut self: Self) -> Self {
self.info.oblique = true;
self
}
pub fn monospace(mut self: Self) -> Self {
self.info.monospace = true;
self
}
pub fn bold(mut self: Self) -> Self {
self.info.bold = true;
self
}
pub fn size(mut self: Self, size: f32) -> Self {
self.info.size = size;
self
}
pub fn build(self: Self) -> Result<Font> {
if let Some(file) = self.file {
Font::from_file(self.context, file)
} else {
Font::from_info(self.context, self.info)
}
}
pub(crate) fn new<'b>(context: &'b RenderContext) -> FontBuilder {
FontBuilder {
context : context,
info : FontInfo { ..FontInfo::default() },
file : None,
}
}
}