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.
5 #include "ui/views/examples/tabbed_pane_example.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "ui/views/controls/button/label_button.h"
9 #include "ui/views/controls/tabbed_pane/tabbed_pane.h"
10 #include "ui/views/layout/grid_layout.h"
15 TabbedPaneExample::TabbedPaneExample() : ExampleBase("Tabbed Pane") {
18 TabbedPaneExample::~TabbedPaneExample() {
21 void TabbedPaneExample::CreateExampleView(View* container) {
22 tabbed_pane_ = new TabbedPane(false);
23 tabbed_pane_->set_listener(this);
24 add_ = new LabelButton(this, ASCIIToUTF16("Add"));
25 add_at_ = new LabelButton(this, ASCIIToUTF16("Add At 1"));
26 select_at_ = new LabelButton(this, ASCIIToUTF16("Select At 1"));
28 GridLayout* layout = new GridLayout(container);
29 container->SetLayoutManager(layout);
31 const int tabbed_pane_column = 0;
32 ColumnSet* column_set = layout->AddColumnSet(tabbed_pane_column);
33 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL,
34 1.0f, GridLayout::USE_PREF, 0, 0);
35 layout->StartRow(1 /* expand */, tabbed_pane_column);
36 layout->AddView(tabbed_pane_);
38 // Create a few tabs with a button first.
42 // Add control buttons horizontally.
43 const int button_column = 1;
44 column_set = layout->AddColumnSet(button_column);
45 for (int i = 0; i < 3; i++) {
46 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL,
47 1.0f, GridLayout::USE_PREF, 0, 0);
50 layout->StartRow(0 /* no expand */, button_column);
51 layout->AddView(add_);
52 layout->AddView(add_at_);
53 layout->AddView(select_at_);
56 void TabbedPaneExample::ButtonPressed(Button* sender, const ui::Event& event) {
59 } else if (sender == add_at_) {
60 const string16 label = ASCIIToUTF16("Added at 1");
61 tabbed_pane_->AddTabAtIndex(1, label, new LabelButton(NULL, label));
62 } else if (sender == select_at_) {
63 if (tabbed_pane_->GetTabCount() > 1)
64 tabbed_pane_->SelectTabAt(1);
69 void TabbedPaneExample::TabSelectedAt(int index) {
70 // Just print the status when selection changes.
74 void TabbedPaneExample::PrintStatus() {
75 ExampleBase::PrintStatus("Tab Count:%d, Selected Tab:%d",
76 tabbed_pane_->GetTabCount(),
77 tabbed_pane_->selected_tab_index());
80 void TabbedPaneExample::AddButton(const std::string& label) {
81 LabelButton* button = new LabelButton(NULL, ASCIIToUTF16(label));
82 tabbed_pane_->AddTab(ASCIIToUTF16(label), button);
85 } // namespace examples