| 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 "ui/views/examples/single_split_view_example.h" | |
| 6 | |
| 7 #include "ui/views/background.h" | |
| 8 #include "ui/views/controls/single_split_view.h" | |
| 9 #include "ui/views/layout/grid_layout.h" | |
| 10 | |
| 11 namespace views { | |
| 12 namespace examples { | |
| 13 namespace { | |
| 14 | |
| 15 // SingleSplitView's content, which draws gradient color on background. | |
| 16 class SplittedView : public View { | |
| 17 public: | |
| 18 SplittedView(); | |
| 19 virtual ~SplittedView(); | |
| 20 | |
| 21 void SetColor(SkColor from, SkColor to); | |
| 22 | |
| 23 private: | |
| 24 // View: | |
| 25 virtual gfx::Size GetPreferredSize() const override; | |
| 26 virtual gfx::Size GetMinimumSize() const override; | |
| 27 virtual void Layout() override; | |
| 28 | |
| 29 DISALLOW_COPY_AND_ASSIGN(SplittedView); | |
| 30 }; | |
| 31 | |
| 32 SplittedView::SplittedView() { | |
| 33 SetColor(SK_ColorRED, SK_ColorGREEN); | |
| 34 } | |
| 35 | |
| 36 SplittedView::~SplittedView() { | |
| 37 } | |
| 38 | |
| 39 void SplittedView::SetColor(SkColor from, SkColor to) { | |
| 40 set_background(Background::CreateVerticalGradientBackground(from, to)); | |
| 41 } | |
| 42 | |
| 43 gfx::Size SplittedView::GetPreferredSize() const { | |
| 44 return gfx::Size(width(), height()); | |
| 45 } | |
| 46 | |
| 47 gfx::Size SplittedView::GetMinimumSize() const { | |
| 48 return gfx::Size(10, 10); | |
| 49 } | |
| 50 | |
| 51 void SplittedView::Layout() { | |
| 52 SizeToPreferredSize(); | |
| 53 } | |
| 54 | |
| 55 } // namespace | |
| 56 | |
| 57 SingleSplitViewExample::SingleSplitViewExample() | |
| 58 : ExampleBase("Single Split View") { | |
| 59 } | |
| 60 | |
| 61 SingleSplitViewExample::~SingleSplitViewExample() { | |
| 62 } | |
| 63 | |
| 64 void SingleSplitViewExample::CreateExampleView(View* container) { | |
| 65 SplittedView* splitted_view_1 = new SplittedView; | |
| 66 SplittedView* splitted_view_2 = new SplittedView; | |
| 67 | |
| 68 splitted_view_1->SetColor(SK_ColorYELLOW, SK_ColorCYAN); | |
| 69 | |
| 70 single_split_view_ = new SingleSplitView( | |
| 71 splitted_view_1, splitted_view_2, | |
| 72 SingleSplitView::HORIZONTAL_SPLIT, | |
| 73 this); | |
| 74 | |
| 75 GridLayout* layout = new GridLayout(container); | |
| 76 container->SetLayoutManager(layout); | |
| 77 | |
| 78 ColumnSet* column_set = layout->AddColumnSet(0); | |
| 79 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, | |
| 80 GridLayout::USE_PREF, 0, 0); | |
| 81 layout->StartRow(1, 0); | |
| 82 layout->AddView(single_split_view_); | |
| 83 } | |
| 84 | |
| 85 bool SingleSplitViewExample::SplitHandleMoved(SingleSplitView* sender) { | |
| 86 PrintStatus("Splitter moved"); | |
| 87 return true; | |
| 88 } | |
| 89 | |
| 90 } // namespace examples | |
| 91 } // namespace views | |
| OLD | NEW |