GPU-accelerated UI toolkit (Vulkan)
git clone https://git.lucas.co/cce-ui.git
Optimize performance: cache text labels and styled labels
src/widget/display/label.rs | 13 +------------
src/widget/display/text_label.rs | 16 +---------------
2 files changed, 2 insertions(+), 27 deletions(-)
diff --git a/src/widget/display/label.rs b/src/widget/display/label.rs
index 40a0e57..1cb3afe 100644
--- a/src/widget/display/label.rs
+++ b/src/widget/display/label.rs
@@ -102,18 +102,7 @@ impl StyledLabel {
pub fn new_with_family(fs: &mut glyphon::FontSystem, text: &str, size: f32, color: [f32; 4], family: &str) -> Self {
let scale = crate::scale::scale_factor();
- let physical_size = size * scale;
- let metrics = glyphon::Metrics::new(physical_size, physical_size * 1.4);
- let mut buffer = glyphon::Buffer::new(fs, metrics);
- let family_enum = match family {
- "monospace" => glyphon::Family::Name(crate::layout::get_system_monospace_font()),
- "sans-serif" => glyphon::Family::SansSerif,
- "serif" => glyphon::Family::Serif,
- name => glyphon::Family::Name(name),
- };
- let attrs = glyphon::Attrs::new().family(family_enum);
- buffer.set_text(fs, text, attrs, glyphon::Shaping::Advanced);
- buffer.shape_until_scroll(fs, true);
+ let buffer = crate::backend::window_runner::get_text_buffer(fs, text, size, Some(family));
let w = buffer.layout_runs().next().map(|r| r.line_w).unwrap_or(0.0) / scale;
let g_color = glyphon::Color::rgb(
(color[0] * 255.0) as u8,
diff --git a/src/widget/display/text_label.rs b/src/widget/display/text_label.rs
index 5d7e625..8d60474 100644
--- a/src/widget/display/text_label.rs
+++ b/src/widget/display/text_label.rs
@@ -75,19 +75,5 @@ impl TextLabel {
}
pub(crate) fn make_widget_text_buffer(fs: &mut glyphon::FontSystem, text: &str, size: f32, font_family: &str) -> glyphon::Buffer {
- let scale = crate::scale::scale_factor();
- let physical_size = size * scale;
- let metrics = glyphon::Metrics::new(physical_size, physical_size * 1.4);
- let mut buf = glyphon::Buffer::new(fs, metrics);
- let (family_name, _) = crate::layout::parse_font_string(font_family);
- let family = match family_name.as_str() {
- "monospace" => glyphon::Family::Name(crate::layout::get_system_monospace_font()),
- "sans-serif" => glyphon::Family::SansSerif,
- "serif" => glyphon::Family::Serif,
- _ => glyphon::Family::Name(&family_name),
- };
- let attrs = glyphon::Attrs::new().family(family);
- buf.set_text(fs, text, attrs, glyphon::Shaping::Advanced);
- buf.shape_until_scroll(fs, true);
- buf
+ crate::backend::window_runner::get_text_buffer(fs, text, size, Some(font_family))
}