Text styles
The look’s type scale: text says what it is (a title, a headline, body text, a caption) and the theme says how large and heavy that is, for one label or for everything inside an area.
A label in a role
ui.add(Label::new("Storage").font(TextRole::Title3));
ui.add(Label::new("Used by your photos and messages").font(TextRole::Subheadline));
ui.add(Label::new("12.4 GB of 64 GB").font(TextRole::Caption));
Everything inside an area
ui.text_style(TextRole::Caption, |ui| {
ui.add(Label::new("Labels without a role of their own"));
ui.label("and egui's own labels");
ui.add(Label::new("unless they pick one").font(TextRole::Headline));
});
egui’s own text
let headline = TextRole::Headline.font_id(ui.ctx());
ui.label(egui::RichText::new("Recent files").font(headline));
A scale from another base size
// Larger text: build the scale from another base size, then
// set it on the look's shape.
let mut larger = (*tokens(ui.ctx())).clone();
larger.shape.type_scale = TypeScale::for_base_size(16.0);
The story above is gallery/src/stories/typography.rs, running in your browser. Every snippet on this page is cut from it.