Replace impl Into<String>
with impl ToString
(#302)
* Replace `impl Into<String>` with `impl ToString` This is something I ran into today. Types that implement `std::fmt::Display` cannot be passed to functions that take `impl Into<String>`. You have to call `display_thing.to_string()`. Its a small thing but would be fixed by instead taking `impl ToString`. Afaik `impl ToString` is a superset of `impl Into<String>`, unless users manually implement `Into<String> for T` (or `From<T> for String`) for their own types. However I think its more common to implement `Display` as that works with `println` and friends. The main difference is that `Display::fmt` can return errors but thats also quite rare in my experience. I did some testing in a [playground] and seems to work. [playground]: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=1111e071f6ae416ae2688d58d2e9b575 * Silence warnings
This commit is contained in:
parent
e991a1c310
commit
02a62d1986
17 changed files with 97 additions and 73 deletions
|
@ -148,7 +148,7 @@ impl CollapsingHeader {
|
||||||
/// If the label is unique and static this is fine,
|
/// If the label is unique and static this is fine,
|
||||||
/// but if it changes or there are several `CollapsingHeader` with the same title
|
/// but if it changes or there are several `CollapsingHeader` with the same title
|
||||||
/// you need to provide a unique id source with [`Self::id_source`].
|
/// you need to provide a unique id source with [`Self::id_source`].
|
||||||
pub fn new(label: impl Into<String>) -> Self {
|
pub fn new(label: impl ToString) -> Self {
|
||||||
let label = Label::new(label).text_style(TextStyle::Button).wrap(false);
|
let label = Label::new(label).text_style(TextStyle::Button).wrap(false);
|
||||||
let id_source = Id::new(label.text());
|
let id_source = Id::new(label.text());
|
||||||
Self {
|
Self {
|
||||||
|
|
|
@ -55,8 +55,9 @@ impl ComboBox {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// What we show as the currently selected value
|
/// What we show as the currently selected value
|
||||||
pub fn selected_text(mut self, selected_text: impl Into<String>) -> Self {
|
#[allow(clippy::needless_pass_by_value)]
|
||||||
self.selected_text = selected_text.into();
|
pub fn selected_text(mut self, selected_text: impl ToString) -> Self {
|
||||||
|
self.selected_text = selected_text.to_string();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,7 +151,7 @@ impl ComboBox {
|
||||||
pub fn combo_box_with_label(
|
pub fn combo_box_with_label(
|
||||||
ui: &mut Ui,
|
ui: &mut Ui,
|
||||||
label: impl Into<Label>,
|
label: impl Into<Label>,
|
||||||
selected: impl Into<String>,
|
selected: impl ToString,
|
||||||
menu_contents: impl FnOnce(&mut Ui),
|
menu_contents: impl FnOnce(&mut Ui),
|
||||||
) -> Response {
|
) -> Response {
|
||||||
let label = label.into();
|
let label = label.into();
|
||||||
|
@ -165,10 +166,11 @@ pub fn combo_box_with_label(
|
||||||
.inner
|
.inner
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::needless_pass_by_value)]
|
||||||
fn combo_box(
|
fn combo_box(
|
||||||
ui: &mut Ui,
|
ui: &mut Ui,
|
||||||
button_id: Id,
|
button_id: Id,
|
||||||
selected: impl Into<String>,
|
selected: impl ToString,
|
||||||
menu_contents: impl FnOnce(&mut Ui),
|
menu_contents: impl FnOnce(&mut Ui),
|
||||||
) -> Response {
|
) -> Response {
|
||||||
let popup_id = button_id.with("popup");
|
let popup_id = button_id.with("popup");
|
||||||
|
@ -181,7 +183,7 @@ fn combo_box(
|
||||||
|
|
||||||
let galley = ui
|
let galley = ui
|
||||||
.fonts()
|
.fonts()
|
||||||
.layout_no_wrap(TextStyle::Button, selected.into());
|
.layout_no_wrap(TextStyle::Button, selected.to_string());
|
||||||
|
|
||||||
let width = galley.size.x + ui.spacing().item_spacing.x + icon_size.x;
|
let width = galley.size.x + ui.spacing().item_spacing.x + icon_size.x;
|
||||||
let width = width.at_least(full_minimum_width);
|
let width = width.at_least(full_minimum_width);
|
||||||
|
|
|
@ -122,7 +122,7 @@ pub fn show_tooltip_at(
|
||||||
/// egui::show_tooltip_text(ui.ctx(), egui::Id::new("my_tooltip"), "Helpful text");
|
/// egui::show_tooltip_text(ui.ctx(), egui::Id::new("my_tooltip"), "Helpful text");
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
pub fn show_tooltip_text(ctx: &CtxRef, id: Id, text: impl Into<String>) {
|
pub fn show_tooltip_text(ctx: &CtxRef, id: Id, text: impl ToString) {
|
||||||
show_tooltip(ctx, id, |ui| {
|
show_tooltip(ctx, id, |ui| {
|
||||||
ui.add(crate::widgets::Label::new(text));
|
ui.add(crate::widgets::Label::new(text));
|
||||||
})
|
})
|
||||||
|
|
|
@ -36,8 +36,9 @@ impl<'open> Window<'open> {
|
||||||
/// The window title is used as a unique [`Id`] and must be unique, and should not change.
|
/// The window title is used as a unique [`Id`] and must be unique, and should not change.
|
||||||
/// This is true even if you disable the title bar with `.title_bar(false)`.
|
/// This is true even if you disable the title bar with `.title_bar(false)`.
|
||||||
/// If you need a changing title, you must call `window.id(…)` with a fixed id.
|
/// If you need a changing title, you must call `window.id(…)` with a fixed id.
|
||||||
pub fn new(title: impl Into<String>) -> Self {
|
#[allow(clippy::needless_pass_by_value)]
|
||||||
let title = title.into();
|
pub fn new(title: impl ToString) -> Self {
|
||||||
|
let title = title.to_string();
|
||||||
let area = Area::new(&title);
|
let area = Area::new(&title);
|
||||||
let title_label = Label::new(title).text_style(TextStyle::Heading).wrap(false);
|
let title_label = Label::new(title).text_style(TextStyle::Heading).wrap(false);
|
||||||
Self {
|
Self {
|
||||||
|
|
|
@ -31,7 +31,7 @@ pub struct Output {
|
||||||
impl Output {
|
impl Output {
|
||||||
/// Open the given url in a web browser.
|
/// Open the given url in a web browser.
|
||||||
/// If egui is running in a browser, the same tab will be reused.
|
/// If egui is running in a browser, the same tab will be reused.
|
||||||
pub fn open_url(&mut self, url: impl Into<String>) {
|
pub fn open_url(&mut self, url: impl ToString) {
|
||||||
self.open_url = Some(OpenUrl::same_tab(url))
|
self.open_url = Some(OpenUrl::same_tab(url))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,16 +59,18 @@ pub struct OpenUrl {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl OpenUrl {
|
impl OpenUrl {
|
||||||
pub fn same_tab(url: impl Into<String>) -> Self {
|
#[allow(clippy::needless_pass_by_value)]
|
||||||
|
pub fn same_tab(url: impl ToString) -> Self {
|
||||||
Self {
|
Self {
|
||||||
url: url.into(),
|
url: url.to_string(),
|
||||||
new_tab: false,
|
new_tab: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_tab(url: impl Into<String>) -> Self {
|
#[allow(clippy::needless_pass_by_value)]
|
||||||
|
pub fn new_tab(url: impl ToString) -> Self {
|
||||||
Self {
|
Self {
|
||||||
url: url.into(),
|
url: url.to_string(),
|
||||||
new_tab: true,
|
new_tab: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -279,17 +281,19 @@ impl WidgetInfo {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn labeled(typ: WidgetType, label: impl Into<String>) -> Self {
|
#[allow(clippy::needless_pass_by_value)]
|
||||||
|
pub fn labeled(typ: WidgetType, label: impl ToString) -> Self {
|
||||||
Self {
|
Self {
|
||||||
label: Some(label.into()),
|
label: Some(label.to_string()),
|
||||||
..Self::new(typ)
|
..Self::new(typ)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// checkboxes, radio-buttons etc
|
/// checkboxes, radio-buttons etc
|
||||||
pub fn selected(typ: WidgetType, selected: bool, label: impl Into<String>) -> Self {
|
#[allow(clippy::needless_pass_by_value)]
|
||||||
|
pub fn selected(typ: WidgetType, selected: bool, label: impl ToString) -> Self {
|
||||||
Self {
|
Self {
|
||||||
label: Some(label.into()),
|
label: Some(label.to_string()),
|
||||||
selected: Some(selected),
|
selected: Some(selected),
|
||||||
..Self::new(typ)
|
..Self::new(typ)
|
||||||
}
|
}
|
||||||
|
@ -302,8 +306,9 @@ impl WidgetInfo {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn slider(value: f64, label: impl Into<String>) -> Self {
|
#[allow(clippy::needless_pass_by_value)]
|
||||||
let label = label.into();
|
pub fn slider(value: f64, label: impl ToString) -> Self {
|
||||||
|
let label = label.to_string();
|
||||||
Self {
|
Self {
|
||||||
label: if label.is_empty() { None } else { Some(label) },
|
label: if label.is_empty() { None } else { Some(label) },
|
||||||
value: Some(value),
|
value: Some(value),
|
||||||
|
@ -311,9 +316,10 @@ impl WidgetInfo {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn text_edit(edit_text: impl Into<String>) -> Self {
|
#[allow(clippy::needless_pass_by_value)]
|
||||||
|
pub fn text_edit(edit_text: impl ToString) -> Self {
|
||||||
Self {
|
Self {
|
||||||
edit_text: Some(edit_text.into()),
|
edit_text: Some(edit_text.to_string()),
|
||||||
..Self::new(WidgetType::TextEdit)
|
..Self::new(WidgetType::TextEdit)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,16 +60,13 @@ pub fn bar<R>(ui: &mut Ui, add_contents: impl FnOnce(&mut Ui) -> R) -> InnerResp
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Construct a top level menu in a menu bar. This would be e.g. "File", "Edit" etc.
|
/// Construct a top level menu in a menu bar. This would be e.g. "File", "Edit" etc.
|
||||||
pub fn menu(ui: &mut Ui, title: impl Into<String>, add_contents: impl FnOnce(&mut Ui)) {
|
pub fn menu(ui: &mut Ui, title: impl ToString, add_contents: impl FnOnce(&mut Ui)) {
|
||||||
menu_impl(ui, title, Box::new(add_contents))
|
menu_impl(ui, title, Box::new(add_contents))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn menu_impl<'c>(
|
#[allow(clippy::needless_pass_by_value)]
|
||||||
ui: &mut Ui,
|
fn menu_impl<'c>(ui: &mut Ui, title: impl ToString, add_contents: Box<dyn FnOnce(&mut Ui) + 'c>) {
|
||||||
title: impl Into<String>,
|
let title = title.to_string();
|
||||||
add_contents: Box<dyn FnOnce(&mut Ui) + 'c>,
|
|
||||||
) {
|
|
||||||
let title = title.into();
|
|
||||||
let bar_id = ui.id();
|
let bar_id = ui.id();
|
||||||
let menu_id = bar_id.with(&title);
|
let menu_id = bar_id.with(&title);
|
||||||
|
|
||||||
|
|
|
@ -173,10 +173,17 @@ impl Painter {
|
||||||
|
|
||||||
/// ## Debug painting
|
/// ## Debug painting
|
||||||
impl Painter {
|
impl Painter {
|
||||||
pub fn debug_rect(&mut self, rect: Rect, color: Color32, text: impl Into<String>) {
|
#[allow(clippy::needless_pass_by_value)]
|
||||||
|
pub fn debug_rect(&mut self, rect: Rect, color: Color32, text: impl ToString) {
|
||||||
self.rect_stroke(rect, 0.0, (1.0, color));
|
self.rect_stroke(rect, 0.0, (1.0, color));
|
||||||
let text_style = TextStyle::Monospace;
|
let text_style = TextStyle::Monospace;
|
||||||
self.text(rect.min, Align2::LEFT_TOP, text.into(), text_style, color);
|
self.text(
|
||||||
|
rect.min,
|
||||||
|
Align2::LEFT_TOP,
|
||||||
|
text.to_string(),
|
||||||
|
text_style,
|
||||||
|
color,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn error(&self, pos: Pos2, text: impl std::fmt::Display) -> Rect {
|
pub fn error(&self, pos: Pos2, text: impl std::fmt::Display) -> Rect {
|
||||||
|
@ -293,17 +300,18 @@ impl Painter {
|
||||||
/// To center the text at the given position, use `anchor: (Center, Center)`.
|
/// To center the text at the given position, use `anchor: (Center, Center)`.
|
||||||
///
|
///
|
||||||
/// Returns where the text ended up.
|
/// Returns where the text ended up.
|
||||||
|
#[allow(clippy::needless_pass_by_value)]
|
||||||
pub fn text(
|
pub fn text(
|
||||||
&self,
|
&self,
|
||||||
pos: Pos2,
|
pos: Pos2,
|
||||||
anchor: Align2,
|
anchor: Align2,
|
||||||
text: impl Into<String>,
|
text: impl ToString,
|
||||||
text_style: TextStyle,
|
text_style: TextStyle,
|
||||||
text_color: Color32,
|
text_color: Color32,
|
||||||
) -> Rect {
|
) -> Rect {
|
||||||
let galley = self
|
let galley = self
|
||||||
.fonts()
|
.fonts()
|
||||||
.layout_multiline(text_style, text.into(), f32::INFINITY);
|
.layout_multiline(text_style, text.to_string(), f32::INFINITY);
|
||||||
let rect = anchor.anchor_rect(Rect::from_min_size(pos, galley.size));
|
let rect = anchor.anchor_rect(Rect::from_min_size(pos, galley.size));
|
||||||
self.galley(rect.min, galley, text_color);
|
self.galley(rect.min, galley, text_color);
|
||||||
rect
|
rect
|
||||||
|
|
|
@ -356,21 +356,21 @@ impl Response {
|
||||||
///
|
///
|
||||||
/// The text will not be visible if the widget is not enabled.
|
/// The text will not be visible if the widget is not enabled.
|
||||||
/// If you call this multiple times the tooltips will stack underneath the previous ones.
|
/// If you call this multiple times the tooltips will stack underneath the previous ones.
|
||||||
pub fn on_hover_text(self, text: impl Into<String>) -> Self {
|
pub fn on_hover_text(self, text: impl ToString) -> Self {
|
||||||
self.on_hover_ui(|ui| {
|
self.on_hover_ui(|ui| {
|
||||||
ui.add(crate::widgets::Label::new(text));
|
ui.add(crate::widgets::Label::new(text));
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Show this text when hovering if the widget is disabled.
|
/// Show this text when hovering if the widget is disabled.
|
||||||
pub fn on_disabled_hover_text(self, text: impl Into<String>) -> Self {
|
pub fn on_disabled_hover_text(self, text: impl ToString) -> Self {
|
||||||
self.on_disabled_hover_ui(|ui| {
|
self.on_disabled_hover_ui(|ui| {
|
||||||
ui.add(crate::widgets::Label::new(text));
|
ui.add(crate::widgets::Label::new(text));
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deprecated = "Deprecated 2020-10-01: use `on_hover_text` instead."]
|
#[deprecated = "Deprecated 2020-10-01: use `on_hover_text` instead."]
|
||||||
pub fn tooltip_text(self, text: impl Into<String>) -> Self {
|
pub fn tooltip_text(self, text: impl ToString) -> Self {
|
||||||
self.on_hover_text(text)
|
self.on_hover_text(text)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -899,7 +899,7 @@ impl Ui {
|
||||||
/// Shortcut for `add(Hyperlink::new(url))`
|
/// Shortcut for `add(Hyperlink::new(url))`
|
||||||
///
|
///
|
||||||
/// See also [`Hyperlink`].
|
/// See also [`Hyperlink`].
|
||||||
pub fn hyperlink(&mut self, url: impl Into<String>) -> Response {
|
pub fn hyperlink(&mut self, url: impl ToString) -> Response {
|
||||||
Hyperlink::new(url).ui(self)
|
Hyperlink::new(url).ui(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -911,7 +911,7 @@ impl Ui {
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// See also [`Hyperlink`].
|
/// See also [`Hyperlink`].
|
||||||
pub fn hyperlink_to(&mut self, label: impl Into<String>, url: impl Into<String>) -> Response {
|
pub fn hyperlink_to(&mut self, label: impl ToString, url: impl ToString) -> Response {
|
||||||
Hyperlink::new(url).text(label).ui(self)
|
Hyperlink::new(url).text(label).ui(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -941,7 +941,7 @@ impl Ui {
|
||||||
/// See also [`Button`].
|
/// See also [`Button`].
|
||||||
#[must_use = "You should check if the user clicked this with `if ui.button(…).clicked() { … } "]
|
#[must_use = "You should check if the user clicked this with `if ui.button(…).clicked() { … } "]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn button(&mut self, text: impl Into<String>) -> Response {
|
pub fn button(&mut self, text: impl ToString) -> Response {
|
||||||
Button::new(text).ui(self)
|
Button::new(text).ui(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -951,19 +951,19 @@ impl Ui {
|
||||||
///
|
///
|
||||||
/// Shortcut for `add(Button::new(text).small())`
|
/// Shortcut for `add(Button::new(text).small())`
|
||||||
#[must_use = "You should check if the user clicked this with `if ui.small_button(…).clicked() { … } "]
|
#[must_use = "You should check if the user clicked this with `if ui.small_button(…).clicked() { … } "]
|
||||||
pub fn small_button(&mut self, text: impl Into<String>) -> Response {
|
pub fn small_button(&mut self, text: impl ToString) -> Response {
|
||||||
Button::new(text).small().ui(self)
|
Button::new(text).small().ui(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Show a checkbox.
|
/// Show a checkbox.
|
||||||
pub fn checkbox(&mut self, checked: &mut bool, text: impl Into<String>) -> Response {
|
pub fn checkbox(&mut self, checked: &mut bool, text: impl ToString) -> Response {
|
||||||
Checkbox::new(checked, text).ui(self)
|
Checkbox::new(checked, text).ui(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Show a [`RadioButton`].
|
/// Show a [`RadioButton`].
|
||||||
/// Often you want to use [`Self::radio_value`] instead.
|
/// Often you want to use [`Self::radio_value`] instead.
|
||||||
#[must_use = "You should check if the user clicked this with `if ui.radio(…).clicked() { … } "]
|
#[must_use = "You should check if the user clicked this with `if ui.radio(…).clicked() { … } "]
|
||||||
pub fn radio(&mut self, selected: bool, text: impl Into<String>) -> Response {
|
pub fn radio(&mut self, selected: bool, text: impl ToString) -> Response {
|
||||||
RadioButton::new(selected, text).ui(self)
|
RadioButton::new(selected, text).ui(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -988,7 +988,7 @@ impl Ui {
|
||||||
&mut self,
|
&mut self,
|
||||||
current_value: &mut Value,
|
current_value: &mut Value,
|
||||||
selected_value: Value,
|
selected_value: Value,
|
||||||
text: impl Into<String>,
|
text: impl ToString,
|
||||||
) -> Response {
|
) -> Response {
|
||||||
let mut response = self.radio(*current_value == selected_value, text);
|
let mut response = self.radio(*current_value == selected_value, text);
|
||||||
if response.clicked() {
|
if response.clicked() {
|
||||||
|
@ -1002,7 +1002,7 @@ impl Ui {
|
||||||
///
|
///
|
||||||
/// See also [`SelectableLabel`].
|
/// See also [`SelectableLabel`].
|
||||||
#[must_use = "You should check if the user clicked this with `if ui.selectable_label(…).clicked() { … } "]
|
#[must_use = "You should check if the user clicked this with `if ui.selectable_label(…).clicked() { … } "]
|
||||||
pub fn selectable_label(&mut self, checked: bool, text: impl Into<String>) -> Response {
|
pub fn selectable_label(&mut self, checked: bool, text: impl ToString) -> Response {
|
||||||
SelectableLabel::new(checked, text).ui(self)
|
SelectableLabel::new(checked, text).ui(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1016,7 +1016,7 @@ impl Ui {
|
||||||
&mut self,
|
&mut self,
|
||||||
current_value: &mut Value,
|
current_value: &mut Value,
|
||||||
selected_value: Value,
|
selected_value: Value,
|
||||||
text: impl Into<String>,
|
text: impl ToString,
|
||||||
) -> Response {
|
) -> Response {
|
||||||
let mut response = self.selectable_label(*current_value == selected_value, text);
|
let mut response = self.selectable_label(*current_value == selected_value, text);
|
||||||
if response.clicked() {
|
if response.clicked() {
|
||||||
|
@ -1212,7 +1212,7 @@ impl Ui {
|
||||||
/// A [`CollapsingHeader`] that starts out collapsed.
|
/// A [`CollapsingHeader`] that starts out collapsed.
|
||||||
pub fn collapsing<R>(
|
pub fn collapsing<R>(
|
||||||
&mut self,
|
&mut self,
|
||||||
heading: impl Into<String>,
|
heading: impl ToString,
|
||||||
add_contents: impl FnOnce(&mut Ui) -> R,
|
add_contents: impl FnOnce(&mut Ui) -> R,
|
||||||
) -> CollapsingResponse<R> {
|
) -> CollapsingResponse<R> {
|
||||||
CollapsingHeader::new(heading).show(self, add_contents)
|
CollapsingHeader::new(heading).show(self, add_contents)
|
||||||
|
|
|
@ -26,9 +26,10 @@ pub struct Button {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Button {
|
impl Button {
|
||||||
pub fn new(text: impl Into<String>) -> Self {
|
#[allow(clippy::needless_pass_by_value)]
|
||||||
|
pub fn new(text: impl ToString) -> Self {
|
||||||
Self {
|
Self {
|
||||||
text: text.into(),
|
text: text.to_string(),
|
||||||
text_color: None,
|
text_color: None,
|
||||||
text_style: TextStyle::Button,
|
text_style: TextStyle::Button,
|
||||||
fill: Default::default(),
|
fill: Default::default(),
|
||||||
|
@ -211,10 +212,11 @@ pub struct Checkbox<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Checkbox<'a> {
|
impl<'a> Checkbox<'a> {
|
||||||
pub fn new(checked: &'a mut bool, text: impl Into<String>) -> Self {
|
#[allow(clippy::needless_pass_by_value)]
|
||||||
|
pub fn new(checked: &'a mut bool, text: impl ToString) -> Self {
|
||||||
Checkbox {
|
Checkbox {
|
||||||
checked,
|
checked,
|
||||||
text: text.into(),
|
text: text.to_string(),
|
||||||
text_color: None,
|
text_color: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -321,10 +323,11 @@ pub struct RadioButton {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RadioButton {
|
impl RadioButton {
|
||||||
pub fn new(checked: bool, text: impl Into<String>) -> Self {
|
#[allow(clippy::needless_pass_by_value)]
|
||||||
|
pub fn new(checked: bool, text: impl ToString) -> Self {
|
||||||
Self {
|
Self {
|
||||||
checked,
|
checked,
|
||||||
text: text.into(),
|
text: text.to_string(),
|
||||||
text_color: None,
|
text_color: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,24 +16,27 @@ pub struct Hyperlink {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Hyperlink {
|
impl Hyperlink {
|
||||||
pub fn new(url: impl Into<String>) -> Self {
|
#[allow(clippy::needless_pass_by_value)]
|
||||||
let url = url.into();
|
pub fn new(url: impl ToString) -> Self {
|
||||||
|
let url = url.to_string();
|
||||||
Self {
|
Self {
|
||||||
url: url.clone(),
|
url: url.clone(),
|
||||||
label: Label::new(url),
|
label: Label::new(url),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_label_and_url(label: impl Into<Label>, url: impl Into<String>) -> Self {
|
#[allow(clippy::needless_pass_by_value)]
|
||||||
|
pub fn from_label_and_url(label: impl Into<Label>, url: impl ToString) -> Self {
|
||||||
Self {
|
Self {
|
||||||
url: url.into(),
|
url: url.to_string(),
|
||||||
label: label.into(),
|
label: label.into(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Show some other text than the url
|
/// Show some other text than the url
|
||||||
pub fn text(mut self, text: impl Into<String>) -> Self {
|
#[allow(clippy::needless_pass_by_value)]
|
||||||
self.label.text = text.into();
|
pub fn text(mut self, text: impl ToString) -> Self {
|
||||||
|
self.label.text = text.to_string();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,9 +29,10 @@ pub struct Label {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Label {
|
impl Label {
|
||||||
pub fn new(text: impl Into<String>) -> Self {
|
#[allow(clippy::needless_pass_by_value)]
|
||||||
|
pub fn new(text: impl ToString) -> Self {
|
||||||
Self {
|
Self {
|
||||||
text: text.into(),
|
text: text.to_string(),
|
||||||
wrap: None,
|
wrap: None,
|
||||||
text_style: None,
|
text_style: None,
|
||||||
background_color: Color32::TRANSPARENT,
|
background_color: Color32::TRANSPARENT,
|
||||||
|
|
|
@ -28,10 +28,11 @@ pub struct SelectableLabel {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SelectableLabel {
|
impl SelectableLabel {
|
||||||
pub fn new(selected: bool, text: impl Into<String>) -> Self {
|
#[allow(clippy::needless_pass_by_value)]
|
||||||
|
pub fn new(selected: bool, text: impl ToString) -> Self {
|
||||||
Self {
|
Self {
|
||||||
selected,
|
selected,
|
||||||
text: text.into(),
|
text: text.to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -174,8 +174,8 @@ impl<'a> Slider<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Show a text next to the slider (e.g. explaining what the slider controls).
|
/// Show a text next to the slider (e.g. explaining what the slider controls).
|
||||||
pub fn text(mut self, text: impl Into<String>) -> Self {
|
pub fn text(mut self, text: impl ToString) -> Self {
|
||||||
self.text = text.into();
|
self.text = text.to_string();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -204,8 +204,9 @@ impl<'t> TextEdit<'t> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Show a faint hint text when the text field is empty.
|
/// Show a faint hint text when the text field is empty.
|
||||||
pub fn hint_text(mut self, hint_text: impl Into<String>) -> Self {
|
#[allow(clippy::needless_pass_by_value)]
|
||||||
self.hint_text = hint_text.into();
|
pub fn hint_text(mut self, hint_text: impl ToString) -> Self {
|
||||||
|
self.hint_text = hint_text.to_string();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -124,15 +124,16 @@ impl Shape {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::needless_pass_by_value)]
|
||||||
pub fn text(
|
pub fn text(
|
||||||
fonts: &Fonts,
|
fonts: &Fonts,
|
||||||
pos: Pos2,
|
pos: Pos2,
|
||||||
anchor: Align2,
|
anchor: Align2,
|
||||||
text: impl Into<String>,
|
text: impl ToString,
|
||||||
text_style: TextStyle,
|
text_style: TextStyle,
|
||||||
color: Color32,
|
color: Color32,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let galley = fonts.layout_multiline(text_style, text.into(), f32::INFINITY);
|
let galley = fonts.layout_multiline(text_style, text.to_string(), f32::INFINITY);
|
||||||
let rect = anchor.anchor_rect(Rect::from_min_size(pos, galley.size));
|
let rect = anchor.anchor_rect(Rect::from_min_size(pos, galley.size));
|
||||||
Self::Text {
|
Self::Text {
|
||||||
pos: rect.min,
|
pos: rect.min,
|
||||||
|
|
|
@ -340,20 +340,20 @@ pub mod http {
|
||||||
|
|
||||||
impl Request {
|
impl Request {
|
||||||
/// Create a `GET` requests with the given url.
|
/// Create a `GET` requests with the given url.
|
||||||
pub fn get(url: impl Into<String>) -> Self {
|
pub fn get(url: impl ToString) -> Self {
|
||||||
Self {
|
Self {
|
||||||
method: "GET".to_owned(),
|
method: "GET".to_owned(),
|
||||||
url: url.into(),
|
url: url.to_string(),
|
||||||
body: "".to_string(),
|
body: "".to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a `POST` requests with the give url and body.
|
/// Create a `POST` requests with the give url and body.
|
||||||
pub fn post(url: impl Into<String>, body: impl Into<String>) -> Self {
|
pub fn post(url: impl ToString, body: impl ToString) -> Self {
|
||||||
Self {
|
Self {
|
||||||
method: "POST".to_owned(),
|
method: "POST".to_owned(),
|
||||||
url: url.into(),
|
url: url.to_string(),
|
||||||
body: body.into(),
|
body: body.to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue