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