summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--views/examples/examples_main.cc2
-rw-r--r--views/examples/progress_bar_example.cc69
-rw-r--r--views/examples/progress_bar_example.h44
-rw-r--r--views/views.gyp2
4 files changed, 117 insertions, 0 deletions
diff --git a/views/examples/examples_main.cc b/views/examples/examples_main.cc
index 17869d2..d6b4ba6 100644
--- a/views/examples/examples_main.cc
+++ b/views/examples/examples_main.cc
@@ -25,6 +25,7 @@
#include "views/examples/native_theme_button_example.h"
#include "views/examples/native_theme_checkbox_example.h"
#include "views/examples/native_widget_views_example.h"
+#include "views/examples/progress_bar_example.h"
#include "views/examples/radio_button_example.h"
#include "views/examples/scroll_view_example.h"
#include "views/examples/single_split_view_example.h"
@@ -93,6 +94,7 @@ void ExamplesMain::Init() {
examples_.push_back(new NativeThemeButtonExample(this));
examples_.push_back(new NativeThemeCheckboxExample(this));
examples_.push_back(new NativeWidgetViewsExample(this));
+ examples_.push_back(new ProgressBarExample(this));
examples_.push_back(new RadioButtonExample(this));
examples_.push_back(new ScrollViewExample(this));
examples_.push_back(new SingleSplitViewExample(this));
diff --git a/views/examples/progress_bar_example.cc b/views/examples/progress_bar_example.cc
new file mode 100644
index 0000000..91c73d6
--- /dev/null
+++ b/views/examples/progress_bar_example.cc
@@ -0,0 +1,69 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "views/examples/progress_bar_example.h"
+
+#include "base/utf_string_conversions.h"
+#include "views/controls/button/text_button.h"
+#include "views/controls/progress_bar.h"
+#include "views/layout/grid_layout.h"
+#include "views/view.h"
+
+namespace {
+
+const double kStepSize = 0.1;
+
+double ClampToMin(double percent) {
+ return std::min(std::max(percent, 0.0), 1.0);
+}
+
+} // namespace
+
+namespace examples {
+
+ProgressBarExample::ProgressBarExample(ExamplesMain* main)
+ : ExampleBase(main, "Progress Bar"),
+ minus_button_(NULL),
+ plus_button_(NULL),
+ progress_bar_(NULL),
+ current_percent_(0.0) {
+}
+
+ProgressBarExample::~ProgressBarExample() {
+}
+
+void ProgressBarExample::CreateExampleView(views::View* container) {
+ views::GridLayout* layout = new views::GridLayout(container);
+ container->SetLayoutManager(layout);
+
+ views::ColumnSet* column_set = layout->AddColumnSet(0);
+ column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL,
+ 0, views::GridLayout::USE_PREF, 0, 0);
+ column_set->AddPaddingColumn(0, 8);
+ column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL,
+ 1, views::GridLayout::USE_PREF, 0, 0);
+ column_set->AddPaddingColumn(0, 8);
+ column_set->AddColumn(views::GridLayout::TRAILING, views::GridLayout::FILL,
+ 0, views::GridLayout::USE_PREF, 0, 0);
+
+ layout->StartRow(0, 0);
+ minus_button_ = new views::TextButton(this, ASCIIToUTF16("-"));
+ layout->AddView(minus_button_);
+ progress_bar_ = new views::ProgressBar();
+ layout->AddView(progress_bar_);
+ plus_button_ = new views::TextButton(this, ASCIIToUTF16("+"));
+ layout->AddView(plus_button_);
+}
+
+void ProgressBarExample::ButtonPressed(views::Button* sender,
+ const views::Event& event) {
+ if (sender == minus_button_)
+ current_percent_ = ClampToMin(current_percent_ - kStepSize);
+ else if (sender == plus_button_)
+ current_percent_ = ClampToMin(current_percent_ + kStepSize);
+
+ progress_bar_->SetValue(current_percent_);
+}
+
+} // namespace examples
diff --git a/views/examples/progress_bar_example.h b/views/examples/progress_bar_example.h
new file mode 100644
index 0000000..1c30ea1
--- /dev/null
+++ b/views/examples/progress_bar_example.h
@@ -0,0 +1,44 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef VIEWS_EXAMPLES_PROGRESS_BAR_EXAMPLE_H_
+#define VIEWS_EXAMPLES_PROGRESS_BAR_EXAMPLE_H_
+#pragma once
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "views/controls/button/button.h"
+#include "views/examples/example_base.h"
+
+namespace views {
+class ProgressBar;
+}
+
+namespace examples {
+
+class ProgressBarExample : public ExampleBase,
+ public views::ButtonListener {
+ public:
+ explicit ProgressBarExample(ExamplesMain* main);
+ virtual ~ProgressBarExample();
+
+ // Overridden from ExampleBase:
+ virtual void CreateExampleView(views::View* container) OVERRIDE;
+
+ private:
+ // Overridden from views::ButtonListener:
+ virtual void ButtonPressed(views::Button* button,
+ const views::Event& event) OVERRIDE;
+
+ views::Button* minus_button_;
+ views::Button* plus_button_;
+ views::ProgressBar* progress_bar_;
+ double current_percent_;
+
+ DISALLOW_COPY_AND_ASSIGN(ProgressBarExample);
+};
+
+} // namespace examples
+
+#endif // VIEWS_EXAMPLES_PROGRESS_BAR_EXAMPLE_H_
diff --git a/views/views.gyp b/views/views.gyp
index b10b530..650b83e 100644
--- a/views/views.gyp
+++ b/views/views.gyp
@@ -716,6 +716,8 @@
'examples/native_theme_checkbox_example.h',
'examples/native_widget_views_example.cc',
'examples/native_widget_views_example.h',
+ 'examples/progress_bar_example.cc',
+ 'examples/progress_bar_example.h',
'examples/radio_button_example.cc',
'examples/radio_button_example.h',
'examples/scroll_view_example.cc',