0

I am trying to understand how a font style and size works in egui "0.19.0".

For example I wish to choose the font style and size of text in a TextEdit box. Here is what I have tried.

ui.add(
    TextEdit::multiline(&mut ss)
    .text_color(Color32::LIGHT_RED)
    .font(FontSelection::FontId(FontId::new(
    20.,
    FontFamily::Name("arial".into()),
    ))),
);

As represented above to create a Font, I need to first create a FontSelection which also requires a FontId which consists of a size and FontFamily.

A look at this page on the rust documentations website showed me a way choose font for my text. https://docs.rs/egui/latest/egui/enum.FontFamily.html

enter image description here

Based on this I assume that the FontFamily is the real font style that I can choose from by using the Name function. I come from a java background where normally use item.setFont("Arial") to specify the font of text in the component item.

However my above code panics with the message

thread 'main' panicked at 'FontFamily::Name("serif") is not bound to any fonts',
C:\Users\user\.cargo\registry\src\github.com-1ecc6299db9ec823\epaint-0.19.0\src\text\fonts.rs:594:21

Why doesn't this work?

What are the differences between FontFamily, FontId, FontSelection and how do I choose a font such as Ariel for my text? Links to any relevant documents would be greatly appreciated.

Isaac Dzikum
  • 184
  • 9

0 Answers0