Crates.io | egui_font_loader |
lib.rs | egui_font_loader |
version | 1.0.0 |
created_at | 2025-04-22 22:36:03.0521+00 |
updated_at | 2025-04-22 22:36:03.0521+00 |
description | Egui simple font loader |
homepage | |
repository | https://github.com/RakuJa/egui_font_loader |
max_upload_size | |
id | 1644770 |
size | 18,349 |
A simple library to simplify egui font loading
Important! It's advised to load the font only once and avoid doing it in the update function.
Fonts need to be found locally.
To load a single font known at compile time, it's suggested to use the load_font macro
load_font!(ctx, "DesiredFontName", "path/to/font.ttf");
The DesiredFontName can be anything, just keep it in mind to load it later on.
use egui_font_loader::LoaderFontData;
use egui_font_loader::load_fonts;
let fonts = vec![
LoaderFontData {
name: "DesiredFontName".into(),
path: "path/to/custom/font/first.ttf".into(),
},
LoaderFontData {
name: "SecondCustomFont".into(),
path: "path/to/custom/font/second.ttf".into(),
},
];
load_fonts(&egui_ctx, fonts).unwrap();
// Some code
ui.heading(
RichText::new("Code By RakuJa")
.color(Color32::from_rgb(102, 0, 51))
.font(FontId {
size: 15.0,
family: FontFamily::Name("DesiredFontName".into()),
}),
);
// Some other code
In the main.rs
eframe::run_native(
"My window title",
options,
Box::new(|cc| {
Ok(Box::new(MyApp::new(cc)))
}),
)
In myapp.rs
impl MyApp {
pub fn new(
cc: &eframe::CreationContext<'_>,
) -> Self {
// This is also where you can customize the look and feel of egui using
// `cc.egui_ctx.set_visuals` and `cc.egui_ctx.set_fonts`.
load_fonts(&cc.egui_ctx, vec![/*add LoaderFontData here*/]).unwrap();
Self {//initialize it}
}
}