diff --git a/egui/src/demos/widgets.rs b/egui/src/demos/widgets.rs index 21bf7b37..d01d7ab5 100644 --- a/egui/src/demos/widgets.rs +++ b/egui/src/demos/widgets.rs @@ -51,8 +51,8 @@ impl Widgets { ui.horizontal_wrapped_for_text(TextStyle::Body, |ui| { ui.label("Long text will wrap, just as you would expect."); ui.add(Label::new("Text can have").text_color(srgba(110, 255, 110, 255))); - ui.add(Label::new("color").text_color(srgba(128, 140, 255, 255))); - ui.add(Label::new("and tooltips.")).on_hover_text( + ui.colored_label(srgba(128, 140, 255, 255), "color"); // Shortcut version + ui.label("and tooltips.").on_hover_text( "This is a multiline tooltip that demonstrates that you can easily add tooltips to any element.\nThis is the second line.\nThis is the third.", ); diff --git a/egui/src/ui.rs b/egui/src/ui.rs index 4706a5be..38902e14 100644 --- a/egui/src/ui.rs +++ b/egui/src/ui.rs @@ -531,6 +531,11 @@ impl Ui { self.add(label.into()) } + /// Shortcut for `add(Label::new(text).text_color(color))` + pub fn colored_label(&mut self, color: impl Into, label: impl Into