From 71660a70ccb9e9b543ee939d918203803a0d4994 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sun, 3 Nov 2024 16:31:38 +0900 Subject: [PATCH] Update context.rs --- crates/egui/src/context.rs | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/crates/egui/src/context.rs b/crates/egui/src/context.rs index 331430c7865..10eab71eb56 100644 --- a/crates/egui/src/context.rs +++ b/crates/egui/src/context.rs @@ -567,7 +567,7 @@ impl ContextImpl { } /// Load fonts unless already loaded. - fn update_fonts_mut(&mut self) { + pub(crate) fn update_fonts_mut(&mut self) { crate::profile_function!(); let input = &self.viewport().input; @@ -1759,22 +1759,8 @@ impl Context { pub fn set_fonts(&self, font_definitions: FontDefinitions) { crate::profile_function!(); - let pixels_per_point = self.pixels_per_point(); - - let mut update_fonts = true; - - self.read(|ctx| { - if let Some(current_fonts) = ctx.fonts.get(&pixels_per_point.into()) { - // NOTE: this comparison is expensive since it checks TTF data for equality - if current_fonts.lock().fonts.definitions() == &font_definitions { - update_fonts = false; // no need to update - } - } - }); - - if update_fonts { - self.memory_mut(|mem| mem.new_font_definitions = Some(font_definitions)); - } + self.memory_mut(|mem| mem.new_font_definitions = Some(font_definitions)); + self.write(|ctx| ctx.update_fonts_mut()); } /// Tell `egui` which fonts to use.