summaryrefslogtreecommitdiffstats
path: root/wgpu/src/text.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2023-06-16 15:50:03 +0200
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2023-06-16 15:50:03 +0200
commit0c65936664dfba70fe5d22d1347c14cf9f85d0da (patch)
tree4313233d0f05a9006b16aa9216419d81a87da885 /wgpu/src/text.rs
parent267dbf34e94bbdfe99de857aea5930f1fcac7aec (diff)
downloadiced-0c65936664dfba70fe5d22d1347c14cf9f85d0da.tar.gz
iced-0c65936664dfba70fe5d22d1347c14cf9f85d0da.tar.bz2
iced-0c65936664dfba70fe5d22d1347c14cf9f85d0da.zip
Update `glyphon` and `cosmic-text`
Diffstat (limited to 'wgpu/src/text.rs')
-rw-r--r--wgpu/src/text.rs31
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),