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 #5345

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
20 changes: 3 additions & 17 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 @@ -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.
Expand Down
Loading