Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checkbox label is now Into<String> #260

Merged
merged 3 commits into from
Apr 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions examples/tour/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ impl<'a> Step {
|choices, language| {
choices.push(Radio::new(
language,
language.into(),
language,
selection,
StepMessage::LanguageSelected,
))
Expand Down Expand Up @@ -729,16 +729,16 @@ impl Language {
}
}

impl From<Language> for &str {
fn from(language: Language) -> &'static str {
match language {
impl From<Language> for String {
fn from(language: Language) -> String {
String::from(match language {
hecrj marked this conversation as resolved.
Show resolved Hide resolved
Language::Rust => "Rust",
Language::Elm => "Elm",
Language::Ruby => "Ruby",
Language::Haskell => "Haskell",
Language::C => "C",
Language::Other => "Other",
}
})
}
}

Expand Down
4 changes: 2 additions & 2 deletions native/src/widget/checkbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ impl<Message, Renderer: self::Renderer + text::Renderer>
/// `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: Box::new(f),
label: String::from(label),
label: label.into(),
width: Length::Shrink,
size: <Renderer as self::Renderer>::DEFAULT_SIZE,
spacing: Renderer::DEFAULT_SPACING,
Expand Down
9 changes: 7 additions & 2 deletions native/src/widget/radio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,20 @@ impl<Message, Renderer: self::Renderer> Radio<Message, Renderer> {
/// 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,
{
Radio {
is_selected: Some(value) == selected,
on_click: f(value),
label: String::from(label),
label: label.into(),
style: Renderer::Style::default(),
}
}
Expand Down