aboutsummaryrefslogtreecommitdiff
path: root/include/cru/ui/style/Condition.hpp
blob: 97d29287a595cbf267b0a6188a5aa3eb9ad9abe4 (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
#pragma once
#include "../Base.hpp"
#include "cru/common/Base.hpp"
#include "cru/common/Event.hpp"
#include "cru/ui/controls/IClickableControl.hpp"
#include "cru/ui/helper/ClickDetector.hpp"

#include <type_traits>
#include <utility>
#include <vector>

namespace cru::ui::style {
class Condition : public Object {
 public:
  virtual std::vector<IBaseEvent*> ChangeOn(
      controls::Control* control) const = 0;
  virtual bool Judge(controls::Control* control) const = 0;
};

class CompoundCondition : public Condition {
 public:
  explicit CompoundCondition(std::vector<Condition*> conditions);

  const std::vector<Condition*>& GetConditions() const { return conditions_; }

  std::vector<IBaseEvent*> ChangeOn(controls::Control* control) const override;

 private:
  std::vector<Condition*> conditions_;
};

class AndCondition : public CompoundCondition {
 public:
  using CompoundCondition::CompoundCondition;

  bool Judge(controls::Control* control) const override;
};

class OrCondition : public CompoundCondition {
 public:
  using CompoundCondition::CompoundCondition;

  bool Judge(controls::Control* control) const override;
};

class FocusCondition : public Condition {
 public:
  explicit FocusCondition(bool has_focus);

  std::vector<IBaseEvent*> ChangeOn(controls::Control* control) const override;
  bool Judge(controls::Control* control) const override;

 private:
  bool has_focus_;
};

class ClickStateCondition : public Condition {
 public:
  explicit ClickStateCondition(helper::ClickState click_state);

  std::vector<IBaseEvent*> ChangeOn(controls::Control* control) const override;
  bool Judge(controls::Control* control) const override;

 private:
  helper::ClickState click_state_;
};
}  // namespace cru::ui::style