Don't load fonts in doctests (#1711)
I was hoping this would speed up the doctests, but it doesn't really
This commit is contained in:
parent
317436c057
commit
8c7c4c764b
2 changed files with 67 additions and 51 deletions
|
@ -527,6 +527,7 @@ pub enum WidgetType {
|
|||
/// For use in tests; especially doctests.
|
||||
pub fn __run_test_ctx(mut run_ui: impl FnMut(&Context)) {
|
||||
let ctx = Context::default();
|
||||
ctx.set_fonts(FontDefinitions::empty()); // prevent fonts from being loaded (save CPU time)
|
||||
let _ = ctx.run(Default::default(), |ctx| {
|
||||
run_ui(ctx);
|
||||
});
|
||||
|
@ -535,6 +536,7 @@ pub fn __run_test_ctx(mut run_ui: impl FnMut(&Context)) {
|
|||
/// For use in tests; especially doctests.
|
||||
pub fn __run_test_ui(mut add_contents: impl FnMut(&mut Ui)) {
|
||||
let ctx = Context::default();
|
||||
ctx.set_fonts(FontDefinitions::empty()); // prevent fonts from being loaded (save CPU time)
|
||||
let _ = ctx.run(Default::default(), |ctx| {
|
||||
crate::CentralPanel::default().show(ctx, |ui| {
|
||||
add_contents(ui);
|
||||
|
|
|
@ -244,14 +244,21 @@ pub struct FontDefinitions {
|
|||
}
|
||||
|
||||
impl Default for FontDefinitions {
|
||||
/// Specifies the default fonts if the feature `default_fonts` is enabled,
|
||||
/// otherwise this is the same as [`Self::empty`].
|
||||
#[cfg(not(feature = "default_fonts"))]
|
||||
fn default() -> Self {
|
||||
Self::empty()
|
||||
}
|
||||
|
||||
/// Specifies the default fonts if the feature `default_fonts` is enabled,
|
||||
/// otherwise this is the same as [`Self::empty`].
|
||||
#[cfg(feature = "default_fonts")]
|
||||
fn default() -> Self {
|
||||
#[allow(unused)]
|
||||
let mut font_data: BTreeMap<String, FontData> = BTreeMap::new();
|
||||
|
||||
let mut families = BTreeMap::new();
|
||||
|
||||
#[cfg(feature = "default_fonts")]
|
||||
{
|
||||
font_data.insert(
|
||||
"Hack".to_owned(),
|
||||
FontData::from_static(include_bytes!("../../fonts/Hack-Regular.ttf")),
|
||||
|
@ -296,13 +303,6 @@ impl Default for FontDefinitions {
|
|||
"emoji-icon-font".to_owned(),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "default_fonts"))]
|
||||
{
|
||||
families.insert(FontFamily::Monospace, vec![]);
|
||||
families.insert(FontFamily::Proportional, vec![]);
|
||||
}
|
||||
|
||||
Self {
|
||||
font_data,
|
||||
|
@ -311,6 +311,20 @@ impl Default for FontDefinitions {
|
|||
}
|
||||
}
|
||||
|
||||
impl FontDefinitions {
|
||||
/// No fonts.
|
||||
pub fn empty() -> Self {
|
||||
let mut families = BTreeMap::new();
|
||||
families.insert(FontFamily::Monospace, vec![]);
|
||||
families.insert(FontFamily::Proportional, vec![]);
|
||||
|
||||
Self {
|
||||
font_data: Default::default(),
|
||||
families,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
/// The collection of fonts used by `epaint`.
|
||||
|
|
Loading…
Reference in a new issue