| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "ui/views/examples/label_example.h" | 5 #include "ui/views/examples/label_example.h" |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "ui/views/background.h" | 8 #include "ui/views/background.h" |
| 9 #include "ui/views/border.h" | 9 #include "ui/views/border.h" |
| 10 #include "ui/views/controls/button/checkbox.h" | 10 #include "ui/views/controls/button/checkbox.h" |
| 11 #include "ui/views/controls/button/label_button.h" | 11 #include "ui/views/controls/button/label_button.h" |
| 12 #include "ui/views/controls/combobox/combobox.h" | 12 #include "ui/views/controls/combobox/combobox.h" |
| 13 #include "ui/views/controls/label.h" | 13 #include "ui/views/controls/label.h" |
| 14 #include "ui/views/controls/textfield/textfield.h" | 14 #include "ui/views/controls/textfield/textfield.h" |
| 15 #include "ui/views/examples/example_combobox_model.h" | 15 #include "ui/views/examples/example_combobox_model.h" |
| 16 #include "ui/views/layout/box_layout.h" | 16 #include "ui/views/layout/box_layout.h" |
| 17 #include "ui/views/layout/grid_layout.h" | 17 #include "ui/views/layout/grid_layout.h" |
| 18 #include "ui/views/view.h" | 18 #include "ui/views/view.h" |
| 19 | 19 |
| 20 using base::ASCIIToUTF16; | 20 using base::ASCIIToUTF16; |
| 21 using base::WideToUTF16; | 21 using base::WideToUTF16; |
| 22 | 22 |
| 23 namespace views { | 23 namespace views { |
| 24 namespace examples { | 24 namespace examples { |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 const char* kElideBehaviors[] = { "Truncate", "Elide Head", "Elide Middle", | 28 const char* kElideBehaviors[] = { "No Elide", "Truncate", "Elide Head", |
| 29 "Elide Tail", "Elide Email", "Fade Tail" }; | 29 "Elide Middle", "Elide Tail", "Elide Email", "Fade Tail" }; |
| 30 const char* kAlignments[] = { "Left", "Center", "Right", "Head" }; | 30 const char* kAlignments[] = { "Left", "Center", "Right", "Head" }; |
| 31 | 31 |
| 32 // A Label with a clamped preferred width to demonstrate eliding or wrapping. | 32 // A Label with a clamped preferred width to demonstrate eliding or wrapping. |
| 33 class PreferredSizeLabel : public Label { | 33 class PreferredSizeLabel : public Label { |
| 34 public: | 34 public: |
| 35 PreferredSizeLabel() : Label() { | 35 PreferredSizeLabel() : Label() { |
| 36 SetBorder(Border::CreateSolidBorder(1, SK_ColorGRAY)); | 36 SetBorder(Border::CreateSolidBorder(1, SK_ColorGRAY)); |
| 37 } | 37 } |
| 38 virtual ~PreferredSizeLabel() {} | 38 virtual ~PreferredSizeLabel() {} |
| 39 | 39 |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 shadows_->set_listener(this); | 183 shadows_->set_listener(this); |
| 184 layout->AddView(shadows_); | 184 layout->AddView(shadows_); |
| 185 layout->AddPaddingRow(0, 8); | 185 layout->AddPaddingRow(0, 8); |
| 186 | 186 |
| 187 column_set = layout->AddColumnSet(2); | 187 column_set = layout->AddColumnSet(2); |
| 188 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, | 188 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, |
| 189 1, GridLayout::USE_PREF, 0, 0); | 189 1, GridLayout::USE_PREF, 0, 0); |
| 190 layout->StartRow(0, 2); | 190 layout->StartRow(0, 2); |
| 191 custom_label_ = new PreferredSizeLabel(); | 191 custom_label_ = new PreferredSizeLabel(); |
| 192 custom_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 192 custom_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 193 custom_label_->SetElideBehavior(gfx::TRUNCATE); | 193 custom_label_->SetElideBehavior(gfx::NO_ELIDE); |
| 194 custom_label_->SetText(textfield_->text()); | 194 custom_label_->SetText(textfield_->text()); |
| 195 layout->AddView(custom_label_); | 195 layout->AddView(custom_label_); |
| 196 | 196 |
| 197 container->AddChildView(control_container); | 197 container->AddChildView(control_container); |
| 198 } | 198 } |
| 199 | 199 |
| 200 Combobox* LabelExample::AddCombobox(GridLayout* layout, | 200 Combobox* LabelExample::AddCombobox(GridLayout* layout, |
| 201 const char* name, | 201 const char* name, |
| 202 const char** strings, | 202 const char** strings, |
| 203 int count) { | 203 int count) { |
| 204 layout->StartRow(0, 0); | 204 layout->StartRow(0, 0); |
| 205 layout->AddView(new Label(base::ASCIIToUTF16(name))); | 205 layout->AddView(new Label(base::ASCIIToUTF16(name))); |
| 206 ExampleComboboxModel* model = new ExampleComboboxModel(strings, count); | 206 ExampleComboboxModel* model = new ExampleComboboxModel(strings, count); |
| 207 example_combobox_models_.push_back(model); | 207 example_combobox_models_.push_back(model); |
| 208 Combobox* combobox = new Combobox(model); | 208 Combobox* combobox = new Combobox(model); |
| 209 combobox->SetSelectedIndex(0); | 209 combobox->SetSelectedIndex(0); |
| 210 combobox->set_listener(this); | 210 combobox->set_listener(this); |
| 211 layout->AddView(combobox); | 211 layout->AddView(combobox); |
| 212 return combobox; | 212 return combobox; |
| 213 } | 213 } |
| 214 | 214 |
| 215 } // namespace examples | 215 } // namespace examples |
| 216 } // namespace views | 216 } // namespace views |
| OLD | NEW |