From c6baeb6432a4db7433aab4fc8f89cc235473f11a Mon Sep 17 00:00:00 2001 From: crupest Date: Wed, 2 Dec 2020 20:50:26 +0800 Subject: ... --- include/cru/ui/style/Condition.hpp | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) (limited to 'include/cru/ui/style/Condition.hpp') diff --git a/include/cru/ui/style/Condition.hpp b/include/cru/ui/style/Condition.hpp index 97d29287..c4fd2106 100644 --- a/include/cru/ui/style/Condition.hpp +++ b/include/cru/ui/style/Condition.hpp @@ -5,6 +5,7 @@ #include "cru/ui/controls/IClickableControl.hpp" #include "cru/ui/helper/ClickDetector.hpp" +#include #include #include #include @@ -15,18 +16,26 @@ class Condition : public Object { virtual std::vector ChangeOn( controls::Control* control) const = 0; virtual bool Judge(controls::Control* control) const = 0; + + virtual std::unique_ptr Clone() const = 0; }; class CompoundCondition : public Condition { public: - explicit CompoundCondition(std::vector conditions); + explicit CompoundCondition( + std::vector> conditions); + + const std::vector& GetConditions() const { + return readonly_conditions_; + } - const std::vector& GetConditions() const { return conditions_; } + std::vector> CloneConditions() const; std::vector ChangeOn(controls::Control* control) const override; private: - std::vector conditions_; + std::vector> conditions_; + std::vector readonly_conditions_; }; class AndCondition : public CompoundCondition { @@ -34,6 +43,10 @@ class AndCondition : public CompoundCondition { using CompoundCondition::CompoundCondition; bool Judge(controls::Control* control) const override; + + std::unique_ptr Clone() const override { + return std::make_unique(CloneConditions()); + } }; class OrCondition : public CompoundCondition { @@ -41,6 +54,10 @@ class OrCondition : public CompoundCondition { using CompoundCondition::CompoundCondition; bool Judge(controls::Control* control) const override; + + std::unique_ptr Clone() const override { + return std::make_unique(CloneConditions()); + } }; class FocusCondition : public Condition { @@ -50,6 +67,10 @@ class FocusCondition : public Condition { std::vector ChangeOn(controls::Control* control) const override; bool Judge(controls::Control* control) const override; + std::unique_ptr Clone() const override { + return std::make_unique(has_focus_); + } + private: bool has_focus_; }; @@ -61,6 +82,10 @@ class ClickStateCondition : public Condition { std::vector ChangeOn(controls::Control* control) const override; bool Judge(controls::Control* control) const override; + std::unique_ptr Clone() const override { + return std::make_unique(click_state_); + } + private: helper::ClickState click_state_; }; -- cgit v1.2.3