| 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/slider_example.h" | 5 #include "ui/views/examples/slider_example.h" |
| 6 | 6 |
| 7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "ui/views/controls/label.h" | 9 #include "ui/views/controls/label.h" |
| 10 #include "ui/views/controls/slider.h" | 10 #include "ui/views/controls/slider.h" |
| 11 #include "ui/views/layout/box_layout.h" | 11 #include "ui/views/layout/box_layout.h" |
| 12 #include "ui/views/view.h" | 12 #include "ui/views/view.h" |
| 13 | 13 |
| 14 namespace views { | 14 namespace views { |
| 15 namespace examples { | 15 namespace examples { |
| 16 | 16 |
| 17 SliderExample::SliderExample() | 17 SliderExample::SliderExample() |
| 18 : ExampleBase("Slider"), | 18 : ExampleBase("Slider"), |
| 19 slider_(NULL), | 19 slider_(NULL), |
| 20 label_(NULL) { | 20 label_(NULL) { |
| 21 } | 21 } |
| 22 | 22 |
| 23 SliderExample::~SliderExample() { | 23 SliderExample::~SliderExample() { |
| 24 } | 24 } |
| 25 | 25 |
| 26 void SliderExample::CreateExampleView(View* container) { | 26 void SliderExample::CreateExampleView(View* container) { |
| 27 label_ = new Label(); | 27 label_ = new Label(); |
| 28 // Create a material design slider in this example. | 28 slider_ = new views::Slider(this); |
| 29 slider_ = Slider::CreateSlider(true /** is_material_design **/, this); | |
| 30 | 29 |
| 31 slider_->SetValue(0.5); | 30 slider_->SetValue(0.5); |
| 32 | 31 |
| 33 container->SetLayoutManager(new BoxLayout(BoxLayout::kHorizontal, 3, 3, 3)); | 32 container->SetLayoutManager(new BoxLayout(BoxLayout::kHorizontal, 3, 3, 3)); |
| 34 container->AddChildView(slider_); | 33 container->AddChildView(slider_); |
| 35 container->AddChildView(label_); | 34 container->AddChildView(label_); |
| 36 } | 35 } |
| 37 | 36 |
| 38 void SliderExample::SliderValueChanged(Slider* sender, | 37 void SliderExample::SliderValueChanged(Slider* sender, |
| 39 float value, | 38 float value, |
| 40 float old_value, | 39 float old_value, |
| 41 SliderChangeReason reason) { | 40 SliderChangeReason reason) { |
| 42 label_->SetText(base::ASCIIToUTF16(base::StringPrintf("%.3lf", value))); | 41 label_->SetText(base::ASCIIToUTF16(base::StringPrintf("%.3lf", value))); |
| 43 } | 42 } |
| 44 | 43 |
| 45 } // namespace examples | 44 } // namespace examples |
| 46 } // namespace views | 45 } // namespace views |
| 47 | 46 |
| OLD | NEW |