From 2075cb4676b5b3a18ab062f17263d05d964685e4 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Fri, 11 Dec 2020 12:25:28 +0100 Subject: [PATCH] Add ui.colored_label(color, text) helper function --- egui/src/demos/widgets.rs | 4 ++-- egui/src/ui.rs | 5 +++++ egui/src/widgets/mod.rs | 6 +++--- 3 files changed, 10 insertions(+), 5 deletions(-) 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