aboutsummaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-12-03 20:51:53 +0800
committercrupest <crupest@outlook.com>2020-12-03 20:51:53 +0800
commit93a8bf8b967817031cd2798cdaedfa73f867dead (patch)
tree0e1a2a72ad0e07c0f670a6feb87f211929788f0e /src/ui
parentc6baeb6432a4db7433aab4fc8f89cc235473f11a (diff)
downloadcru-93a8bf8b967817031cd2798cdaedfa73f867dead.tar.gz
cru-93a8bf8b967817031cd2798cdaedfa73f867dead.tar.bz2
cru-93a8bf8b967817031cd2798cdaedfa73f867dead.zip
...
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/CMakeLists.txt2
-rw-r--r--src/ui/style/Condition.cpp22
-rw-r--r--src/ui/style/StyleRule.cpp6
-rw-r--r--src/ui/style/StyleRuleSet.cpp0
4 files changed, 14 insertions, 16 deletions
diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt
index e61ed7de..4964a1ae 100644
--- a/src/ui/CMakeLists.txt
+++ b/src/ui/CMakeLists.txt
@@ -37,6 +37,7 @@ add_library(cru_ui STATIC
style/Condition.cpp
style/Styler.cpp
style/StyleRule.cpp
+ style/StyleRuleSet.cpp
)
target_sources(cru_ui PUBLIC
${CRU_UI_INCLUDE_DIR}/Base.hpp
@@ -79,5 +80,6 @@ target_sources(cru_ui PUBLIC
${CRU_UI_INCLUDE_DIR}/style/Condition.hpp
${CRU_UI_INCLUDE_DIR}/style/Styler.hpp
${CRU_UI_INCLUDE_DIR}/style/StyleRule.hpp
+ ${CRU_UI_INCLUDE_DIR}/style/StyleRuleSet.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 2b51bde3..891eb062 100644
--- a/src/ui/style/Condition.cpp
+++ b/src/ui/style/Condition.cpp
@@ -1,6 +1,7 @@
#include "cru/ui/style/Condition.hpp"
#include <memory>
+#include "cru/common/ClonablePtr.hpp"
#include "cru/common/Event.hpp"
#include "cru/ui/controls/Control.hpp"
#include "cru/ui/controls/IClickableControl.hpp"
@@ -8,16 +9,14 @@
namespace cru::ui::style {
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<ClonablePtr<Condition>> conditions)
+ : conditions_(std::move(conditions)) {}
std::vector<IBaseEvent*> CompoundCondition::ChangeOn(
controls::Control* control) const {
std::vector<IBaseEvent*> result;
- for (auto condition : GetConditions()) {
+ for (auto condition : conditions_) {
for (auto e : condition->ChangeOn(control)) {
result.push_back(e);
}
@@ -26,24 +25,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()) {
+ for (auto condition : conditions_) {
if (!condition->Judge(control)) return false;
}
return true;
}
bool OrCondition::Judge(controls::Control* control) const {
- for (auto condition : GetConditions()) {
+ for (auto condition : conditions_) {
if (condition->Judge(control)) return true;
}
return false;
diff --git a/src/ui/style/StyleRule.cpp b/src/ui/style/StyleRule.cpp
index 4a5ecf7e..1a72a970 100644
--- a/src/ui/style/StyleRule.cpp
+++ b/src/ui/style/StyleRule.cpp
@@ -1,6 +1,12 @@
#include "cru/ui/style/StyleRule.hpp"
namespace cru::ui::style {
+StyleRule::StyleRule(ClonablePtr<Condition> condition,
+ ClonablePtr<Styler> styler, std::u16string name)
+ : condition_(std::move(condition)),
+ styler_(std::move(styler)),
+ name_(std::move(name)) {}
+
bool StyleRule::CheckAndApply(controls::Control *control) const {
auto active = condition_->Judge(control);
if (active) {
diff --git a/src/ui/style/StyleRuleSet.cpp b/src/ui/style/StyleRuleSet.cpp
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/src/ui/style/StyleRuleSet.cpp