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
use core::hash::BuildHasher;
use glyph_brush::delegate_glyph_brush_builder_fns;
use glyph_brush::{rusttype, DefaultSectionHasher};
use rusttype::{Font, SharedBytes};
use super::GlyphBrush;
pub struct GlyphBrushBuilder<'a, D, H = DefaultSectionHasher> {
inner: glyph_brush::GlyphBrushBuilder<'a, H>,
texture_filter_method: wgpu::FilterMode,
depth: D,
}
impl<'a, H> From<glyph_brush::GlyphBrushBuilder<'a, H>> for GlyphBrushBuilder<'a, (), H> {
fn from(inner: glyph_brush::GlyphBrushBuilder<'a, H>) -> Self {
GlyphBrushBuilder {
inner,
texture_filter_method: wgpu::FilterMode::Linear,
depth: (),
}
}
}
impl<'a> GlyphBrushBuilder<'a, ()> {
#[inline]
pub fn using_font_bytes<B: Into<SharedBytes<'a>>>(font_0_data: B) -> Self {
Self::using_font(Font::from_bytes(font_0_data).unwrap())
}
#[inline]
pub fn using_fonts_bytes<B, V>(font_data: V) -> Self
where
B: Into<SharedBytes<'a>>,
V: Into<Vec<B>>,
{
Self::using_fonts(
font_data
.into()
.into_iter()
.map(|data| Font::from_bytes(data).unwrap())
.collect::<Vec<_>>(),
)
}
#[inline]
pub fn using_font(font_0: Font<'a>) -> Self {
Self::using_fonts(vec![font_0])
}
pub fn using_fonts<V: Into<Vec<Font<'a>>>>(fonts: V) -> Self {
GlyphBrushBuilder {
inner: glyph_brush::GlyphBrushBuilder::using_fonts(fonts),
texture_filter_method: wgpu::FilterMode::Linear,
depth: (),
}
}
}
impl<'a, D, H: BuildHasher> GlyphBrushBuilder<'a, D, H> {
delegate_glyph_brush_builder_fns!(inner);
pub fn texture_filter_method(
mut self,
filter_method: wgpu::FilterMode,
) -> Self {
self.texture_filter_method = filter_method;
self
}
pub fn section_hasher<T: BuildHasher>(
self,
section_hasher: T,
) -> GlyphBrushBuilder<'a, D, T> {
GlyphBrushBuilder {
inner: self.inner.section_hasher(section_hasher),
texture_filter_method: self.texture_filter_method,
depth: self.depth,
}
}
pub fn depth_stencil_state(
self,
depth_stencil_state: wgpu::DepthStencilStateDescriptor,
) -> GlyphBrushBuilder<'a, wgpu::DepthStencilStateDescriptor, H> {
GlyphBrushBuilder {
inner: self.inner,
texture_filter_method: self.texture_filter_method,
depth: depth_stencil_state,
}
}
}
impl<'a, H: BuildHasher> GlyphBrushBuilder<'a, (), H> {
pub fn build(
self,
device: &mut wgpu::Device,
render_format: wgpu::TextureFormat,
) -> GlyphBrush<'a, (), H> {
GlyphBrush::<(), H>::new(
device,
self.texture_filter_method,
render_format,
self.inner,
)
}
}
impl<'a, H: BuildHasher>
GlyphBrushBuilder<'a, wgpu::DepthStencilStateDescriptor, H>
{
pub fn build(
self,
device: &mut wgpu::Device,
render_format: wgpu::TextureFormat,
) -> GlyphBrush<'a, wgpu::DepthStencilStateDescriptor, H> {
GlyphBrush::<wgpu::DepthStencilStateDescriptor, H>::new(
device,
self.texture_filter_method,
render_format,
self.depth,
self.inner,
)
}
}