blob: 4d90b9e804cee620a84e0167762de050878e6e49 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/views/examples/throbber_example.h"
#include <memory>
#include "base/macros.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/views/controls/throbber.h"
#include "ui/views/examples/grit/views_examples_resources.h"
#include "ui/views/layout/fill_layout.h"
#include "ui/views/view.h"
namespace views {
namespace examples {
namespace {
class ThrobberView : public View {
public:
ThrobberView() {
throbber_ = AddChildView(std::make_unique<Throbber>());
throbber_->Start();
}
// View::
gfx::Size CalculatePreferredSize() const override {
return gfx::Size(width(), height());
}
void Layout() override {
int diameter = 16;
throbber_->SetBounds((width() - diameter) / 2, (height() - diameter) / 2,
diameter, diameter);
SizeToPreferredSize();
}
bool OnMousePressed(const ui::MouseEvent& event) override {
if (GetEventHandlerForPoint(event.location()) != throbber_)
return false;
if (is_checked_)
throbber_->Start();
else
throbber_->Stop();
throbber_->SetChecked(!is_checked_);
is_checked_ = !is_checked_;
return true;
}
private:
Throbber* throbber_;
bool is_checked_ = false;
DISALLOW_COPY_AND_ASSIGN(ThrobberView);
};
} // namespace
ThrobberExample::ThrobberExample()
: ExampleBase(l10n_util::GetStringUTF8(IDS_THROBBER_SELECT_LABEL).c_str()) {
}
ThrobberExample::~ThrobberExample() = default;
void ThrobberExample::CreateExampleView(View* container) {
container->SetLayoutManager(std::make_unique<FillLayout>());
container->AddChildView(std::make_unique<ThrobberView>());
}
} // namespace examples
} // namespace views
|