From f7825fd93620c1c1a8d26aa81337da4df24b49a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Tue, 14 Apr 2020 07:41:35 +0200 Subject: [PATCH] Fix `Checkbox` and `Radio` API in `iced_web` --- examples/tour/src/main.rs | 2 +- web/src/widget/checkbox.rs | 4 ++-- web/src/widget/radio.rs | 9 +++++++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/examples/tour/src/main.rs b/examples/tour/src/main.rs index 918238b6..c9678b9d 100644 --- a/examples/tour/src/main.rs +++ b/examples/tour/src/main.rs @@ -530,7 +530,7 @@ impl<'a> Step { |choices, language| { choices.push(Radio::new( language, - &String::from(language), + language, selection, StepMessage::LanguageSelected, )) diff --git a/web/src/widget/checkbox.rs b/web/src/widget/checkbox.rs index 0657ccfb..5ebc26c8 100644 --- a/web/src/widget/checkbox.rs +++ b/web/src/widget/checkbox.rs @@ -43,14 +43,14 @@ impl Checkbox { /// `Message`. /// /// [`Checkbox`]: struct.Checkbox.html - pub fn new(is_checked: bool, label: &str, f: F) -> Self + pub fn new(is_checked: bool, label: impl Into, f: F) -> Self where F: 'static + Fn(bool) -> Message, { Checkbox { is_checked, on_toggle: Rc::new(f), - label: String::from(label), + label: label.into(), width: Length::Shrink, style: Default::default(), } diff --git a/web/src/widget/radio.rs b/web/src/widget/radio.rs index e00e26db..520b24cd 100644 --- a/web/src/widget/radio.rs +++ b/web/src/widget/radio.rs @@ -49,7 +49,12 @@ impl Radio { /// receives the value of the radio and must produce a `Message`. /// /// [`Radio`]: struct.Radio.html - pub fn new(value: V, label: &str, selected: Option, f: F) -> Self + pub fn new( + value: V, + label: impl Into, + selected: Option, + f: F, + ) -> Self where V: Eq + Copy, F: 'static + Fn(V) -> Message, @@ -57,7 +62,7 @@ impl Radio { Radio { is_selected: Some(value) == selected, on_click: f(value), - label: String::from(label), + label: label.into(), style: Default::default(), } }