diff options
Diffstat (limited to 'wgpu/src/text.rs')
-rw-r--r-- | wgpu/src/text.rs | 31 |
1 files changed, 13 insertions, 18 deletions
diff --git a/wgpu/src/text.rs b/wgpu/src/text.rs index 0d88865c..6a552270 100644 --- a/wgpu/src/text.rs +++ b/wgpu/src/text.rs @@ -53,7 +53,7 @@ impl Pipeline { } pub fn load_font(&mut self, bytes: Cow<'static, [u8]>) { - self.font_system.get_mut().db_mut().load_font_source( + let _ = self.font_system.get_mut().db_mut().load_font_source( glyphon::fontdb::Source::Binary(Arc::new(bytes.into_owned())), ); } @@ -116,15 +116,7 @@ impl Pipeline { let buffer = self.render_cache.get(key).expect("Get cached buffer"); - let (total_lines, max_width) = buffer - .layout_runs() - .enumerate() - .fold((0, 0.0), |(_, max), (i, buffer)| { - (i + 1, buffer.line_w.max(max)) - }); - - let total_height = - total_lines as f32 * buffer.metrics().line_height; + let (max_width, total_height) = measure(buffer); let x = section.bounds.x * scale_factor; let y = section.bounds.y * scale_factor; @@ -265,14 +257,7 @@ impl Pipeline { }, ); - let (total_lines, max_width) = paragraph - .layout_runs() - .enumerate() - .fold((0, 0.0), |(_, max), (i, buffer)| { - (i + 1, buffer.line_w.max(max)) - }); - - (max_width, line_height * total_lines as f32) + measure(paragraph) } pub fn hit_test( @@ -312,6 +297,16 @@ impl Pipeline { } } +fn measure(buffer: &glyphon::Buffer) -> (f32, f32) { + let (width, total_lines) = buffer + .layout_runs() + .fold((0.0, 0usize), |(width, total_lines), run| { + (run.line_w.max(width), total_lines + 1) + }); + + (width, total_lines as f32 * buffer.metrics().line_height) +} + fn to_family(family: font::Family) -> glyphon::Family<'static> { match family { font::Family::Name(name) => glyphon::Family::Name(name), |