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 17 matching lines...) Expand all Loading... |
28 namespace { | 28 namespace { |
29 | 29 |
30 const char* kElideBehaviors[] = { "No Elide", "Truncate", "Elide Head", | 30 const char* kElideBehaviors[] = { "No Elide", "Truncate", "Elide Head", |
31 "Elide Middle", "Elide Tail", "Elide Email", "Fade Tail" }; | 31 "Elide Middle", "Elide Tail", "Elide Email", "Fade Tail" }; |
32 const char* kAlignments[] = { "Left", "Center", "Right", "Head" }; | 32 const char* kAlignments[] = { "Left", "Center", "Right", "Head" }; |
33 | 33 |
34 // A Label with a clamped preferred width to demonstrate eliding or wrapping. | 34 // A Label with a clamped preferred width to demonstrate eliding or wrapping. |
35 class PreferredSizeLabel : public Label { | 35 class PreferredSizeLabel : public Label { |
36 public: | 36 public: |
37 PreferredSizeLabel() : Label() { | 37 PreferredSizeLabel() : Label() { |
38 SetBorder(Border::CreateSolidBorder(1, SK_ColorGRAY)); | 38 SetBorder(CreateSolidBorder(1, SK_ColorGRAY)); |
39 } | 39 } |
40 ~PreferredSizeLabel() override {} | 40 ~PreferredSizeLabel() override {} |
41 | 41 |
42 // Label: | 42 // Label: |
43 gfx::Size GetPreferredSize() const override { | 43 gfx::Size GetPreferredSize() const override { |
44 return gfx::Size(50, Label::GetPreferredSize().height()); | 44 return gfx::Size(50, Label::GetPreferredSize().height()); |
45 } | 45 } |
46 | 46 |
47 private: | 47 private: |
48 DISALLOW_COPY_AND_ASSIGN(PreferredSizeLabel); | 48 DISALLOW_COPY_AND_ASSIGN(PreferredSizeLabel); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 container->AddChildView(label); | 105 container->AddChildView(label); |
106 | 106 |
107 label = new PreferredSizeLabel(); | 107 label = new PreferredSizeLabel(); |
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(Border::CreateSolidBorder(20, SK_ColorRED)); | 115 label->SetBorder(CreateSolidBorder(20, SK_ColorRED)); |
116 container->AddChildView(label); | 116 container->AddChildView(label); |
117 | 117 |
118 AddCustomLabel(container); | 118 AddCustomLabel(container); |
119 } | 119 } |
120 | 120 |
121 void LabelExample::ButtonPressed(Button* button, const ui::Event& event) { | 121 void LabelExample::ButtonPressed(Button* button, const ui::Event& event) { |
122 if (button == multiline_) { | 122 if (button == multiline_) { |
123 custom_label_->SetMultiLine(multiline_->checked()); | 123 custom_label_->SetMultiLine(multiline_->checked()); |
124 } else if (button == shadows_) { | 124 } else if (button == shadows_) { |
125 gfx::ShadowValues shadows; | 125 gfx::ShadowValues shadows; |
(...skipping 18 matching lines...) Expand all Loading... |
144 } | 144 } |
145 | 145 |
146 void LabelExample::ContentsChanged(Textfield* sender, | 146 void LabelExample::ContentsChanged(Textfield* sender, |
147 const base::string16& new_contents) { | 147 const base::string16& new_contents) { |
148 custom_label_->SetText(new_contents); | 148 custom_label_->SetText(new_contents); |
149 custom_label_->parent()->parent()->Layout(); | 149 custom_label_->parent()->parent()->Layout(); |
150 } | 150 } |
151 | 151 |
152 void LabelExample::AddCustomLabel(View* container) { | 152 void LabelExample::AddCustomLabel(View* container) { |
153 View* control_container = new View(); | 153 View* control_container = new View(); |
154 control_container->SetBorder(Border::CreateSolidBorder(2, SK_ColorGRAY)); | 154 control_container->SetBorder(CreateSolidBorder(2, SK_ColorGRAY)); |
155 control_container->set_background( | 155 control_container->set_background( |
156 Background::CreateSolidBackground(SK_ColorLTGRAY)); | 156 Background::CreateSolidBackground(SK_ColorLTGRAY)); |
157 GridLayout* layout = GridLayout::CreatePanel(control_container); | 157 GridLayout* layout = GridLayout::CreatePanel(control_container); |
158 control_container->SetLayoutManager(layout); | 158 control_container->SetLayoutManager(layout); |
159 | 159 |
160 ColumnSet* column_set = layout->AddColumnSet(0); | 160 ColumnSet* column_set = layout->AddColumnSet(0); |
161 column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, | 161 column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, |
162 0.0f, GridLayout::USE_PREF, 0, 0); | 162 0.0f, GridLayout::USE_PREF, 0, 0); |
163 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, | 163 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, |
164 1.0f, GridLayout::USE_PREF, 0, 0); | 164 1.0f, GridLayout::USE_PREF, 0, 0); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 example_combobox_models_.push_back(base::WrapUnique(model)); | 214 example_combobox_models_.push_back(base::WrapUnique(model)); |
215 Combobox* combobox = new Combobox(model); | 215 Combobox* combobox = new Combobox(model); |
216 combobox->SetSelectedIndex(0); | 216 combobox->SetSelectedIndex(0); |
217 combobox->set_listener(this); | 217 combobox->set_listener(this); |
218 layout->AddView(combobox); | 218 layout->AddView(combobox); |
219 return combobox; | 219 return combobox; |
220 } | 220 } |
221 | 221 |
222 } // namespace examples | 222 } // namespace examples |
223 } // namespace views | 223 } // namespace views |
OLD | NEW |