| 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/border.h" | 8 #include "ui/views/border.h" |
| 9 #include "ui/views/controls/label.h" | 9 #include "ui/views/controls/label.h" |
| 10 #include "ui/views/layout/box_layout.h" | 10 #include "ui/views/layout/box_layout.h" |
| 11 #include "ui/views/view.h" | 11 #include "ui/views/view.h" |
| 12 | 12 |
| 13 using base::ASCIIToUTF16; | 13 using base::ASCIIToUTF16; |
| 14 using base::WideToUTF16; | 14 using base::WideToUTF16; |
| 15 | 15 |
| 16 namespace views { | 16 namespace views { |
| 17 namespace examples { | 17 namespace examples { |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 // A Label with a constrained preferred size to demonstrate eliding or wrapping. | 21 // A Label with a constrained preferred size to demonstrate eliding or wrapping. |
| 22 class PreferredSizeLabel : public Label { | 22 class PreferredSizeLabel : public Label { |
| 23 public: | 23 public: |
| 24 PreferredSizeLabel(); | 24 PreferredSizeLabel() : Label() { |
| 25 virtual ~PreferredSizeLabel(); | 25 SetBorder(Border::CreateSolidBorder(2, SK_ColorCYAN)); |
| 26 } |
| 27 virtual ~PreferredSizeLabel() {} |
| 26 | 28 |
| 27 // Label: | 29 // Label: |
| 28 virtual gfx::Size GetPreferredSize() const OVERRIDE; | 30 virtual gfx::Size GetPreferredSize() const OVERRIDE { |
| 31 return gfx::Size(100, 40); |
| 32 } |
| 29 | 33 |
| 30 private: | 34 private: |
| 31 DISALLOW_COPY_AND_ASSIGN(PreferredSizeLabel); | 35 DISALLOW_COPY_AND_ASSIGN(PreferredSizeLabel); |
| 32 }; | 36 }; |
| 33 | 37 |
| 34 PreferredSizeLabel::PreferredSizeLabel() : Label() { | |
| 35 SetBorder(Border::CreateSolidBorder(2, SK_ColorCYAN)); | |
| 36 } | |
| 37 | |
| 38 PreferredSizeLabel::~PreferredSizeLabel() {} | |
| 39 | |
| 40 gfx::Size PreferredSizeLabel::GetPreferredSize() const { | |
| 41 return gfx::Size(100, 40); | |
| 42 } | |
| 43 | |
| 44 } // namespace | 38 } // namespace |
| 45 | 39 |
| 46 LabelExample::LabelExample() : ExampleBase("Label") {} | 40 LabelExample::LabelExample() : ExampleBase("Label") {} |
| 47 | 41 |
| 48 LabelExample::~LabelExample() {} | 42 LabelExample::~LabelExample() {} |
| 49 | 43 |
| 50 void LabelExample::CreateExampleView(View* container) { | 44 void LabelExample::CreateExampleView(View* container) { |
| 51 // A very simple label example, followed by additional helpful examples. | 45 // A very simple label example, followed by additional helpful examples. |
| 52 container->SetLayoutManager(new BoxLayout(BoxLayout::kVertical, 0, 0, 10)); | 46 container->SetLayoutManager(new BoxLayout(BoxLayout::kVertical, 0, 0, 10)); |
| 53 Label* label = new Label(ASCIIToUTF16("Hello world!")); | 47 Label* label = new Label(ASCIIToUTF16("Hello world!")); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 74 label->SetShadowOffset(2, 2); | 68 label->SetShadowOffset(2, 2); |
| 75 label->set_halo_color(SK_ColorGREEN); | 69 label->set_halo_color(SK_ColorGREEN); |
| 76 container->AddChildView(label); | 70 container->AddChildView(label); |
| 77 | 71 |
| 78 label = new PreferredSizeLabel(); | 72 label = new PreferredSizeLabel(); |
| 79 label->SetText(ASCIIToUTF16("A long label will elide toward its logical end " | 73 label->SetText(ASCIIToUTF16("A long label will elide toward its logical end " |
| 80 "if the text's width exceeds the label's available width.")); | 74 "if the text's width exceeds the label's available width.")); |
| 81 container->AddChildView(label); | 75 container->AddChildView(label); |
| 82 | 76 |
| 83 label = new PreferredSizeLabel(); | 77 label = new PreferredSizeLabel(); |
| 78 label->SetElideBehavior(gfx::FADE_TAIL); |
| 79 label->SetText(ASCIIToUTF16("Some long labels will fade, rather than elide, " |
| 80 "if the text's width exceeds the label's available width.")); |
| 81 container->AddChildView(label); |
| 82 |
| 83 label = new PreferredSizeLabel(); |
| 84 label->SetText(ASCIIToUTF16("A multi-line label will wrap onto subsequent " | 84 label->SetText(ASCIIToUTF16("A multi-line label will wrap onto subsequent " |
| 85 "lines if the text's width exceeds the label's available width.")); | 85 "lines if the text's width exceeds the label's available width.")); |
| 86 label->SetMultiLine(true); | 86 label->SetMultiLine(true); |
| 87 container->AddChildView(label); | 87 container->AddChildView(label); |
| 88 | 88 |
| 89 label = new Label(WideToUTF16(L"Password!")); | 89 label = new Label(WideToUTF16(L"Password!")); |
| 90 label->SetObscured(true); | 90 label->SetObscured(true); |
| 91 container->AddChildView(label); | 91 container->AddChildView(label); |
| 92 } | 92 } |
| 93 | 93 |
| 94 } // namespace examples | 94 } // namespace examples |
| 95 } // namespace views | 95 } // namespace views |
| OLD | NEW |