| 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/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "ui/gfx/geometry/vector2d.h" | 10 #include "ui/gfx/geometry/vector2d.h" |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 label->SetText(ASCIIToUTF16("A multi-line label will wrap onto subsequent " | 108 label->SetText(ASCIIToUTF16("A multi-line label will wrap onto subsequent " |
| 109 "lines if the text's width exceeds the label's available width, which is " | 109 "lines if the text's width exceeds the label's available width, which is " |
| 110 "helpful for extemely long text used to demonstrate line wrapping.")); | 110 "helpful for extemely long text used to demonstrate line wrapping.")); |
| 111 label->SetMultiLine(true); | 111 label->SetMultiLine(true); |
| 112 container->AddChildView(label); | 112 container->AddChildView(label); |
| 113 | 113 |
| 114 label = new Label(ASCIIToUTF16("Label with thick border")); | 114 label = new Label(ASCIIToUTF16("Label with thick border")); |
| 115 label->SetBorder(CreateSolidBorder(20, SK_ColorRED)); | 115 label->SetBorder(CreateSolidBorder(20, SK_ColorRED)); |
| 116 container->AddChildView(label); | 116 container->AddChildView(label); |
| 117 | 117 |
| 118 label = new Label(ASCIIToUTF16("A label supporting text selection.")); | 118 label = new Label( |
| 119 ASCIIToUTF16("A multiline label...\n\n...which supports text selection")); |
| 119 label->SetSelectable(true); | 120 label->SetSelectable(true); |
| 121 label->SetMultiLine(true); |
| 120 container->AddChildView(label); | 122 container->AddChildView(label); |
| 121 | 123 |
| 122 AddCustomLabel(container); | 124 AddCustomLabel(container); |
| 123 } | 125 } |
| 124 | 126 |
| 125 void LabelExample::ButtonPressed(Button* button, const ui::Event& event) { | 127 void LabelExample::ButtonPressed(Button* button, const ui::Event& event) { |
| 126 if (button == multiline_) { | 128 if (button == multiline_) { |
| 127 custom_label_->SetMultiLine(multiline_->checked()); | 129 custom_label_->SetMultiLine(multiline_->checked()); |
| 128 } else if (button == shadows_) { | 130 } else if (button == shadows_) { |
| 129 gfx::ShadowValues shadows; | 131 gfx::ShadowValues shadows; |
| 130 if (shadows_->checked()) { | 132 if (shadows_->checked()) { |
| 131 shadows.push_back(gfx::ShadowValue(gfx::Vector2d(), 1, SK_ColorRED)); | 133 shadows.push_back(gfx::ShadowValue(gfx::Vector2d(), 1, SK_ColorRED)); |
| 132 shadows.push_back(gfx::ShadowValue(gfx::Vector2d(2, 2), 0, SK_ColorGRAY)); | 134 shadows.push_back(gfx::ShadowValue(gfx::Vector2d(2, 2), 0, SK_ColorGRAY)); |
| 133 } | 135 } |
| 134 custom_label_->SetShadows(shadows); | 136 custom_label_->SetShadows(shadows); |
| 137 } else if (button == selectable_) { |
| 138 custom_label_->SetSelectable(selectable_->checked()); |
| 135 } | 139 } |
| 136 custom_label_->parent()->parent()->Layout(); | 140 custom_label_->parent()->parent()->Layout(); |
| 137 custom_label_->SchedulePaint(); | 141 custom_label_->SchedulePaint(); |
| 138 } | 142 } |
| 139 | 143 |
| 140 void LabelExample::OnPerformAction(Combobox* combobox) { | 144 void LabelExample::OnPerformAction(Combobox* combobox) { |
| 141 if (combobox == alignment_) { | 145 if (combobox == alignment_) { |
| 142 custom_label_->SetHorizontalAlignment( | 146 custom_label_->SetHorizontalAlignment( |
| 143 static_cast<gfx::HorizontalAlignment>(combobox->selected_index())); | 147 static_cast<gfx::HorizontalAlignment>(combobox->selected_index())); |
| 144 } else if (combobox == elide_behavior_) { | 148 } else if (combobox == elide_behavior_) { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 alignment_ = AddCombobox(layout, "Alignment: ", kAlignments, | 183 alignment_ = AddCombobox(layout, "Alignment: ", kAlignments, |
| 180 arraysize(kAlignments)); | 184 arraysize(kAlignments)); |
| 181 elide_behavior_ = AddCombobox(layout, "Elide Behavior: ", kElideBehaviors, | 185 elide_behavior_ = AddCombobox(layout, "Elide Behavior: ", kElideBehaviors, |
| 182 arraysize(kElideBehaviors)); | 186 arraysize(kElideBehaviors)); |
| 183 | 187 |
| 184 column_set = layout->AddColumnSet(1); | 188 column_set = layout->AddColumnSet(1); |
| 185 column_set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, | 189 column_set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, |
| 186 0, GridLayout::USE_PREF, 0, 0); | 190 0, GridLayout::USE_PREF, 0, 0); |
| 187 column_set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, | 191 column_set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, |
| 188 0, GridLayout::USE_PREF, 0, 0); | 192 0, GridLayout::USE_PREF, 0, 0); |
| 193 column_set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, 0, |
| 194 GridLayout::USE_PREF, 0, 0); |
| 189 layout->StartRow(0, 1); | 195 layout->StartRow(0, 1); |
| 190 multiline_ = new Checkbox(base::ASCIIToUTF16("Multiline")); | 196 multiline_ = new Checkbox(base::ASCIIToUTF16("Multiline")); |
| 191 multiline_->set_listener(this); | 197 multiline_->set_listener(this); |
| 192 layout->AddView(multiline_); | 198 layout->AddView(multiline_); |
| 193 shadows_ = new Checkbox(base::ASCIIToUTF16("Shadows")); | 199 shadows_ = new Checkbox(base::ASCIIToUTF16("Shadows")); |
| 194 shadows_->set_listener(this); | 200 shadows_->set_listener(this); |
| 195 layout->AddView(shadows_); | 201 layout->AddView(shadows_); |
| 202 selectable_ = new Checkbox(base::ASCIIToUTF16("Selectable")); |
| 203 selectable_->set_listener(this); |
| 204 layout->AddView(selectable_); |
| 196 layout->AddPaddingRow(0, 8); | 205 layout->AddPaddingRow(0, 8); |
| 197 | 206 |
| 198 column_set = layout->AddColumnSet(2); | 207 column_set = layout->AddColumnSet(2); |
| 199 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, | 208 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, |
| 200 1, GridLayout::USE_PREF, 0, 0); | 209 1, GridLayout::USE_PREF, 0, 0); |
| 201 layout->StartRow(0, 2); | 210 layout->StartRow(0, 2); |
| 202 custom_label_ = new PreferredSizeLabel(); | 211 custom_label_ = new PreferredSizeLabel(); |
| 203 custom_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 212 custom_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 204 custom_label_->SetElideBehavior(gfx::NO_ELIDE); | 213 custom_label_->SetElideBehavior(gfx::NO_ELIDE); |
| 205 custom_label_->SetText(textfield_->text()); | 214 custom_label_->SetText(textfield_->text()); |
| 206 layout->AddView(custom_label_); | 215 layout->AddView(custom_label_); |
| 207 | 216 |
| 217 // Disable the text selection checkbox if |custom_label_| does not support |
| 218 // text selection. |
| 219 selectable_->SetEnabled(custom_label_->IsSelectionSupported()); |
| 220 |
| 208 container->AddChildView(control_container); | 221 container->AddChildView(control_container); |
| 209 } | 222 } |
| 210 | 223 |
| 211 Combobox* LabelExample::AddCombobox(GridLayout* layout, | 224 Combobox* LabelExample::AddCombobox(GridLayout* layout, |
| 212 const char* name, | 225 const char* name, |
| 213 const char** strings, | 226 const char** strings, |
| 214 int count) { | 227 int count) { |
| 215 layout->StartRow(0, 0); | 228 layout->StartRow(0, 0); |
| 216 layout->AddView(new Label(base::ASCIIToUTF16(name))); | 229 layout->AddView(new Label(base::ASCIIToUTF16(name))); |
| 217 ExampleComboboxModel* model = new ExampleComboboxModel(strings, count); | 230 ExampleComboboxModel* model = new ExampleComboboxModel(strings, count); |
| 218 example_combobox_models_.push_back(base::WrapUnique(model)); | 231 example_combobox_models_.push_back(base::WrapUnique(model)); |
| 219 Combobox* combobox = new Combobox(model); | 232 Combobox* combobox = new Combobox(model); |
| 220 combobox->SetSelectedIndex(0); | 233 combobox->SetSelectedIndex(0); |
| 221 combobox->set_listener(this); | 234 combobox->set_listener(this); |
| 222 layout->AddView(combobox); | 235 layout->AddView(combobox); |
| 223 return combobox; | 236 return combobox; |
| 224 } | 237 } |
| 225 | 238 |
| 226 } // namespace examples | 239 } // namespace examples |
| 227 } // namespace views | 240 } // namespace views |
| OLD | NEW |