aboutsummaryrefslogtreecommitdiff
path: root/include/cru/ui/style/Trigger.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'include/cru/ui/style/Trigger.hpp')
-rw-r--r--include/cru/ui/style/Trigger.hpp75
1 files changed, 75 insertions, 0 deletions
diff --git a/include/cru/ui/style/Trigger.hpp b/include/cru/ui/style/Trigger.hpp
new file mode 100644
index 00000000..ab012a3e
--- /dev/null
+++ b/include/cru/ui/style/Trigger.hpp
@@ -0,0 +1,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