diff --git a/crates/egui_demo_lib/src/demo/font_book.rs b/crates/egui_demo_lib/src/demo/font_book.rs index e2310f8a1e3..a71bd96e319 100644 --- a/crates/egui_demo_lib/src/demo/font_book.rs +++ b/crates/egui_demo_lib/src/demo/font_book.rs @@ -42,12 +42,14 @@ impl crate::View for FontBook { ui.add(crate::egui_github_link_file!()); }); + let available_glyphs = self + .available_glyphs + .entry(self.font_id.family.clone()) + .or_insert_with(|| available_characters(ui, self.font_id.clone())); + ui.label(format!( "The selected font supports {} characters.", - self.available_glyphs - .get(&self.font_id.family) - .map(|map| map.len()) - .unwrap_or_default() + available_glyphs.len() )); ui.horizontal_wrapped(|ui| { @@ -74,10 +76,6 @@ impl crate::View for FontBook { }); let filter = &self.filter; - let available_glyphs = self - .available_glyphs - .entry(self.font_id.family.clone()) - .or_insert_with(|| available_characters(ui, self.font_id.family.clone())); ui.separator(); @@ -105,7 +103,7 @@ impl crate::View for FontBook { )); }; - if ui.add(button).on_hover_ui(tooltip_ui).clicked() { + if ui.add(button).on_hover_ui_at_pointer(tooltip_ui).clicked() { ui.ctx().copy_text(chr.to_string()); } } @@ -115,11 +113,11 @@ impl crate::View for FontBook { } } -fn available_characters(ui: &egui::Ui, family: egui::FontFamily) -> BTreeMap { +fn available_characters(ui: &egui::Ui, font_id: egui::FontId) -> BTreeMap { ui.fonts(|f| { f.lock() .fonts - .font(&egui::FontId::new(10.0, family)) // size is arbitrary for getting the characters + .font(&font_id) .characters() .iter() .filter(|(chr, _fonts)| !chr.is_whitespace() && !chr.is_ascii_control())