Skip to content

Commit

Permalink
Update context.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
rustbasic authored Oct 12, 2024
1 parent 23728e1 commit 11fb0bf
Showing 1 changed file with 3 additions and 19 deletions.
22 changes: 3 additions & 19 deletions crates/egui/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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?
Expand Down

0 comments on commit 11fb0bf

Please sign in to comment.