diff options
author | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-29 18:19:26 +0000 |
---|---|---|
committer | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-29 18:19:26 +0000 |
commit | ecf100830533911b799a5806d69f1cc0bd5d91e3 (patch) | |
tree | 3f1a5438fa2aa6bde53e7e1a12c7a91b8a75a011 /views/examples | |
parent | 595513ffea29bc07d8b3a087fffe9f84a60ecc6f (diff) | |
download | chromium_src-ecf100830533911b799a5806d69f1cc0bd5d91e3.zip chromium_src-ecf100830533911b799a5806d69f1cc0bd5d91e3.tar.gz chromium_src-ecf100830533911b799a5806d69f1cc0bd5d91e3.tar.bz2 |
Fixed the header file not found issue of 222030. (The file has been renamed after review)
See http://codereview.chromium.org/222030 for the original review
BUG=none
TEST=compiled & tested chrome target on win/linux, view_examples target on linux.
Review URL: http://codereview.chromium.org/242036
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@27513 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/examples')
-rw-r--r-- | views/examples/examples_main_base.cc | 2 | ||||
-rw-r--r-- | views/examples/scroll_view_example.h | 121 |
2 files changed, 123 insertions, 0 deletions
diff --git a/views/examples/examples_main_base.cc b/views/examples/examples_main_base.cc index cd65c2c..b407347 100644 --- a/views/examples/examples_main_base.cc +++ b/views/examples/examples_main_base.cc @@ -18,6 +18,7 @@ #include "views/examples/combobox_example.h" #include "views/examples/message_box_example.h" #include "views/examples/radio_button_example.h" +#include "views/examples/scroll_view_example.h" #include "views/examples/tabbed_pane_example.h" namespace examples { @@ -74,6 +75,7 @@ void ExamplesMainBase::Run() { TabbedPaneExample tabbed_pane_example(tabbed_pane, message); MessageBoxExample message_box_example(tabbed_pane, message); RadioButtonExample radio_button_example(tabbed_pane, message); + ScrollViewExample scroll_view_example(tabbed_pane, message); widget->Show(); diff --git a/views/examples/scroll_view_example.h b/views/examples/scroll_view_example.h new file mode 100644 index 0000000..b032224 --- /dev/null +++ b/views/examples/scroll_view_example.h @@ -0,0 +1,121 @@ +// Copyright (c) 2009 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_SCROLL_BAR_EXAMPLE_H_ +#define VIEWS_EXAMPLES_SCROLL_BAR_EXAMPLE_H_ + +#include "base/string_util.h" +#include "views/controls/button/text_button.h" +#include "views/controls/scroll_view.h" +#include "views/examples/example_base.h" + +namespace examples { + +class ScrollViewExample : protected ExampleBase, private views::ButtonListener { + public: + ScrollViewExample(views::TabbedPane* tabbed_pane, views::Label* message) + : ExampleBase(message), + wide_(new views::TextButton(this, L"Wide")), + tall_(new views::TextButton(this, L"Tall")), + big_square_(new views::TextButton(this, L"Big Square")), + small_square_(new views::TextButton(this, L"Small Square")), + scroll_to_(new views::TextButton(this, L"Scroll to")), + scrollable_(new ScrollableView()), + scroll_view_(new views::ScrollView()) { + scroll_view_->SetContents(scrollable_); + scrollable_->SetBounds(0, 0, 1000, 100); + scrollable_->SetColor(SK_ColorYELLOW, SK_ColorCYAN); + + views::View* container = new views::View(); + tabbed_pane->AddTab(L"Scroll View", container); + + views::GridLayout* layout = new views::GridLayout(container); + container->SetLayoutManager(layout); + + // Add scroll view. + views::ColumnSet* column_set = layout->AddColumnSet(0); + column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, + views::GridLayout::USE_PREF, 0, 0); + layout->StartRow(1, 0); + layout->AddView(scroll_view_); + + // Add control buttons. + column_set = layout->AddColumnSet(1); + for (int i = 0; i < 5; i++) { + column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, + views::GridLayout::USE_PREF, 0, 0); + } + layout->StartRow(0, 1); + layout->AddView(wide_); + layout->AddView(tall_); + layout->AddView(big_square_); + layout->AddView(small_square_); + layout->AddView(scroll_to_); + } + + virtual ~ScrollViewExample() {} + + private: + // ScrollView's content, which draws gradient color on background. + // TODO(oshima): add child views as well. + class ScrollableView : public views::View { + public: + ScrollableView() { + SetColor(SK_ColorRED, SK_ColorCYAN); + } + + gfx::Size GetPreferredSize() { + return gfx::Size(width(), height()); + } + + void SetColor(SkColor from, SkColor to) { + set_background( + views::Background::CreateVerticalGradientBackground(from, to)); + } + + virtual void Layout() { + SizeToPreferredSize(); + } + + private: + DISALLOW_COPY_AND_ASSIGN(ScrollableView); + }; + + // ButtonListner implementation. + virtual void ButtonPressed(views::Button* sender, const views::Event& event) { + if (sender == wide_) { + scrollable_->SetBounds(0, 0, 1000, 100); + scrollable_->SetColor(SK_ColorYELLOW, SK_ColorCYAN); + } else if (sender == tall_) { + scrollable_->SetBounds(0, 0, 100, 1000); + scrollable_->SetColor(SK_ColorRED, SK_ColorCYAN); + } else if (sender == big_square_) { + scrollable_->SetBounds(0, 0, 1000, 1000); + scrollable_->SetColor(SK_ColorRED, SK_ColorGREEN); + } else if (sender == small_square_) { + scrollable_->SetBounds(0, 0, 100, 100); + scrollable_->SetColor(SK_ColorYELLOW, SK_ColorGREEN); + } else if (sender == scroll_to_) { + scroll_view_->ScrollContentsRegionToBeVisible(20, 500, 1000, 500); + } + scroll_view_->Layout(); + } + + // Control buttons to change the size of scrollable and jump to + // predefined position. + views::TextButton* wide_, *tall_, *big_square_, *small_square_, *scroll_to_; + + // The content of the scroll view. + ScrollableView* scrollable_; + + // The scroll view to test. + views::ScrollView* scroll_view_; + + DISALLOW_COPY_AND_ASSIGN(ScrollViewExample); +}; + +} // namespace examples + +#endif // VIEWS_EXAMPLES_SCROLL_BAR_EXAMPLE_H_ + |