Derive Clone for RadioGroup

Also remove broken example.
This commit is contained in:
Alexandre Bury 2016-10-02 15:03:03 -07:00
parent bf3888e275
commit 53aea8e91c

View File

@ -23,24 +23,13 @@ impl<T> SharedState<T> {
/// ///
/// A `RadioGroup` is used to create and manage [`RadioButton`]s. /// A `RadioGroup` is used to create and manage [`RadioButton`]s.
/// ///
/// A `RadioGroup` can be cloned; it will keep pointing to the same group.
///
/// [`RadioButton`]: struct.RadioButton.html /// [`RadioButton`]: struct.RadioButton.html
/// #[derive(Clone)]
/// # Examples
///
/// ```
/// let mut group = RadioGroup::new();
///
/// let button_1 = group.button_str(1, "Option 1");
/// let button_2 = group.button_str(2, "Option 2");
/// let button_3 = group.button_str(3, "Option 3");
/// ```
pub struct RadioGroup<T> { pub struct RadioGroup<T> {
// Given to every child button // Given to every child button
state: Rc<RefCell<SharedState<T>>>, state: Rc<RefCell<SharedState<T>>>,
// Count the number of children already created,
// to give an ID to the next child.
count: usize,
} }
impl<T> RadioGroup<T> { impl<T> RadioGroup<T> {
@ -51,7 +40,6 @@ impl<T> RadioGroup<T> {
selection: 0, selection: 0,
values: Vec::new(), values: Vec::new(),
})), })),
count: 0,
} }
} }
@ -60,10 +48,9 @@ impl<T> RadioGroup<T> {
/// The button will display `label` next to it, and will embed `value`. /// The button will display `label` next to it, and will embed `value`.
pub fn button<S: Into<String>>(&mut self, value: T, label: S) pub fn button<S: Into<String>>(&mut self, value: T, label: S)
-> RadioButton<T> { -> RadioButton<T> {
let count = self.state.borrow().values.len();
self.state.borrow_mut().values.push(Rc::new(value)); self.state.borrow_mut().values.push(Rc::new(value));
let result = let result = RadioButton::new(self.state.clone(), count, label.into());
RadioButton::new(self.state.clone(), self.count, label.into());
self.count += 1;
result result
} }