Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: ctx.set_fonts() Doesn't Apply Fonts with Same Name #5253

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading