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.push(Radio::new(
language,
&String::from(language),
language,
selection,
StepMessage::LanguageSelected,
))

View File

@ -43,14 +43,14 @@ impl<Message> Checkbox<Message> {
/// `Message`.
///
/// [`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
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(),
}

View File

@ -49,7 +49,12 @@ impl<Message> Radio<Message> {
/// receives the value of the radio and must produce a `Message`.
///
/// [`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
V: Eq + Copy,
F: 'static + Fn(V) -> Message,
@ -57,7 +62,7 @@ impl<Message> Radio<Message> {
Radio {
is_selected: Some(value) == selected,
on_click: f(value),
label: String::from(label),
label: label.into(),
style: Default::default(),
}
}