<commit_before>use {Printer, With};
use vec::Vec2;
use view::View;
use theme::ColorStyle;
use event::{Event, EventResult, Key};
use direction::Direction;

use std::cell::RefCell;
use std::rc::Rc;

struct SharedState<T> {
    selection: usize,
    values: Vec<Rc<T>>,
}

impl<T> SharedState<T> {
    pub fn selection(&self) -> Rc<T> {
        self.values[self.selection].clone()
    }
}

/// Group to coordinate multiple radio buttons.
///
/// A `RadioGroup` is used to create and manage [`RadioButton`]s.
///
/// [`RadioButton`]: struct.RadioButton.html
///
/// # 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> {
    // Given to every child button
    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> {
    /// Creates an empty group for radio buttons.
    pub fn new() -> Self {
        RadioGroup {
            state: Rc::new(RefCell::new(SharedState {
                selection: 0,
                values: Vec::new(),
            })),
            count: 0,
        }
    }

    /// Adds a new button to the group.
    ///
    /// The button will display `label` next to it, and will embed `value`.
    pub fn button<S: Into<String>>(&mut self, value: T, label: S)
                                   -> RadioButton<T> {
        self.state.borrow_mut().values.push(Rc::new(value));
        let result =
            RadioButton::new(self.state.clone(), self.count, label.into());
        self.count += 1;<commit_msg>Derive `Clone` for `RadioGroup`<commit_after>use {Printer, With};
use vec::Vec2;
use view::View;
use theme::ColorStyle;
use event::{Event, EventResult, Key};
use direction::Direction;

use std::cell::RefCell;
use std::rc::Rc;

struct SharedState<T> {
    selection: usize,
    values: Vec<Rc<T>>,
}

impl<T> SharedState<T> {
    pub fn selection(&self) -> Rc<T> {
        self.values[self.selection].clone()
    }
}

/// Group to coordinate multiple radio buttons.
///
/// 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
#[derive(Clone)]
pub struct RadioGroup<T> {
    // Given to every child button
    state: Rc<RefCell<SharedState<T>>>,
}

impl<T> RadioGroup<T> {
    /// Creates an empty group for radio buttons.
    pub fn new() -> Self {
        RadioGroup {
            state: Rc::new(RefCell::new(SharedState {
                selection: 0,
                values: Vec::new(),
            })),
        }
    }

    /// Adds a new button to the group.
    ///
    /// The button will display `label` next to it, and will embed `value`.
    pub fn button<S: Into<String>>(&mut self, value: T, label: S)
                                   -> RadioButton<T> {
        let count = self.state.borrow().values.len();
        self.state.borrow_mut().values.push(Rc::new(value));
        let result = RadioButton::new(self.state.clone(), count, label.into());
{'fraction_non_alphanumeric': 0.16481823783117683, 'fraction_numerical': 0.0046210720887245845, 'mean_word_length': 2.4143007360672977, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3349125', 'n_tokens_mistral': 1040, 'n_tokens_neox': 1028, 'n_words': 288}