aboutsummaryrefslogtreecommitdiff
path: root/include/cru/ui/style/Trigger.hpp
blob: ab012a3ec1e3cbdbd0f6195027708ed6aaa3c054 (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
#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 <utility>
#include <vector>

namespace cru::ui::style {
class Trigger {
 public:
  virtual ~Trigger() = default;

  bool GetState() const { return current_; }
  IEvent<bool>* ChangeEvent() { return &change_event_; }

 protected:
  void Raise(bool value);

 private:
  bool current_ = false;
  Event<bool> change_event_;

 protected:
  EventRevokerListGuard guard_;
};

class CompoundTrigger : public Trigger {
 public:
  explicit CompoundTrigger(std::vector<Trigger*> triggers);

  const std::vector<Trigger*>& GetTriggers() const { return triggers_; }

 protected:
  virtual bool CalculateState(const std::vector<Trigger*>& triggers) const = 0;

 private:
  std::vector<Trigger*> triggers_;
};

class AndTrigger : public CompoundTrigger {
 public:
  using CompoundTrigger::CompoundTrigger;

 protected:
  bool CalculateState(const std::vector<Trigger*>& triggers) const override;
};

class OrTrigger : public CompoundTrigger {
 public:
  using CompoundTrigger::CompoundTrigger;

 protected:
  bool CalculateState(const std::vector<Trigger*>& triggers) const override;
};

class FocusTrigger : public Trigger {
 public:
  FocusTrigger(controls::Control* control, bool has_focus);

 private:
  bool has_focus_;
};

class ClickStateTrigger : public Trigger {
 public:
  ClickStateTrigger(controls::IClickableControl* control,
                    helper::ClickState click_state);

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