Skip to content

Commit

Permalink
customize fonts
Browse files Browse the repository at this point in the history
  • Loading branch information
chanmaoganda committed Jul 10, 2024
1 parent df01e19 commit 128bbc2
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 7 deletions.
Binary file added assets/consola_mono/ConsolaMono-Bold.ttf
Binary file not shown.
Binary file added assets/consola_mono/ConsolaMono-Book.ttf
Binary file not shown.
32 changes: 30 additions & 2 deletions crates/gui/src/league_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ pub struct LeagueApp {
}

impl LeagueApp {
pub fn new() -> Self {
pub fn new(cc: &eframe::CreationContext<'_>) -> Self {
Self::customize_font(&cc.egui_ctx);
Self {
lcu_client: Arc::new(RwLock::new(lcu_api::LcuClient::new())),
histories: Arc::new(RwLock::new(vec![])),
Expand Down Expand Up @@ -37,6 +38,18 @@ impl LeagueApp {

impl eframe::App for LeagueApp {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {

let mut style = (*ctx.style()).clone();
style.text_styles = [
(egui::TextStyle::Heading, egui::FontId::new(12.0, egui::FontFamily::Proportional)),
(egui::TextStyle::Body, egui::FontId::new(11.0, egui::FontFamily::Proportional)),
(egui::TextStyle::Monospace, egui::FontId::new(8.0, egui::FontFamily::Proportional)),
(egui::TextStyle::Button, egui::FontId::new(14.0, egui::FontFamily::Proportional)),
(egui::TextStyle::Small, egui::FontId::new(10.0, egui::FontFamily::Proportional)),
]
.into();
ctx.set_style(style);

egui_extras::install_image_loaders(ctx);
CentralPanel::default().show(ctx, |ui| {
self.render_refresh_button(ui);
Expand Down Expand Up @@ -64,7 +77,9 @@ impl LeagueApp {
log::debug!("rendering player {}", slot + 1);
let games = &history.game_history.game_list;
ui.add_space(PADDING);
ui.add(Label::new(format!("player {} game history: ", slot + 1)));
let header = egui::RichText::new(format!("player {} game history: ", slot + 1))
.font(egui::FontId::new(14.0, egui::FontFamily::Proportional));
ui.label(header);
ui.add_space(PADDING);
for (index, game) in games.iter().enumerate() {
if index == 5 {
Expand All @@ -86,4 +101,17 @@ impl LeagueApp {
}
}

fn customize_font(ctx: &egui::Context) {
let mut fonts = egui::FontDefinitions::default();
fonts.font_data.insert("consola".to_owned(),
egui::FontData::from_static(include_bytes!("../../../assets/consola_mono/ConsolaMono-Book.ttf")));
fonts.families.entry(
egui::FontFamily::Proportional).or_default()
.insert(0, "consola".to_owned());
fonts.families.entry(
egui::FontFamily::Monospace).or_default()
.insert(0, "consola".to_owned());
ctx.set_fonts(fonts);
}

}
8 changes: 3 additions & 5 deletions crates/gui/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,19 @@ pub use league_app::LeagueApp;
fn main() -> Result<(), eframe::Error> {
env_logger::init();
free_window::hide_console_window();

let app = LeagueApp::new();

let main_win_opts = eframe::NativeOptions {
viewport: egui::ViewportBuilder::default()
.with_inner_size([640., 460.]),
.with_inner_size([720., 460.]),
persist_window: true,
..Default::default()
};

eframe::run_native(
"Match History",
main_win_opts,
Box::new(move |_| {
Ok(Box::new(app))
Box::new(move |cc| {
Ok(Box::new(LeagueApp::new(cc)))
}),
)?;

Expand Down

0 comments on commit 128bbc2

Please sign in to comment.