OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/throbber_example.h" | 5 #include "ui/views/examples/throbber_example.h" |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "ui/views/controls/throbber.h" | 8 #include "ui/views/controls/throbber.h" |
9 #include "ui/views/layout/fill_layout.h" | 9 #include "ui/views/layout/fill_layout.h" |
10 #include "ui/views/view.h" | 10 #include "ui/views/view.h" |
11 | 11 |
12 namespace views { | 12 namespace views { |
13 namespace examples { | 13 namespace examples { |
14 | 14 |
15 namespace { | 15 namespace { |
16 | 16 |
17 class ThrobberView : public View { | 17 class ThrobberView : public View { |
18 public: | 18 public: |
19 ThrobberView() : throbber_(new Throbber()) { | 19 ThrobberView() : throbber_(new Throbber()), is_checked_(false) { |
20 AddChildView(throbber_); | 20 AddChildView(throbber_); |
21 throbber_->Start(); | 21 throbber_->Start(); |
22 } | 22 } |
23 | 23 |
24 // View implementation. | |
tdanderson
2016/09/19 23:32:27
nit: Just "// View:"
yiyix
2016/09/21 17:10:48
Done.
| |
24 gfx::Size GetPreferredSize() const override { | 25 gfx::Size GetPreferredSize() const override { |
25 return gfx::Size(width(), height()); | 26 return gfx::Size(width(), height()); |
26 } | 27 } |
27 | 28 |
28 void Layout() override { | 29 void Layout() override { |
29 int diameter = 64; | 30 int diameter = 16; |
30 throbber_->SetBounds((width() - diameter) / 2, | 31 throbber_->SetBounds((width() - diameter) / 2, |
31 (height() - diameter) / 2, | 32 (height() - diameter) / 2, |
32 diameter, diameter); | 33 diameter, diameter); |
33 SizeToPreferredSize(); | 34 SizeToPreferredSize(); |
34 } | 35 } |
35 | 36 |
37 bool OnMousePressed(const ui::MouseEvent& event) override { | |
38 if (GetEventHandlerForPoint(event.location()) == throbber_) { | |
39 if (is_checked_) { | |
40 throbber_->Start(); | |
41 throbber_->SetChecked(false); | |
42 is_checked_ = false; | |
43 } else { | |
44 throbber_->Stop(); | |
45 throbber_->SetChecked(true); | |
46 is_checked_ = true; | |
tdanderson
2016/09/19 23:32:27
You can avoid duplicated code with:
throbber->Set
yiyix
2016/09/21 17:10:48
Thanks, I thought about it, then i don't know how
| |
47 } | |
48 return true; | |
49 } | |
50 return false; | |
51 } | |
52 | |
36 private: | 53 private: |
37 Throbber* throbber_; | 54 Throbber* throbber_; |
55 bool is_checked_; | |
38 | 56 |
39 DISALLOW_COPY_AND_ASSIGN(ThrobberView); | 57 DISALLOW_COPY_AND_ASSIGN(ThrobberView); |
40 }; | 58 }; |
41 | 59 |
42 } // namespace | 60 } // namespace |
43 | 61 |
44 ThrobberExample::ThrobberExample() : ExampleBase("Throbber") { | 62 ThrobberExample::ThrobberExample() : ExampleBase("Throbber") { |
45 } | 63 } |
46 | 64 |
47 ThrobberExample::~ThrobberExample() { | 65 ThrobberExample::~ThrobberExample() { |
48 } | 66 } |
49 | 67 |
50 void ThrobberExample::CreateExampleView(View* container) { | 68 void ThrobberExample::CreateExampleView(View* container) { |
51 container->SetLayoutManager(new FillLayout()); | 69 container->SetLayoutManager(new FillLayout()); |
52 container->AddChildView(new ThrobberView()); | 70 container->AddChildView(new ThrobberView()); |
53 } | 71 } |
54 | 72 |
55 } // namespace examples | 73 } // namespace examples |
56 } // namespace views | 74 } // namespace views |
OLD | NEW |