aboutsummaryrefslogtreecommitdiff
path: root/include/cru/ui/style/Condition.hpp
blob: c4fd21067c11aaf5b9b17220e5f36f40088098ec (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
#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 <memory>
#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;

  virtual std::unique_ptr<Condition> Clone() const = 0;
};

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

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

  std::vector<std::unique_ptr<Condition>> CloneConditions() const;

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

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

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

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

  std::unique_ptr<Condition> Clone() const override {
    return std::make_unique<AndCondition>(CloneConditions());
  }
};

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

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

  std::unique_ptr<Condition> Clone() const override {
    return std::make_unique<OrCondition>(CloneConditions());
  }
};

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;

  std::unique_ptr<Condition> Clone() const override {
    return std::make_unique<FocusCondition>(has_focus_);
  }

 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;

  std::unique_ptr<Condition> Clone() const override {
    return std::make_unique<ClickStateCondition>(click_state_);
  }

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