Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple method for changing sub-window title font #5292

Open
Resonanz opened this issue Oct 21, 2024 · 2 comments
Open

Simple method for changing sub-window title font #5292

Resonanz opened this issue Oct 21, 2024 · 2 comments

Comments

@Resonanz
Copy link

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
Copy link

marci1175 commented Nov 1, 2024

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| {});

@Resonanz
Copy link
Author

Resonanz commented Nov 2, 2024

You're right. Thanks for pointing that out. Very helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants