diff options
Diffstat (limited to 'views/examples/radio_button_example.cc')
-rw-r--r-- | views/examples/radio_button_example.cc | 33 |
1 files changed, 14 insertions, 19 deletions
diff --git a/views/examples/radio_button_example.cc b/views/examples/radio_button_example.cc index 546a0ee..27d8fa1 100644 --- a/views/examples/radio_button_example.cc +++ b/views/examples/radio_button_example.cc @@ -25,17 +25,16 @@ void RadioButtonExample::CreateExampleView(views::View* container) { select_ = new views::TextButton(this, L"Select"); status_ = new views::TextButton(this, L"Show Status"); - int group = 1; - for (int i = 0; i < arraysize(radio_buttons_); ++i) { - radio_buttons_[i] = new views::RadioButton( - base::StringPrintf( L"Radio %d in group %d", i + 1, group), group); - } + int all = arraysize(radio_buttons_); - ++group; - for (int i = 0; i < arraysize(radio_buttons_nt_); ++i) { - radio_buttons_nt_[i] = new views::RadioButtonNt( - base::StringPrintf( L"Radio %d in group %d", i + 1, group), group); - radio_buttons_nt_[i]->SetFocusable(true); + // divide buttons into 2 groups + int group_count = all / 2; + for (int i = 0; i < all; i++) { + int group = i / group_count; + radio_buttons_[i] = new views::RadioButton( + base::StringPrintf( + L"Radio %d in group %d", (i % group_count + 1), group), + group); } views::GridLayout* layout = new views::GridLayout(container); @@ -44,14 +43,10 @@ void RadioButtonExample::CreateExampleView(views::View* container) { views::ColumnSet* column_set = layout->AddColumnSet(0); column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1.0f, views::GridLayout::USE_PREF, 0, 0); - for (int i = 0; i < arraysize(radio_buttons_); i++) { + for (int i = 0; i < all; i++) { layout->StartRow(0, 0); layout->AddView(radio_buttons_[i]); } - for (int i = 0; i < arraysize(radio_buttons_nt_); i++) { - layout->StartRow(0, 0); - layout->AddView(radio_buttons_nt_[i]); - } layout->StartRow(0, 0); layout->AddView(select_); layout->StartRow(0, 0); @@ -62,16 +57,16 @@ void RadioButtonExample::ButtonPressed(views::Button* sender, const views::Event& event) { if (sender == select_) { radio_buttons_[0]->SetChecked(true); - radio_buttons_nt_[2]->SetChecked(true); + radio_buttons_[5]->SetChecked(true); } else if (sender == status_) { // Show the state of radio buttons. PrintStatus(L"Group1: 1:%ls, 2:%ls, 3:%ls Group2: 1:%ls, 2:%ls, 3:%ls", IntToOnOff(radio_buttons_[0]->checked()), IntToOnOff(radio_buttons_[1]->checked()), IntToOnOff(radio_buttons_[2]->checked()), - IntToOnOff(radio_buttons_nt_[0]->checked()), - IntToOnOff(radio_buttons_nt_[1]->checked()), - IntToOnOff(radio_buttons_nt_[2]->checked())); + IntToOnOff(radio_buttons_[3]->checked()), + IntToOnOff(radio_buttons_[4]->checked()), + IntToOnOff(radio_buttons_[5]->checked())); } } |