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" | |
12 #include "ui/views/controls/combobox/combobox.h" | 11 #include "ui/views/controls/combobox/combobox.h" |
13 #include "ui/views/controls/label.h" | 12 #include "ui/views/controls/label.h" |
14 #include "ui/views/controls/textfield/textfield.h" | 13 #include "ui/views/controls/textfield/textfield.h" |
15 #include "ui/views/examples/example_combobox_model.h" | 14 #include "ui/views/examples/example_combobox_model.h" |
16 #include "ui/views/layout/box_layout.h" | 15 #include "ui/views/layout/box_layout.h" |
17 #include "ui/views/layout/grid_layout.h" | 16 #include "ui/views/layout/grid_layout.h" |
18 #include "ui/views/view.h" | 17 #include "ui/views/view.h" |
19 | 18 |
20 using base::ASCIIToUTF16; | 19 using base::ASCIIToUTF16; |
21 using base::WideToUTF16; | 20 using base::WideToUTF16; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 | 85 |
87 label = new Label(WideToUTF16(L"Password!")); | 86 label = new Label(WideToUTF16(L"Password!")); |
88 label->SetObscured(true); | 87 label->SetObscured(true); |
89 container->AddChildView(label); | 88 container->AddChildView(label); |
90 | 89 |
91 label = new Label(ASCIIToUTF16("A Courier-18 label with shadows.")); | 90 label = new Label(ASCIIToUTF16("A Courier-18 label with shadows.")); |
92 label->SetFontList(gfx::FontList("Courier, 18px")); | 91 label->SetFontList(gfx::FontList("Courier, 18px")); |
93 gfx::ShadowValues shadows(1, gfx::ShadowValue(gfx::Point(), 1, SK_ColorRED)); | 92 gfx::ShadowValues shadows(1, gfx::ShadowValue(gfx::Point(), 1, SK_ColorRED)); |
94 gfx::ShadowValue shadow(gfx::Point(2, 2), 0, SK_ColorGRAY); | 93 gfx::ShadowValue shadow(gfx::Point(2, 2), 0, SK_ColorGRAY); |
95 shadows.push_back(shadow); | 94 shadows.push_back(shadow); |
96 label->set_shadows(shadows); | 95 label->SetShadows(shadows); |
97 container->AddChildView(label); | 96 container->AddChildView(label); |
98 | 97 |
99 label = new PreferredSizeLabel(); | 98 label = new PreferredSizeLabel(); |
100 label->SetText(ASCIIToUTF16("A long label will elide toward its logical end " | 99 label->SetText(ASCIIToUTF16("A long label will elide toward its logical end " |
101 "if the text's width exceeds the label's available width.")); | 100 "if the text's width exceeds the label's available width.")); |
102 container->AddChildView(label); | 101 container->AddChildView(label); |
103 | 102 |
104 label = new PreferredSizeLabel(); | 103 label = new PreferredSizeLabel(); |
105 label->SetText(ASCIIToUTF16("A multi-line label will wrap onto subsequent " | 104 label->SetText(ASCIIToUTF16("A multi-line label will wrap onto subsequent " |
106 "lines if the text's width exceeds the label's available width, which is " | 105 "lines if the text's width exceeds the label's available width, which is " |
107 "helpful for extemely long text used to demonstrate line wrapping.")); | 106 "helpful for extemely long text used to demonstrate line wrapping.")); |
108 label->SetMultiLine(true); | 107 label->SetMultiLine(true); |
109 container->AddChildView(label); | 108 container->AddChildView(label); |
110 | 109 |
111 AddCustomLabel(container); | 110 AddCustomLabel(container); |
112 } | 111 } |
113 | 112 |
114 void LabelExample::ButtonPressed(Button* button, const ui::Event& event) { | 113 void LabelExample::ButtonPressed(Button* button, const ui::Event& event) { |
115 if (button == multiline_) { | 114 if (button == multiline_) { |
116 custom_label_->SetMultiLine(multiline_->checked()); | 115 custom_label_->SetMultiLine(multiline_->checked()); |
117 } else if (button == shadows_) { | 116 } else if (button == shadows_) { |
118 gfx::ShadowValues shadows; | 117 gfx::ShadowValues shadows; |
119 if (shadows_->checked()) { | 118 if (shadows_->checked()) { |
120 shadows.push_back(gfx::ShadowValue(gfx::Point(), 1, SK_ColorRED)); | 119 shadows.push_back(gfx::ShadowValue(gfx::Point(), 1, SK_ColorRED)); |
121 shadows.push_back(gfx::ShadowValue(gfx::Point(2, 2), 0, SK_ColorGRAY)); | 120 shadows.push_back(gfx::ShadowValue(gfx::Point(2, 2), 0, SK_ColorGRAY)); |
122 } | 121 } |
123 custom_label_->set_shadows(shadows); | 122 custom_label_->SetShadows(shadows); |
124 } | 123 } |
125 custom_label_->parent()->parent()->Layout(); | 124 custom_label_->parent()->parent()->Layout(); |
126 custom_label_->SchedulePaint(); | 125 custom_label_->SchedulePaint(); |
127 } | 126 } |
128 | 127 |
129 void LabelExample::OnPerformAction(Combobox* combobox) { | 128 void LabelExample::OnPerformAction(Combobox* combobox) { |
130 if (combobox == alignment_) { | 129 if (combobox == alignment_) { |
131 custom_label_->SetHorizontalAlignment( | 130 custom_label_->SetHorizontalAlignment( |
132 static_cast<gfx::HorizontalAlignment>(combobox->selected_index())); | 131 static_cast<gfx::HorizontalAlignment>(combobox->selected_index())); |
133 } else if (combobox == elide_behavior_) { | 132 } else if (combobox == elide_behavior_) { |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 example_combobox_models_.push_back(model); | 206 example_combobox_models_.push_back(model); |
208 Combobox* combobox = new Combobox(model); | 207 Combobox* combobox = new Combobox(model); |
209 combobox->SetSelectedIndex(0); | 208 combobox->SetSelectedIndex(0); |
210 combobox->set_listener(this); | 209 combobox->set_listener(this); |
211 layout->AddView(combobox); | 210 layout->AddView(combobox); |
212 return combobox; | 211 return combobox; |
213 } | 212 } |
214 | 213 |
215 } // namespace examples | 214 } // namespace examples |
216 } // namespace views | 215 } // namespace views |
OLD | NEW |