diff options
author | crupest <crupest@outlook.com> | 2020-12-02 19:19:22 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-12-02 19:19:22 +0800 |
commit | 145cfd5b82d76e0c937eceda707aa22427899943 (patch) | |
tree | ab98708eea0e0ba7b965e20927303e49a8d9ae23 /src/ui/style/Condition.cpp | |
parent | 0fb7a0e0b2b9e04ca414b1e47c69cc854c79831b (diff) | |
download | cru-145cfd5b82d76e0c937eceda707aa22427899943.tar.gz cru-145cfd5b82d76e0c937eceda707aa22427899943.tar.bz2 cru-145cfd5b82d76e0c937eceda707aa22427899943.zip |
...
Diffstat (limited to 'src/ui/style/Condition.cpp')
-rw-r--r-- | src/ui/style/Condition.cpp | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/src/ui/style/Condition.cpp b/src/ui/style/Condition.cpp new file mode 100644 index 00000000..bc24e265 --- /dev/null +++ b/src/ui/style/Condition.cpp @@ -0,0 +1,71 @@ +#include "cru/ui/style/Condition.hpp" + +#include "cru/common/Event.hpp" +#include "cru/ui/controls/Control.hpp" +#include "cru/ui/controls/IClickableControl.hpp" +#include "cru/ui/helper/ClickDetector.hpp" + +namespace cru::ui::style { +CompoundCondition::CompoundCondition(std::vector<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 e : condition->ChangeOn(control)) { + result.push_back(e); + } + } + + return result; +} + +bool AndCondition::Judge(controls::Control* control) const { + for (auto condition : GetConditions()) { + if (!condition->Judge(control)) return false; + } + return true; +} + +bool OrCondition::Judge(controls::Control* control) const { + for (auto condition : GetConditions()) { + if (condition->Judge(control)) return true; + } + return false; +} + +FocusCondition::FocusCondition(bool has_focus) : has_focus_(has_focus) {} + +std::vector<IBaseEvent*> FocusCondition::ChangeOn( + controls::Control* control) const { + return {control->GainFocusEvent()->Direct(), + control->LoseFocusEvent()->Direct()}; +} + +bool FocusCondition::Judge(controls::Control* control) const { + return control->HasFocus() == has_focus_; +} + +ClickStateCondition::ClickStateCondition(helper::ClickState click_state) + : click_state_(click_state) {} + +std::vector<IBaseEvent*> ClickStateCondition::ChangeOn( + controls::Control* control) const { + auto clickable_control = dynamic_cast<controls::IClickableControl*>(control); + if (clickable_control) { + return {clickable_control->ClickStateChangeEvent()}; + } else { + return {}; + } +} + +bool ClickStateCondition::Judge(controls::Control* control) const { + auto clickable_control = dynamic_cast<controls::IClickableControl*>(control); + if (clickable_control) { + return clickable_control->GetClickState() == click_state_; + } + return false; +} +} // namespace cru::ui::style |