ui.label now take impl ToString as argument, not impl Into<Label>

This commit is contained in:
Emil Ernerfeldt 2021-10-18 21:09:44 +02:00
parent ebd2c859ac
commit 9f1a5dcb33
4 changed files with 18 additions and 21 deletions

View file

@ -30,6 +30,7 @@ NOTE: [`epaint`](epaint/CHANGELOG.md), [`eframe`](eframe/CHANGELOG.md), [`egui_w
* `ScrollArea` will auto-shrink to content size unless told otherwise using `ScollArea::auto_shrink`. * `ScrollArea` will auto-shrink to content size unless told otherwise using `ScollArea::auto_shrink`.
* By default, `Slider`'s `clamp_to_range` is set to true. * By default, `Slider`'s `clamp_to_range` is set to true.
* Rename `TextEdit::enabled` to `TextEdit::interactive`. * Rename `TextEdit::enabled` to `TextEdit::interactive`.
* `ui.label` (and friends) now take `impl ToString` as argument instead of `impl Into<Label>`.
### Fixed 🐛 ### Fixed 🐛
* Fix wrongly sized multiline `TextEdit` in justified layouts. * Fix wrongly sized multiline `TextEdit` in justified layouts.

View file

@ -406,7 +406,7 @@ pub use {
/// Helper function that adds a label when compiling with debug assertions enabled. /// Helper function that adds a label when compiling with debug assertions enabled.
pub fn warn_if_debug_build(ui: &mut crate::Ui) { pub fn warn_if_debug_build(ui: &mut crate::Ui) {
if cfg!(debug_assertions) { if cfg!(debug_assertions) {
ui.label( ui.add(
crate::Label::new("‼ Debug build ‼") crate::Label::new("‼ Debug build ‼")
.small() .small()
.text_color(crate::Color32::RED), .text_color(crate::Color32::RED),

View file

@ -949,10 +949,10 @@ fn slider_vec2<'a>(
} }
} }
fn ui_color(ui: &mut Ui, srgba: &mut Color32, text: impl Into<Label>) -> Response { fn ui_color(ui: &mut Ui, srgba: &mut Color32, label: impl Into<Label>) -> Response {
ui.horizontal(|ui| { ui.horizontal(|ui| {
ui.color_edit_button_srgba(srgba); ui.color_edit_button_srgba(srgba);
ui.label(text); ui.add(label.into());
}) })
.response .response
} }

View file

@ -1003,54 +1003,50 @@ impl Ui {
/// ///
/// See also [`Label`]. /// See also [`Label`].
#[inline(always)] #[inline(always)]
pub fn label(&mut self, label: impl Into<Label>) -> Response { pub fn label(&mut self, text: impl ToString) -> Response {
label.into().ui(self) Label::new(text).ui(self)
} }
/// Show colored text. /// Show colored text.
/// ///
/// Shortcut for `add(Label::new(text).text_color(color))` /// Shortcut for `add(Label::new(text).text_color(color))`
pub fn colored_label( pub fn colored_label(&mut self, color: impl Into<Color32>, text: impl ToString) -> Response {
&mut self, Label::new(text).text_color(color).ui(self)
color: impl Into<Color32>,
label: impl Into<Label>,
) -> Response {
label.into().text_color(color).ui(self)
} }
/// Show large text. /// Show large text.
/// ///
/// 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, text: impl ToString) -> Response {
label.into().heading().ui(self) Label::new(text).heading().ui(self)
} }
/// Show monospace (fixed width) text. /// Show monospace (fixed width) text.
/// ///
/// Shortcut for `add(Label::new(text).monospace())` /// Shortcut for `add(Label::new(text).monospace())`
pub fn monospace(&mut self, label: impl Into<Label>) -> Response { pub fn monospace(&mut self, text: impl ToString) -> Response {
label.into().monospace().ui(self) Label::new(text).monospace().ui(self)
} }
/// Show text as monospace with a gray background. /// Show text as monospace with a gray background.
/// ///
/// Shortcut for `add(Label::new(text).code())` /// Shortcut for `add(Label::new(text).code())`
pub fn code(&mut self, label: impl Into<Label>) -> Response { pub fn code(&mut self, text: impl ToString) -> Response {
label.into().code().ui(self) Label::new(text).code().ui(self)
} }
/// Show small text. /// Show small text.
/// ///
/// Shortcut for `add(Label::new(text).small())` /// Shortcut for `add(Label::new(text).small())`
pub fn small(&mut self, label: impl Into<Label>) -> Response { pub fn small(&mut self, text: impl ToString) -> Response {
label.into().small().ui(self) Label::new(text).small().ui(self)
} }
/// Show text that stand out a bit (e.g. slightly brighter). /// Show text that stand out a bit (e.g. slightly brighter).
/// ///
/// Shortcut for `add(Label::new(text).strong())` /// Shortcut for `add(Label::new(text).strong())`
pub fn strong(&mut self, label: impl Into<Label>) -> Response { pub fn strong(&mut self, text: impl ToString) -> Response {
label.into().strong().ui(self) Label::new(text).strong().ui(self)
} }
/// Shortcut for `add(Hyperlink::new(url))` /// Shortcut for `add(Hyperlink::new(url))`