Rich text
egui’s RichText wherever a component shows your text: a colour, a weight or italics of your own, and the component’s look for the rest.
Options
let theme = tokens(ui.ctx());
let headline = TextRole::Headline.font_id(ui.ctx());
ui.add(
Picker::new("plan", &mut state.plan)
.style(&picker_styles::Radio)
.entry(PickerOption::new(1, "Starter").description("For one person"))
.entry(
PickerOption::new(2, RichText::new("Team").font(headline)).description(
RichText::new("Most teams pick this").color(theme.success.background),
),
)
.entry(
PickerOption::new(3, "Enterprise")
.description(RichText::new("Talk to us first").italics()),
),
);
Menus and fields
let muted = tokens(ui.ctx()).muted_foreground;
ui.add(
Picker::new("sort", &mut state.sort)
.style(&picker_styles::Menu)
.title_prefix(RichText::new("Sort: ").color(muted))
.item(1, "Newest")
.item(2, "Oldest")
.item(3, RichText::new("Starred").strong()),
);
ui.add(
Combobox::new("fruit", &mut state.fruit)
.placeholder(RichText::new("Pick a fruit...").italics())
.item(1, "Apple")
.item(2, "Banana"),
);
Messages
let theme = tokens(ui.ctx());
Message::new()
.author(
RichText::new("Alice")
.font(TextRole::Headline.font_id(ui.ctx()))
.color(theme.info.background),
)
.time("10:24 AM")
.footer(RichText::new("Edited").italics())
.show(ui, |ui| {
ui.add(
Bubble::new()
.text("The draft is ready.")
.variant(BubbleVariant::Secondary)
.timestamp(RichText::new("10:24").underline()),
);
});
Trails and rules
let theme = tokens(ui.ctx());
let _ = Breadcrumb::new()
.item("Home")
.item("Projects")
.item(BreadcrumbItem::new(
RichText::new("Launch").color(theme.primary.background),
))
.show(ui);
ui.add(Separator::horizontal().label(RichText::new("New since yesterday").italics()));
The story above is gallery/src/stories/rich_text.rs, running in your browser. Every snippet on this page is cut from it.