| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/views/examples/progress_bar_example.h" | 5 #include "ui/views/examples/progress_bar_example.h" |
| 6 | 6 |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "ui/views/controls/button/text_button.h" | 8 #include "ui/views/controls/button/text_button.h" |
| 9 #include "ui/views/layout/grid_layout.h" | 9 #include "ui/views/layout/grid_layout.h" |
| 10 #include "views/controls/progress_bar.h" | 10 #include "views/controls/progress_bar.h" |
| 11 #include "views/view.h" | 11 #include "views/view.h" |
| 12 | 12 |
| 13 namespace { | 13 namespace { |
| 14 | 14 |
| 15 const double kStepSize = 0.1; | 15 const double kStepSize = 0.1; |
| 16 | 16 |
| 17 double ClampToMin(double percent) { | 17 double ClampToMin(double percent) { |
| 18 return std::min(std::max(percent, 0.0), 1.0); | 18 return std::min(std::max(percent, 0.0), 1.0); |
| 19 } | 19 } |
| 20 | 20 |
| 21 } // namespace | 21 } // namespace |
| 22 | 22 |
| 23 namespace views { |
| 23 namespace examples { | 24 namespace examples { |
| 24 | 25 |
| 25 ProgressBarExample::ProgressBarExample(ExamplesMain* main) | 26 ProgressBarExample::ProgressBarExample() |
| 26 : ExampleBase(main, "Progress Bar"), | 27 : ExampleBase("Progress Bar"), |
| 27 minus_button_(NULL), | 28 minus_button_(NULL), |
| 28 plus_button_(NULL), | 29 plus_button_(NULL), |
| 29 progress_bar_(NULL), | 30 progress_bar_(NULL), |
| 30 current_percent_(0.0) { | 31 current_percent_(0.0) { |
| 31 } | 32 } |
| 32 | 33 |
| 33 ProgressBarExample::~ProgressBarExample() { | 34 ProgressBarExample::~ProgressBarExample() { |
| 34 } | 35 } |
| 35 | 36 |
| 36 void ProgressBarExample::CreateExampleView(views::View* container) { | 37 void ProgressBarExample::CreateExampleView(View* container) { |
| 37 views::GridLayout* layout = new views::GridLayout(container); | 38 GridLayout* layout = new GridLayout(container); |
| 38 container->SetLayoutManager(layout); | 39 container->SetLayoutManager(layout); |
| 39 | 40 |
| 40 views::ColumnSet* column_set = layout->AddColumnSet(0); | 41 ColumnSet* column_set = layout->AddColumnSet(0); |
| 41 column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, | 42 column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, |
| 42 0, views::GridLayout::USE_PREF, 0, 0); | 43 0, GridLayout::USE_PREF, 0, 0); |
| 43 column_set->AddPaddingColumn(0, 8); | 44 column_set->AddPaddingColumn(0, 8); |
| 44 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, | 45 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, |
| 45 1, views::GridLayout::USE_PREF, 0, 0); | 46 1, GridLayout::USE_PREF, 0, 0); |
| 46 column_set->AddPaddingColumn(0, 8); | 47 column_set->AddPaddingColumn(0, 8); |
| 47 column_set->AddColumn(views::GridLayout::TRAILING, views::GridLayout::FILL, | 48 column_set->AddColumn(GridLayout::TRAILING, GridLayout::FILL, |
| 48 0, views::GridLayout::USE_PREF, 0, 0); | 49 0, GridLayout::USE_PREF, 0, 0); |
| 49 | 50 |
| 50 layout->StartRow(0, 0); | 51 layout->StartRow(0, 0); |
| 51 minus_button_ = new views::TextButton(this, ASCIIToUTF16("-")); | 52 minus_button_ = new TextButton(this, ASCIIToUTF16("-")); |
| 52 layout->AddView(minus_button_); | 53 layout->AddView(minus_button_); |
| 53 progress_bar_ = new views::ProgressBar(); | 54 progress_bar_ = new ProgressBar(); |
| 54 layout->AddView(progress_bar_); | 55 layout->AddView(progress_bar_); |
| 55 plus_button_ = new views::TextButton(this, ASCIIToUTF16("+")); | 56 plus_button_ = new TextButton(this, ASCIIToUTF16("+")); |
| 56 layout->AddView(plus_button_); | 57 layout->AddView(plus_button_); |
| 57 } | 58 } |
| 58 | 59 |
| 59 void ProgressBarExample::ButtonPressed(views::Button* sender, | 60 void ProgressBarExample::ButtonPressed(Button* sender, const Event& event) { |
| 60 const views::Event& event) { | |
| 61 if (sender == minus_button_) | 61 if (sender == minus_button_) |
| 62 current_percent_ = ClampToMin(current_percent_ - kStepSize); | 62 current_percent_ = ClampToMin(current_percent_ - kStepSize); |
| 63 else if (sender == plus_button_) | 63 else if (sender == plus_button_) |
| 64 current_percent_ = ClampToMin(current_percent_ + kStepSize); | 64 current_percent_ = ClampToMin(current_percent_ + kStepSize); |
| 65 | 65 |
| 66 progress_bar_->SetValue(current_percent_); | 66 progress_bar_->SetValue(current_percent_); |
| 67 } | 67 } |
| 68 | 68 |
| 69 } // namespace examples | 69 } // namespace examples |
| 70 } // namespace views |
| OLD | NEW |