emilk / egui

egui: an easy-to-use immediate mode GUI in Rust that runs on both web and native
https://www.egui.rs/
Apache License 2.0
22.26k stars 1.6k forks source link

Simple method for changing sub-window title font #5292

Open Resonanz opened 1 week ago

Resonanz commented 1 week ago

The first image below appears to me at least to have a title font that is far to large (I am using Ubuntu 24.04).

The second image shows a reduced font size but still doesn't look great to me. The code for reducing the font size for the second case is below.

A simple method call for setting the font properties would be very helpful.

Screenshot from 2024-10-21 17-18-19 Screenshot from 2024-10-21 17-17-38

let mut style: egui::Style = (*ctx.style()).clone();

style.text_styles.insert(
    egui::TextStyle::Heading,
    FontId::new(14.0, egui::FontFamily::Proportional), // Set the font size to 14.0
);

// Apply the new style
ctx.set_style(style);

egui::Window::new("THE TITLE").show(ctx, |ui| {
    ui.label("This window has a custom title font size.");
    ui.label(egui::RichText::new("I'm a heading").heading());
});
marci1175 commented 11 hours ago

Hi! Since the Window::new() function needs an Into<WidgetText> (WidgetText) as an argument, you can actually pass in a RichText so you can directly modify the header's style. Example:

egui::Window::new(RichText::from("Cool window").size(20.)).show(ctx, |ui| {});