simplify font init code

This commit is contained in:
Simon Gardling 2022-03-08 12:46:48 -05:00
parent d9dcdc5815
commit 3104b5b689

View File

@ -44,8 +44,27 @@ flate!(static FONT_FILE: [u8] from "assets/Ubuntu-Light.ttf"); // Font used when
flate!(static EMOJI_FILE: [u8] from "assets/NotoEmoji-Regular.ttf"); // Font used when displaying emojis flate!(static EMOJI_FILE: [u8] from "assets/NotoEmoji-Regular.ttf"); // Font used when displaying emojis
lazy_static::lazy_static! { lazy_static::lazy_static! {
static ref FONT_DATA: FontData = FontData::from_static(&FONT_FILE); static ref FONT_DEFINITIONS: FontDefinitions = {
static ref EMOJI_DATA: FontData = FontData::from_static(&EMOJI_FILE); let mut fonts = FontDefinitions::default();
fonts
.font_data
.insert("Ubuntu-Light".to_owned(), FontData::from_static(&FONT_FILE));
fonts
.font_data
.insert("NotoEmoji-Regular".to_owned(), FontData::from_static(&EMOJI_FILE));
fonts.families.insert(
FontFamily::Monospace,
vec!["Ubuntu-Light".to_owned(), "NotoEmoji-Regular".to_owned()],
);
fonts.families.insert(
FontFamily::Proportional,
vec!["Ubuntu-Light".to_owned(), "NotoEmoji-Regular".to_owned()],
);
fonts
};
} }
// Used when displaying supported expressions in the Help window // Used when displaying supported expressions in the Help window
@ -219,6 +238,7 @@ impl MathApp {
ui.label("Function:"); ui.label("Function:");
if functions_len > 1 { if functions_len > 1 {
// There's more than 1 function! Functions can now be deleted
if ui if ui
.add(Button::new("X")) .add(Button::new("X"))
.on_hover_text("Delete Function") .on_hover_text("Delete Function")
@ -227,6 +247,7 @@ impl MathApp {
remove_i = Some(i); remove_i = Some(i);
} }
} else { } else {
// Display greyed out "X" button if there's only one function added
ui.add_enabled(false, Button::new("X")); ui.add_enabled(false, Button::new("X"));
} }
@ -321,26 +342,7 @@ impl epi::App for MathApp {
false => Visuals::light(), false => Visuals::light(),
}); });
// Reduce size of final binary by just including one font ctx.set_fonts(FONT_DEFINITIONS.clone()); // Initialize fonts
let mut fonts = FontDefinitions::default();
fonts
.font_data
.insert("Ubuntu-Light".to_owned(), FONT_DATA.clone());
fonts
.font_data
.insert("NotoEmoji-Regular".to_owned(), EMOJI_DATA.clone());
fonts.families.insert(
FontFamily::Monospace,
vec!["Ubuntu-Light".to_owned(), "NotoEmoji-Regular".to_owned()],
);
fonts.families.insert(
FontFamily::Proportional,
vec!["Ubuntu-Light".to_owned(), "NotoEmoji-Regular".to_owned()],
);
ctx.set_fonts(fonts);
// Creates Top bar that contains some general options // Creates Top bar that contains some general options
TopBottomPanel::top("top_bar").show(ctx, |ui| { TopBottomPanel::top("top_bar").show(ctx, |ui| {