Merge pull request #260 from 0x7CFE/fix-checkbox-label

Checkbox label is now `Into<String>`
This commit is contained in:
Héctor Ramón 2020-04-06 20:31:39 +02:00 committed by GitHub
commit 0f60253661
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 9 deletions

View File

@ -530,7 +530,7 @@ impl<'a> Step {
|choices, language| { |choices, language| {
choices.push(Radio::new( choices.push(Radio::new(
language, language,
language.into(), language,
selection, selection,
StepMessage::LanguageSelected, StepMessage::LanguageSelected,
)) ))
@ -729,16 +729,16 @@ impl Language {
} }
} }
impl From<Language> for &str { impl From<Language> for String {
fn from(language: Language) -> &'static str { fn from(language: Language) -> String {
match language { String::from(match language {
Language::Rust => "Rust", Language::Rust => "Rust",
Language::Elm => "Elm", Language::Elm => "Elm",
Language::Ruby => "Ruby", Language::Ruby => "Ruby",
Language::Haskell => "Haskell", Language::Haskell => "Haskell",
Language::C => "C", Language::C => "C",
Language::Other => "Other", Language::Other => "Other",
} })
} }
} }

View File

@ -50,14 +50,14 @@ impl<Message, Renderer: self::Renderer + text::Renderer>
/// `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: Box::new(f), on_toggle: Box::new(f),
label: String::from(label), label: label.into(),
width: Length::Shrink, width: Length::Shrink,
size: <Renderer as self::Renderer>::DEFAULT_SIZE, size: <Renderer as self::Renderer>::DEFAULT_SIZE,
spacing: Renderer::DEFAULT_SPACING, spacing: Renderer::DEFAULT_SPACING,

View File

@ -53,7 +53,12 @@ impl<Message, Renderer: self::Renderer> Radio<Message, Renderer> {
/// 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,
@ -61,7 +66,7 @@ impl<Message, Renderer: self::Renderer> Radio<Message, Renderer> {
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: Renderer::Style::default(), style: Renderer::Style::default(),
} }
} }