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