diff options
author | crupest <crupest@outlook.com> | 2020-12-02 20:50:26 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-12-02 20:50:26 +0800 |
commit | c6baeb6432a4db7433aab4fc8f89cc235473f11a (patch) | |
tree | dee45567f87a33a52de752fbc234a7f09bd41245 /src/ui | |
parent | 7cb333e847eec701b0cb3577a84f0107a5be7602 (diff) | |
download | cru-c6baeb6432a4db7433aab4fc8f89cc235473f11a.tar.gz cru-c6baeb6432a4db7433aab4fc8f89cc235473f11a.tar.bz2 cru-c6baeb6432a4db7433aab4fc8f89cc235473f11a.zip |
...
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/ui/style/Condition.cpp | 17 | ||||
-rw-r--r-- | src/ui/style/StyleRule.cpp | 11 |
3 files changed, 28 insertions, 2 deletions
diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt index 03297988..e61ed7de 100644 --- a/src/ui/CMakeLists.txt +++ b/src/ui/CMakeLists.txt @@ -36,6 +36,7 @@ add_library(cru_ui STATIC render/TextRenderObject.cpp style/Condition.cpp style/Styler.cpp + style/StyleRule.cpp ) target_sources(cru_ui PUBLIC ${CRU_UI_INCLUDE_DIR}/Base.hpp @@ -77,5 +78,6 @@ target_sources(cru_ui PUBLIC ${CRU_UI_INCLUDE_DIR}/style/ApplyBorderStyleInfo.hpp ${CRU_UI_INCLUDE_DIR}/style/Condition.hpp ${CRU_UI_INCLUDE_DIR}/style/Styler.hpp + ${CRU_UI_INCLUDE_DIR}/style/StyleRule.hpp ) target_link_libraries(cru_ui PUBLIC cru_platform_gui) diff --git a/src/ui/style/Condition.cpp b/src/ui/style/Condition.cpp index bc24e265..2b51bde3 100644 --- a/src/ui/style/Condition.cpp +++ b/src/ui/style/Condition.cpp @@ -1,4 +1,5 @@ #include "cru/ui/style/Condition.hpp" +#include <memory> #include "cru/common/Event.hpp" #include "cru/ui/controls/Control.hpp" @@ -6,8 +7,11 @@ #include "cru/ui/helper/ClickDetector.hpp" namespace cru::ui::style { -CompoundCondition::CompoundCondition(std::vector<Condition*> conditions) - : conditions_(std::move(conditions)) {} +CompoundCondition::CompoundCondition( + std::vector<std::unique_ptr<Condition>> conditions) + : conditions_(std::move(conditions)) { + for (const auto& p : conditions_) readonly_conditions_.push_back(p.get()); +} std::vector<IBaseEvent*> CompoundCondition::ChangeOn( controls::Control* control) const { @@ -22,6 +26,15 @@ std::vector<IBaseEvent*> CompoundCondition::ChangeOn( return result; } +std::vector<std::unique_ptr<Condition>> CompoundCondition::CloneConditions() + const { + std::vector<std::unique_ptr<Condition>> result; + for (auto condition : GetConditions()) { + result.push_back(condition->Clone()); + } + return result; +} + bool AndCondition::Judge(controls::Control* control) const { for (auto condition : GetConditions()) { if (!condition->Judge(control)) return false; diff --git a/src/ui/style/StyleRule.cpp b/src/ui/style/StyleRule.cpp new file mode 100644 index 00000000..4a5ecf7e --- /dev/null +++ b/src/ui/style/StyleRule.cpp @@ -0,0 +1,11 @@ +#include "cru/ui/style/StyleRule.hpp" + +namespace cru::ui::style { +bool StyleRule::CheckAndApply(controls::Control *control) const { + auto active = condition_->Judge(control); + if (active) { + styler_->Apply(control); + } + return active; +} +} // namespace cru::ui::style |