Skip to content

Commit

Permalink
h
Browse files Browse the repository at this point in the history
  • Loading branch information
zombkit committed Apr 20, 2024
1 parent e05e850 commit 30451d8
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 3 deletions.
2 changes: 1 addition & 1 deletion examples/hello_world_web/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 59 additions & 2 deletions examples/hello_world_web/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,18 @@ impl Default for HelloApp {
impl NewCC for HelloApp {
/// Called once before the first frame.
fn new(cc: &eframe::CreationContext<'_>) -> Self {
// setup_custom_fonts(&cc.egui_ctx);
Default::default()
setup_custom_fonts(&cc.egui_ctx);
//Creating the Ratatui backend/ Egui widget here
let backend = RataguiBackend::new_with_fonts(
100,
100,
"Regular".into(),
"Bold".into(),
"Oblique".into(),
"BoldOblique".into(),
);
let mut terminal = Terminal::new(backend).unwrap();
Self { terminal: terminal }
}
}

Expand Down Expand Up @@ -69,3 +79,50 @@ impl eframe::App for HelloApp {
});
}
}

fn setup_custom_fonts(ctx: &egui::Context) {
// Start with the default fonts (we will be adding to them rather than replacing them).
let mut fonts = egui::FontDefinitions::default();

// Install my own font (maybe supporting non-latin characters).
// .ttf and .otf files supported.
fonts.font_data.insert(
"Regular".to_owned(),
egui::FontData::from_static(include_bytes!("../../../assets/fonts/Iosevka-Regular.ttf")),
);
fonts.families.insert(
egui::FontFamily::Name("Regular".into()),
vec!["Regular".to_owned()],
);
fonts.font_data.insert(
"Bold".to_owned(),
egui::FontData::from_static(include_bytes!("../../../assets/fonts/Iosevka-Bold.ttf")),
);
fonts.families.insert(
egui::FontFamily::Name("Bold".into()),
vec!["Bold".to_owned()],
);

fonts.font_data.insert(
"Oblique".to_owned(),
egui::FontData::from_static(include_bytes!("../../../assets/fonts/Iosevka-Oblique.ttf")),
);
fonts.families.insert(
egui::FontFamily::Name("Oblique".into()),
vec!["Oblique".to_owned()],
);

fonts.font_data.insert(
"BoldOblique".to_owned(),
egui::FontData::from_static(include_bytes!(
"../../../assets/fonts/Iosevka-BoldOblique.ttf"
)),
);
fonts.families.insert(
egui::FontFamily::Name("BoldOblique".into()),
vec!["BoldOblique".to_owned()],
);

// Tell egui to use these fonts:
ctx.set_fonts(fonts);
}

0 comments on commit 30451d8

Please sign in to comment.