OLD | NEW |
1 // Copyright (c) 2010 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 #ifndef VIEWS_EXAMPLES_SINGLE_SPLIT_VIEW_EXAMPLE_H_ | 5 #ifndef VIEWS_EXAMPLES_SINGLE_SPLIT_VIEW_EXAMPLE_H_ |
6 #define VIEWS_EXAMPLES_SINGLE_SPLIT_VIEW_EXAMPLE_H_ | 6 #define VIEWS_EXAMPLES_SINGLE_SPLIT_VIEW_EXAMPLE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "views/controls/single_split_view.h" | 9 #include "views/controls/single_split_view.h" |
10 #include "views/examples/example_base.h" | 10 #include "views/examples/example_base.h" |
11 | 11 |
12 namespace examples { | 12 namespace examples { |
13 | 13 |
14 class SingleSplitViewExample : public ExampleBase { | 14 class SingleSplitViewExample : public ExampleBase { |
15 public: | 15 public: |
16 explicit SingleSplitViewExample(ExamplesMain* main) | 16 explicit SingleSplitViewExample(ExamplesMain* main); |
17 : ExampleBase(main) { | 17 virtual ~SingleSplitViewExample(); |
18 } | |
19 | 18 |
20 virtual ~SingleSplitViewExample() {} | 19 // Overridden from ExampleBase: |
21 | 20 virtual std::wstring GetExampleTitle(); |
22 virtual std::wstring GetExampleTitle() { | 21 virtual void CreateExampleView(views::View* container); |
23 return L"Single Split View"; | |
24 } | |
25 | |
26 virtual void CreateExampleView(views::View* container) { | |
27 SplittedView* splitted_view_1 = new SplittedView(); | |
28 SplittedView* splitted_view_2 = new SplittedView(); | |
29 | |
30 single_split_view_ = new views::SingleSplitView( | |
31 splitted_view_1, splitted_view_2, | |
32 views::SingleSplitView::HORIZONTAL_SPLIT, | |
33 NULL); | |
34 | |
35 splitted_view_1->SetColor(SK_ColorYELLOW, SK_ColorCYAN); | |
36 | |
37 views::GridLayout* layout = new views::GridLayout(container); | |
38 container->SetLayoutManager(layout); | |
39 | |
40 // Add scroll view. | |
41 views::ColumnSet* column_set = layout->AddColumnSet(0); | |
42 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, | |
43 views::GridLayout::USE_PREF, 0, 0); | |
44 layout->StartRow(1, 0); | |
45 layout->AddView(single_split_view_); | |
46 } | |
47 | 22 |
48 private: | 23 private: |
49 // SingleSplitView's content, which draws gradient color on background. | 24 // SingleSplitView's content, which draws gradient color on background. |
50 class SplittedView : public views::View { | 25 class SplittedView : public views::View { |
51 public: | 26 public: |
52 SplittedView() { | 27 SplittedView(); |
53 SetColor(SK_ColorRED, SK_ColorGREEN); | 28 virtual ~SplittedView(); |
54 } | |
55 | 29 |
56 virtual gfx::Size GetPreferredSize() { | 30 // Overridden from views::View: |
57 return gfx::Size(width(), height()); | 31 virtual gfx::Size GetPreferredSize(); |
58 } | 32 virtual gfx::Size GetMinimumSize(); |
| 33 virtual void Layout(); |
59 | 34 |
60 virtual gfx::Size GetMinimumSize() { | |
61 return gfx::Size(10, 10); | |
62 } | |
63 | |
64 void SetColor(SkColor from, SkColor to) { | |
65 set_background( | |
66 views::Background::CreateVerticalGradientBackground(from, to)); | |
67 } | |
68 | |
69 virtual void Layout() { | |
70 SizeToPreferredSize(); | |
71 } | |
72 | 35 |
73 private: | 36 private: |
| 37 void SetColor(SkColor from, SkColor to); |
| 38 |
74 DISALLOW_COPY_AND_ASSIGN(SplittedView); | 39 DISALLOW_COPY_AND_ASSIGN(SplittedView); |
75 }; | 40 }; |
76 | 41 |
77 // The SinleSplitView to test. | 42 // The SinleSplitView to test. |
78 views::SingleSplitView* single_split_view_; | 43 views::SingleSplitView* single_split_view_; |
79 | 44 |
80 DISALLOW_COPY_AND_ASSIGN(SingleSplitViewExample); | 45 DISALLOW_COPY_AND_ASSIGN(SingleSplitViewExample); |
81 }; | 46 }; |
82 | 47 |
83 } // namespace examples | 48 } // namespace examples |
84 | 49 |
85 #endif // VIEWS_EXAMPLES_SINGLE_SPLIT_VIEW_EXAMPLE_H_ | 50 #endif // VIEWS_EXAMPLES_SINGLE_SPLIT_VIEW_EXAMPLE_H_ |
OLD | NEW |