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/button_example.h" | 5 #include "ui/views/examples/button_example.h" |
6 | 6 |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "ui/base/resource/resource_bundle.h" | 8 #include "ui/base/resource/resource_bundle.h" |
9 #include "ui/gfx/image/image.h" | 9 #include "ui/gfx/image/image.h" |
10 #include "ui/resources/grit/ui_resources.h" | 10 #include "ui/resources/grit/ui_resources.h" |
11 #include "ui/views/background.h" | 11 #include "ui/views/background.h" |
12 #include "ui/views/controls/button/blue_button.h" | 12 #include "ui/views/controls/button/blue_button.h" |
13 #include "ui/views/controls/button/image_button.h" | 13 #include "ui/views/controls/button/image_button.h" |
14 #include "ui/views/controls/button/label_button.h" | 14 #include "ui/views/controls/button/label_button.h" |
| 15 #include "ui/views/controls/button/md_text_button.h" |
15 #include "ui/views/layout/box_layout.h" | 16 #include "ui/views/layout/box_layout.h" |
16 #include "ui/views/resources/grit/views_resources.h" | 17 #include "ui/views/resources/grit/views_resources.h" |
17 #include "ui/views/view.h" | 18 #include "ui/views/view.h" |
18 | 19 |
19 using base::ASCIIToUTF16; | 20 using base::ASCIIToUTF16; |
20 | 21 |
21 namespace { | 22 namespace { |
22 const char kLabelButton[] = "Label Button"; | 23 const char kLabelButton[] = "Label Button"; |
23 const char kMultiLineText[] = "Multi-Line\nButton Text Is Here To Stay!\n123"; | 24 const char kMultiLineText[] = "Multi-Line\nButton Text Is Here To Stay!\n123"; |
24 const char kLongText[] = "Start of Really Really Really Really Really Really " | 25 const char kLongText[] = "Start of Really Really Really Really Really Really " |
(...skipping 12 matching lines...) Expand all Loading... |
37 count_(0) { | 38 count_(0) { |
38 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 39 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
39 icon_ = rb.GetImageNamed(IDR_CLOSE_H).ToImageSkia(); | 40 icon_ = rb.GetImageNamed(IDR_CLOSE_H).ToImageSkia(); |
40 } | 41 } |
41 | 42 |
42 ButtonExample::~ButtonExample() { | 43 ButtonExample::~ButtonExample() { |
43 } | 44 } |
44 | 45 |
45 void ButtonExample::CreateExampleView(View* container) { | 46 void ButtonExample::CreateExampleView(View* container) { |
46 container->set_background(Background::CreateSolidBackground(SK_ColorWHITE)); | 47 container->set_background(Background::CreateSolidBackground(SK_ColorWHITE)); |
47 container->SetLayoutManager(new BoxLayout(BoxLayout::kVertical, 10, 10, 10)); | 48 BoxLayout* layout = new BoxLayout(BoxLayout::kVertical, 10, 10, 10); |
| 49 layout->set_cross_axis_alignment(BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER); |
| 50 container->SetLayoutManager(layout); |
48 | 51 |
49 label_button_ = new LabelButton(this, ASCIIToUTF16(kLabelButton)); | 52 label_button_ = new LabelButton(this, ASCIIToUTF16(kLabelButton)); |
50 label_button_->SetFocusable(true); | 53 label_button_->SetFocusable(true); |
51 container->AddChildView(label_button_); | 54 container->AddChildView(label_button_); |
52 | 55 |
53 LabelButton* styled_button = | 56 LabelButton* styled_button = |
54 new LabelButton(this, ASCIIToUTF16("Styled Button")); | 57 new LabelButton(this, ASCIIToUTF16("Styled Button")); |
55 styled_button->SetStyle(Button::STYLE_BUTTON); | 58 styled_button->SetStyle(Button::STYLE_BUTTON); |
56 container->AddChildView(styled_button); | 59 container->AddChildView(styled_button); |
57 | 60 |
58 LabelButton* disabled_button = | 61 LabelButton* disabled_button = |
59 new LabelButton(this, ASCIIToUTF16("Disabled Button")); | 62 new LabelButton(this, ASCIIToUTF16("Disabled Button")); |
60 disabled_button->SetStyle(Button::STYLE_BUTTON); | 63 disabled_button->SetStyle(Button::STYLE_BUTTON); |
61 disabled_button->SetState(Button::STATE_DISABLED); | 64 disabled_button->SetState(Button::STATE_DISABLED); |
62 container->AddChildView(disabled_button); | 65 container->AddChildView(disabled_button); |
63 | 66 |
64 container->AddChildView(new BlueButton(this, ASCIIToUTF16("Blue Button"))); | 67 container->AddChildView(new BlueButton(this, ASCIIToUTF16("Blue Button"))); |
65 | 68 |
| 69 container->AddChildView( |
| 70 new MdTextButton(nullptr, base::ASCIIToUTF16("Material design"))); |
| 71 |
66 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 72 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
67 image_button_ = new ImageButton(this); | 73 image_button_ = new ImageButton(this); |
68 image_button_->SetFocusable(true); | 74 image_button_->SetFocusable(true); |
69 image_button_->SetImage(ImageButton::STATE_NORMAL, | 75 image_button_->SetImage(ImageButton::STATE_NORMAL, |
70 rb.GetImageNamed(IDR_CLOSE).ToImageSkia()); | 76 rb.GetImageNamed(IDR_CLOSE).ToImageSkia()); |
71 image_button_->SetImage(ImageButton::STATE_HOVERED, | 77 image_button_->SetImage(ImageButton::STATE_HOVERED, |
72 rb.GetImageNamed(IDR_CLOSE_H).ToImageSkia()); | 78 rb.GetImageNamed(IDR_CLOSE_H).ToImageSkia()); |
73 image_button_->SetImage(ImageButton::STATE_PRESSED, | 79 image_button_->SetImage(ImageButton::STATE_PRESSED, |
74 rb.GetImageNamed(IDR_CLOSE_P).ToImageSkia()); | 80 rb.GetImageNamed(IDR_CLOSE_P).ToImageSkia()); |
75 container->AddChildView(image_button_); | 81 container->AddChildView(image_button_); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 | 120 |
115 void ButtonExample::ButtonPressed(Button* sender, const ui::Event& event) { | 121 void ButtonExample::ButtonPressed(Button* sender, const ui::Event& event) { |
116 if (sender == label_button_) | 122 if (sender == label_button_) |
117 LabelButtonPressed(event); | 123 LabelButtonPressed(event); |
118 else | 124 else |
119 PrintStatus("Image Button Pressed! count: %d", ++count_); | 125 PrintStatus("Image Button Pressed! count: %d", ++count_); |
120 } | 126 } |
121 | 127 |
122 } // namespace examples | 128 } // namespace examples |
123 } // namespace views | 129 } // namespace views |
OLD | NEW |