Skip to content

Commit ff217e5

Browse files
committed
Fix font caching
1 parent 9f43017 commit ff217e5

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

loopers-gui/src/lib.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ mod app;
77
mod skia;
88
mod widgets;
99

10-
use skia_safe::{Canvas, Font, FontMgr, FontStyle, Size};
10+
use skia_safe::{Canvas, Font, FontMgr, FontStyle, Size, Typeface};
1111

1212
use crate::app::MainPage;
1313
use crossbeam_channel::{Sender, TryRecvError, TrySendError};
@@ -28,10 +28,14 @@ const SHOW_BUTTONS: bool = true;
2828

2929
pub const MESSAGE_DISPLAY_TIME_SECS: u64 = 4;
3030

31+
lazy_static! {
32+
static ref DEFAULT_TYPEFACE: Option<Typeface> =
33+
FontMgr::default().legacy_make_typeface(None, FontStyle::normal());
34+
}
35+
3136
pub fn default_font(size: f32) -> Font {
32-
let typeface = FontMgr::default().legacy_make_typeface(None, FontStyle::normal());
33-
match typeface {
34-
Some(typeface) => Font::new(typeface, size),
37+
match DEFAULT_TYPEFACE.as_ref() {
38+
Some(typeface) => Font::new(typeface.clone(), size),
3539
None => {
3640
let mut font = Font::default();
3741
font.set_size(size);

0 commit comments

Comments
 (0)