From 713f71a19222f9ec05bccb9989e52891967aabc7 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Fri, 20 Sep 2024 21:06:25 +0900 Subject: [PATCH 1/3] Update font_book.rs --- crates/egui_demo_lib/src/demo/font_book.rs | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) 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()) From b71e2ef733bc699f9f162325a9bda5fdd6b08e01 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Fri, 20 Sep 2024 21:15:26 +0900 Subject: [PATCH 2/3] Update font_book.rs --- crates/egui_demo_lib/src/demo/font_book.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/egui_demo_lib/src/demo/font_book.rs b/crates/egui_demo_lib/src/demo/font_book.rs index a71bd96e319..fad27f87399 100644 --- a/crates/egui_demo_lib/src/demo/font_book.rs +++ b/crates/egui_demo_lib/src/demo/font_book.rs @@ -45,7 +45,7 @@ impl crate::View for FontBook { let available_glyphs = self .available_glyphs .entry(self.font_id.family.clone()) - .or_insert_with(|| available_characters(ui, self.font_id.clone())); + .or_insert_with(|| available_characters(ui, &self.font_id)); ui.label(format!( "The selected font supports {} characters.", @@ -113,11 +113,11 @@ impl crate::View for FontBook { } } -fn available_characters(ui: &egui::Ui, font_id: egui::FontId) -> BTreeMap { +fn available_characters(ui: &egui::Ui, font_id: &egui::FontId) -> BTreeMap { ui.fonts(|f| { f.lock() .fonts - .font(&font_id) + .font(font_id) .characters() .iter() .filter(|(chr, _fonts)| !chr.is_whitespace() && !chr.is_ascii_control()) From 647c4f09b1d625ead28dcfde24d81ab869a3701e Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sun, 3 Nov 2024 00:23:15 +0900 Subject: [PATCH 3/3] Update font_book.rs --- crates/egui_demo_lib/src/demo/font_book.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/egui_demo_lib/src/demo/font_book.rs b/crates/egui_demo_lib/src/demo/font_book.rs index fad27f87399..f776eb0e867 100644 --- a/crates/egui_demo_lib/src/demo/font_book.rs +++ b/crates/egui_demo_lib/src/demo/font_book.rs @@ -69,7 +69,6 @@ impl crate::View for FontBook { ui.horizontal(|ui| { ui.label("Filter:"); ui.add(egui::TextEdit::singleline(&mut self.filter).desired_width(120.0)); - self.filter = self.filter.to_lowercase(); if ui.button("x").clicked() { self.filter.clear(); }