From 11fb0bfdfb07ff618b65dfce644ac46bc0d44240 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sat, 12 Oct 2024 23:08:46 +0900 Subject: [PATCH] Update context.rs --- crates/egui/src/context.rs | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/crates/egui/src/context.rs b/crates/egui/src/context.rs index e8b0803b958..9bbfca152bd 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; @@ -1725,27 +1725,11 @@ impl Context { /// /// The default `egui` fonts only support latin and cyrillic alphabets, /// but you can call this to install additional fonts that support e.g. korean characters. - /// - /// The new fonts will become active at the start of the next pass. 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()); } /// Does the OS use dark or light mode?