blob: 6f84329f11d990697d949fe7678fc6f224ad4247 (
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
#pragma once
#include "../Base.h"
#include "ApplyBorderStyleInfo.h"
#include "cru/common/ClonablePtr.h"
#include "cru/platform/gui/Cursor.h"
#include <memory>
#include <vector>
namespace cru::ui::style {
class Styler : public Object {
public:
virtual void Apply(controls::Control* control) const = 0;
virtual Styler* Clone() const = 0;
};
class CompoundStyler : public Styler {
public:
template <typename... S>
static ClonablePtr<CompoundStyler> Create(ClonablePtr<S>... s) {
return ClonablePtr<CompoundStyler>(
new CompoundStyler(std::vector<ClonablePtr<Styler>>{std::move(s)...}));
}
static ClonablePtr<CompoundStyler> Create(
std::vector<ClonablePtr<Styler>> stylers) {
return ClonablePtr<CompoundStyler>(new CompoundStyler(std::move(stylers)));
}
explicit CompoundStyler(std::vector<ClonablePtr<Styler>> stylers)
: stylers_(std::move(stylers)) {}
void Apply(controls::Control* control) const override {
for (const auto& styler : stylers_) {
styler->Apply(control);
}
}
virtual CompoundStyler* Clone() const override {
return new CompoundStyler(stylers_);
}
private:
std::vector<ClonablePtr<Styler>> stylers_;
};
class BorderStyler : public Styler {
public:
static ClonablePtr<BorderStyler> Create() {
return ClonablePtr<BorderStyler>(new BorderStyler());
}
static ClonablePtr<BorderStyler> Create(ApplyBorderStyleInfo style) {
return ClonablePtr<BorderStyler>(new BorderStyler(std::move(style)));
}
BorderStyler() = default;
explicit BorderStyler(ApplyBorderStyleInfo style);
void Apply(controls::Control* control) const override;
BorderStyler* Clone() const override { return new BorderStyler(style_); }
private:
ApplyBorderStyleInfo style_;
};
class CursorStyler : public Styler {
public:
static ClonablePtr<CursorStyler> Create(
std::shared_ptr<platform::gui::ICursor> cursor) {
return ClonablePtr<CursorStyler>(new CursorStyler(std::move(cursor)));
}
static ClonablePtr<CursorStyler> Create(platform::gui::SystemCursorType type);
explicit CursorStyler(std::shared_ptr<platform::gui::ICursor> cursor)
: cursor_(std::move(cursor)) {}
void Apply(controls::Control* control) const override;
CursorStyler* Clone() const override { return new CursorStyler(cursor_); }
private:
std::shared_ptr<platform::gui::ICursor> cursor_;
};
} // namespace cru::ui::style
|