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