Add chainable variant of on_change

This commit is contained in:
Alexander Gavrilov 2018-11-30 15:44:56 -08:00
parent 8ea55a69a0
commit fcfca86a36

View File

@ -81,6 +81,15 @@ impl<T: 'static> RadioGroup<T> {
) {
self.state.borrow_mut().on_change = Some(Rc::new(on_change));
}
/// Sets a callback to be used when the selection changes.
///
/// Chainable variant.
pub fn on_change<F: 'static + Fn(&mut Cursive, &T)>(
self, on_change: F,
) -> Self {
self.with(|s| s.set_on_change(on_change))
}
}
impl RadioGroup<String> {
@ -148,6 +157,7 @@ impl<T: 'static> RadioButton<T> {
/// Chainable variant.
pub fn selected(self) -> Self {
self.with(|s| {
// Ignore the potential callback here
s.select();
})
}