blob: e9b0e9d57604e918ea56fbda6d32ca452be7a9d8 (
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
#pragma once
#include "../Base.h"
#include "cru/base/Base.h"
#include "cru/base/ClonePtr.h"
#include "cru/base/Event.h"
#include "cru/ui/controls/IClickableControl.h"
#include "cru/ui/helper/ClickDetector.h"
#include <memory>
#include <type_traits>
#include <utility>
#include <vector>
namespace cru::ui::style {
class CRU_UI_API Condition : public Object {
public:
virtual std::vector<IBaseEvent*> ChangeOn(
controls::Control* control) const = 0;
virtual bool Judge(controls::Control* control) const = 0;
virtual Condition* Clone() const = 0;
};
class CRU_UI_API NoCondition : public Condition {
public:
static ClonePtr<NoCondition> Create() {
return ClonePtr<NoCondition>(new NoCondition);
};
std::vector<IBaseEvent*> ChangeOn(controls::Control*) const override {
return {};
}
bool Judge(controls::Control*) const override { return true; }
NoCondition* Clone() const override { return new NoCondition; }
};
class CRU_UI_API CompoundCondition : public Condition {
public:
explicit CompoundCondition(std::vector<ClonePtr<Condition>> conditions);
std::vector<IBaseEvent*> ChangeOn(controls::Control* control) const override;
std::vector<ClonePtr<Condition>> GetChildren() const {
return conditions_;
}
protected:
std::vector<ClonePtr<Condition>> conditions_;
};
class CRU_UI_API AndCondition : public CompoundCondition {
public:
static ClonePtr<AndCondition> Create(
std::vector<ClonePtr<Condition>> conditions) {
return ClonePtr<AndCondition>(new AndCondition(std::move(conditions)));
}
using CompoundCondition::CompoundCondition;
bool Judge(controls::Control* control) const override;
AndCondition* Clone() const override { return new AndCondition(conditions_); }
};
class CRU_UI_API OrCondition : public CompoundCondition {
public:
static ClonePtr<OrCondition> Create(
std::vector<ClonePtr<Condition>> conditions) {
return ClonePtr<OrCondition>(new OrCondition(std::move(conditions)));
}
using CompoundCondition::CompoundCondition;
bool Judge(controls::Control* control) const override;
OrCondition* Clone() const override { return new OrCondition(conditions_); }
};
class CRU_UI_API FocusCondition : public Condition {
public:
static ClonePtr<FocusCondition> Create(bool has_focus) {
return ClonePtr<FocusCondition>(new FocusCondition(has_focus));
}
explicit FocusCondition(bool has_focus);
std::vector<IBaseEvent*> ChangeOn(controls::Control* control) const override;
bool Judge(controls::Control* control) const override;
FocusCondition* Clone() const override {
return new FocusCondition(has_focus_);
}
bool IsHasFocus() const { return has_focus_; }
private:
bool has_focus_;
};
class CRU_UI_API HoverCondition : public Condition {
public:
static ClonePtr<HoverCondition> Create(bool hover) {
return ClonePtr<HoverCondition>(new HoverCondition(hover));
}
explicit HoverCondition(bool hover) : hover_(hover) {}
std::vector<IBaseEvent*> ChangeOn(controls::Control* control) const override;
bool Judge(controls::Control* control) const override;
HoverCondition* Clone() const override { return new HoverCondition(hover_); }
private:
bool hover_;
};
class CRU_UI_API ClickStateCondition : public Condition {
public:
static ClonePtr<ClickStateCondition> Create(
helper::ClickState click_state) {
return ClonePtr<ClickStateCondition>(
new ClickStateCondition(click_state));
}
explicit ClickStateCondition(helper::ClickState click_state);
std::vector<IBaseEvent*> ChangeOn(controls::Control* control) const override;
bool Judge(controls::Control* control) const override;
ClickStateCondition* Clone() const override {
return new ClickStateCondition(click_state_);
}
helper::ClickState GetClickState() const { return click_state_; }
private:
helper::ClickState click_state_;
};
class CRU_UI_API CheckedCondition : public Condition {
public:
static ClonePtr<CheckedCondition> Create(bool checked) {
return ClonePtr<CheckedCondition>(new CheckedCondition(checked));
}
explicit CheckedCondition(bool checked);
std::vector<IBaseEvent*> ChangeOn(controls::Control* control) const override;
bool Judge(controls::Control* control) const override;
CheckedCondition* Clone() const override {
return new CheckedCondition(checked_);
}
bool IsChecked() const { return checked_; }
private:
bool checked_;
};
} // namespace cru::ui::style
|