Fix Checkbox and Radio API in iced_web

This commit is contained in:
Héctor Ramón Jiménez 2020-04-14 07:41:35 +02:00
parent 67fd107746
commit f7825fd936
3 changed files with 10 additions and 5 deletions

View File

@ -530,7 +530,7 @@ impl<'a> Step {
|choices, language| { |choices, language| {
choices.push(Radio::new( choices.push(Radio::new(
language, language,
&String::from(language), language,
selection, selection,
StepMessage::LanguageSelected, StepMessage::LanguageSelected,
)) ))

View File

@ -43,14 +43,14 @@ impl<Message> Checkbox<Message> {
/// `Message`. /// `Message`.
/// ///
/// [`Checkbox`]: struct.Checkbox.html /// [`Checkbox`]: struct.Checkbox.html
pub fn new<F>(is_checked: bool, label: &str, f: F) -> Self pub fn new<F>(is_checked: bool, label: impl Into<String>, f: F) -> Self
where where
F: 'static + Fn(bool) -> Message, F: 'static + Fn(bool) -> Message,
{ {
Checkbox { Checkbox {
is_checked, is_checked,
on_toggle: Rc::new(f), on_toggle: Rc::new(f),
label: String::from(label), label: label.into(),
width: Length::Shrink, width: Length::Shrink,
style: Default::default(), style: Default::default(),
} }

View File

@ -49,7 +49,12 @@ impl<Message> Radio<Message> {
/// receives the value of the radio and must produce a `Message`. /// receives the value of the radio and must produce a `Message`.
/// ///
/// [`Radio`]: struct.Radio.html /// [`Radio`]: struct.Radio.html
pub fn new<F, V>(value: V, label: &str, selected: Option<V>, f: F) -> Self pub fn new<F, V>(
value: V,
label: impl Into<String>,
selected: Option<V>,
f: F,
) -> Self
where where
V: Eq + Copy, V: Eq + Copy,
F: 'static + Fn(V) -> Message, F: 'static + Fn(V) -> Message,
@ -57,7 +62,7 @@ impl<Message> Radio<Message> {
Radio { Radio {
is_selected: Some(value) == selected, is_selected: Some(value) == selected,
on_click: f(value), on_click: f(value),
label: String::from(label), label: label.into(),
style: Default::default(), style: Default::default(),
} }
} }