Add ui.colored_label(color, text) helper function
This commit is contained in:
parent
c173ea6b2f
commit
2075cb4676
3 changed files with 10 additions and 5 deletions
|
@ -51,8 +51,8 @@ impl Widgets {
|
||||||
ui.horizontal_wrapped_for_text(TextStyle::Body, |ui| {
|
ui.horizontal_wrapped_for_text(TextStyle::Body, |ui| {
|
||||||
ui.label("Long text will wrap, just as you would expect.");
|
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("Text can have").text_color(srgba(110, 255, 110, 255)));
|
||||||
ui.add(Label::new("color").text_color(srgba(128, 140, 255, 255)));
|
ui.colored_label(srgba(128, 140, 255, 255), "color"); // Shortcut version
|
||||||
ui.add(Label::new("and tooltips.")).on_hover_text(
|
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.",
|
"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.",
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -531,6 +531,11 @@ impl Ui {
|
||||||
self.add(label.into())
|
self.add(label.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Shortcut for `add(Label::new(text).text_color(color))`
|
||||||
|
pub fn colored_label(&mut self, color: impl Into<Srgba>, label: impl Into<Label>) -> Response {
|
||||||
|
self.add(label.into().text_color(color))
|
||||||
|
}
|
||||||
|
|
||||||
/// Shortcut for `add(Label::new(text).heading())`
|
/// Shortcut for `add(Label::new(text).heading())`
|
||||||
pub fn heading(&mut self, label: impl Into<Label>) -> Response {
|
pub fn heading(&mut self, label: impl Into<Label>) -> Response {
|
||||||
self.add(label.into().heading())
|
self.add(label.into().heading())
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
//! Widgets are pieces of GUI such as labels, buttons, sliders etc.
|
//! Widgets are pieces of GUI such as labels, buttons, sliders etc.
|
||||||
//!
|
//!
|
||||||
//! Example widget uses:
|
//! Example widget uses:
|
||||||
//! * `ui.add(Label::new("Text").text_color(color::red));`//!
|
//! * `ui.add(Label::new("Text").text_color(color::red));`
|
||||||
//! * `if ui.add(Button::new("Click me")).clicked { ... }`
|
//! * `if ui.add(Button::new("Click me")).clicked { ... }`
|
||||||
|
|
||||||
#![allow(clippy::new_without_default)]
|
#![allow(clippy::new_without_default)]
|
||||||
|
@ -73,8 +73,8 @@ impl Label {
|
||||||
self.text_style(TextStyle::Small)
|
self.text_style(TextStyle::Small)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn text_color(mut self, text_color: Srgba) -> Self {
|
pub fn text_color(mut self, text_color: impl Into<Srgba>) -> Self {
|
||||||
self.text_color = Some(text_color);
|
self.text_color = Some(text_color.into());
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue