diff options
author | crupest <crupest@outlook.com> | 2020-12-03 20:51:53 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-12-03 20:51:53 +0800 |
commit | 93a8bf8b967817031cd2798cdaedfa73f867dead (patch) | |
tree | 0e1a2a72ad0e07c0f670a6feb87f211929788f0e /include/cru/ui | |
parent | c6baeb6432a4db7433aab4fc8f89cc235473f11a (diff) | |
download | cru-93a8bf8b967817031cd2798cdaedfa73f867dead.tar.gz cru-93a8bf8b967817031cd2798cdaedfa73f867dead.tar.bz2 cru-93a8bf8b967817031cd2798cdaedfa73f867dead.zip |
...
Diffstat (limited to 'include/cru/ui')
-rw-r--r-- | include/cru/ui/style/Condition.hpp | 33 | ||||
-rw-r--r-- | include/cru/ui/style/StyleRule.hpp | 32 | ||||
-rw-r--r-- | include/cru/ui/style/StyleRuleSet.hpp | 0 | ||||
-rw-r--r-- | include/cru/ui/style/Styler.hpp | 6 |
4 files changed, 23 insertions, 48 deletions
diff --git a/include/cru/ui/style/Condition.hpp b/include/cru/ui/style/Condition.hpp index c4fd2106..13ab7764 100644 --- a/include/cru/ui/style/Condition.hpp +++ b/include/cru/ui/style/Condition.hpp @@ -1,6 +1,7 @@ #pragma once #include "../Base.hpp" #include "cru/common/Base.hpp" +#include "cru/common/ClonablePtr.hpp" #include "cru/common/Event.hpp" #include "cru/ui/controls/IClickableControl.hpp" #include "cru/ui/helper/ClickDetector.hpp" @@ -17,25 +18,17 @@ class Condition : public Object { controls::Control* control) const = 0; virtual bool Judge(controls::Control* control) const = 0; - virtual std::unique_ptr<Condition> Clone() const = 0; + virtual 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; + explicit CompoundCondition(std::vector<ClonablePtr<Condition>> conditions); std::vector<IBaseEvent*> ChangeOn(controls::Control* control) const override; - private: - std::vector<std::unique_ptr<Condition>> conditions_; - std::vector<Condition*> readonly_conditions_; + protected: + std::vector<ClonablePtr<Condition>> conditions_; }; class AndCondition : public CompoundCondition { @@ -44,9 +37,7 @@ class AndCondition : public CompoundCondition { bool Judge(controls::Control* control) const override; - std::unique_ptr<Condition> Clone() const override { - return std::make_unique<AndCondition>(CloneConditions()); - } + AndCondition* Clone() const override { return new AndCondition(conditions_); } }; class OrCondition : public CompoundCondition { @@ -55,9 +46,7 @@ class OrCondition : public CompoundCondition { bool Judge(controls::Control* control) const override; - std::unique_ptr<Condition> Clone() const override { - return std::make_unique<OrCondition>(CloneConditions()); - } + OrCondition* Clone() const override { return new OrCondition(conditions_); } }; class FocusCondition : public Condition { @@ -67,8 +56,8 @@ class FocusCondition : public Condition { 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_); + FocusCondition* Clone() const override { + return new FocusCondition(has_focus_); } private: @@ -82,8 +71,8 @@ class ClickStateCondition : public Condition { 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_); + ClickStateCondition* Clone() const override { + return new ClickStateCondition(click_state_); } private: diff --git a/include/cru/ui/style/StyleRule.hpp b/include/cru/ui/style/StyleRule.hpp index f1283e24..8ac42cd0 100644 --- a/include/cru/ui/style/StyleRule.hpp +++ b/include/cru/ui/style/StyleRule.hpp @@ -2,6 +2,7 @@ #include "Condition.hpp" #include "Styler.hpp" #include "cru/common/Base.hpp" +#include "cru/common/ClonablePtr.hpp" #include "cru/ui/Base.hpp" #include <memory> @@ -11,23 +12,10 @@ namespace cru::ui::style { class StyleRule : public Object { public: - StyleRule(std::unique_ptr<Condition> condition, - std::unique_ptr<Styler> styler, std::u16string name = {}); - - StyleRule(const StyleRule& other) - : condition_(other.condition_->Clone()), - styler_(other.styler_->Clone()), - name_(other.name_) {} - - StyleRule& operator=(const StyleRule& other) { - if (this != &other) { - condition_ = other.condition_->Clone(); - styler_ = other.styler_->Clone(); - name_ = other.name_; - } - return *this; - } + StyleRule(ClonablePtr<Condition> condition, ClonablePtr<Styler> styler, + std::u16string name = {}); + CRU_DEFAULT_COPY(StyleRule) CRU_DEFAULT_MOVE(StyleRule) ~StyleRule() override = default; @@ -37,21 +25,21 @@ class StyleRule : public Object { Condition* GetCondition() const { return condition_.get(); } Styler* GetStyler() const { return styler_.get(); } - StyleRule WithNewCondition(std::unique_ptr<Condition> condition, + StyleRule WithNewCondition(ClonablePtr<Condition> condition, std::u16string name = {}) const { - return StyleRule{std::move(condition), styler_->Clone(), std::move(name)}; + return StyleRule{std::move(condition), styler_, std::move(name)}; } - StyleRule WithNewStyler(std::unique_ptr<Styler> styler, + StyleRule WithNewStyler(ClonablePtr<Styler> styler, std::u16string name = {}) const { - return StyleRule{condition_->Clone(), std::move(styler), std::move(name)}; + return StyleRule{condition_, std::move(styler), std::move(name)}; } bool CheckAndApply(controls::Control* control) const; private: - std::unique_ptr<Condition> condition_; - std::unique_ptr<Styler> styler_; + ClonablePtr<Condition> condition_; + ClonablePtr<Styler> styler_; std::u16string name_; }; } // namespace cru::ui::style diff --git a/include/cru/ui/style/StyleRuleSet.hpp b/include/cru/ui/style/StyleRuleSet.hpp new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/include/cru/ui/style/StyleRuleSet.hpp diff --git a/include/cru/ui/style/Styler.hpp b/include/cru/ui/style/Styler.hpp index 4f4b18ba..2aece114 100644 --- a/include/cru/ui/style/Styler.hpp +++ b/include/cru/ui/style/Styler.hpp @@ -10,7 +10,7 @@ class Styler : public Object { public: virtual void Apply(controls::Control* control) const; - virtual std::unique_ptr<Styler> Clone() const = 0; + virtual Styler* Clone() const = 0; }; class BorderStyler : public Styler { @@ -19,9 +19,7 @@ class BorderStyler : public Styler { void Apply(controls::Control* control) const override; - std::unique_ptr<Styler> Clone() const override { - return std::make_unique<BorderStyler>(style_); - } + BorderStyler* Clone() const override { return new BorderStyler(style_); } private: ApplyBorderStyleInfo style_; |