Skip to content

Commit

Permalink
Add Button::from_label
Browse files Browse the repository at this point in the history
  • Loading branch information
ForLoveOfCats committed Sep 12, 2020
1 parent 9564af6 commit 3f7cc72
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ You can find its changes [documented below](#060---2020-06-01).
- Implementation of `Data` trait for `i128` and `u128` primitive data types. ([#1214] by [@koutoftimer])
- `LineBreaking` enum allows configuration of label line-breaking ([#1195] by [@cmyr])
- `TextAlignment` support in `TextLayout` and `Label` ([#1210] by [@cmyr])`
- `Button::from_label` to construct a `Button` with a provided `Label`. ([#????] by [@ForLoveOfCats])

### Changed

Expand Down
21 changes: 21 additions & 0 deletions druid/src/widget/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,27 @@ impl<T: Data> Button<T> {
}
}

/// Create a new button with the provided label.
///
/// Use the `.on_click` method to provide a closure to be called when the
/// button is clicked.
///
/// # Examples
///
/// ```
/// use druid::widget::Button;
///
/// let button = Button::from_label(Label::new("Increment")).on_click(|_ctx, data: &mut u32, _env| {
/// *data += 1;
/// });
/// ```
pub fn from_label(label: Label<T>) -> Button<T> {
Button {
label,
label_size: Size::ZERO,
}
}

/// Construct a new dynamic button.
///
/// The contents of this button are generated from the data using a closure.
Expand Down

0 comments on commit 3f7cc72

Please sign in to comment.