|
|
@ -407,7 +407,14 @@ impl Context { |
|
|
|
|
|
|
|
/// Will become active at the start of the next frame.
|
|
|
|
pub fn set_fonts(&self, font_definitions: FontDefinitions) { |
|
|
|
self.memory().options.font_definitions = font_definitions; |
|
|
|
if let Some(current_fonts) = &self.fonts { |
|
|
|
// NOTE: this comparison is expensive since it checks TTF data for equality
|
|
|
|
if current_fonts.definitions() == &font_definitions { |
|
|
|
return; // no change - save us from reloading font textures
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
self.memory().new_font_definitions = Some(font_definitions); |
|
|
|
} |
|
|
|
|
|
|
|
/// The [`Style`] used by all subsequent windows, panels etc.
|
|
|
@ -531,21 +538,25 @@ impl Context { |
|
|
|
self.input = input.begin_frame(new_raw_input); |
|
|
|
self.frame_state.lock().begin_frame(&self.input); |
|
|
|
|
|
|
|
let font_definitions = self.memory().options.font_definitions.clone(); |
|
|
|
{ |
|
|
|
// Load new fonts if required:
|
|
|
|
let new_font_definitions = self.memory().new_font_definitions.take(); |
|
|
|
let pixels_per_point = self.input.pixels_per_point(); |
|
|
|
let same_as_current = match &self.fonts { |
|
|
|
None => false, |
|
|
|
Some(fonts) => { |
|
|
|
*fonts.definitions() == font_definitions |
|
|
|
&& (fonts.pixels_per_point() - pixels_per_point).abs() < 1e-3 |
|
|
|
|
|
|
|
let pixels_per_point_changed = match &self.fonts { |
|
|
|
None => true, |
|
|
|
Some(current_fonts) => { |
|
|
|
(current_fonts.pixels_per_point() - pixels_per_point).abs() > 1e-3 |
|
|
|
} |
|
|
|
}; |
|
|
|
if !same_as_current { |
|
|
|
|
|
|
|
if self.fonts.is_none() || new_font_definitions.is_some() || pixels_per_point_changed { |
|
|
|
self.fonts = Some(Arc::new(Fonts::from_definitions( |
|
|
|
pixels_per_point, |
|
|
|
font_definitions, |
|
|
|
new_font_definitions.unwrap_or_default(), |
|
|
|
))); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// Ensure we register the background area so panels and background ui can catch clicks:
|
|
|
|
let screen_rect = self.input.screen_rect(); |
|
|
|