From 9fcebe16b5ad4acc8b2e206dbe163e58b1f75cdf Mon Sep 17 00:00:00 2001 From: crupest Date: Wed, 9 Dec 2020 17:21:44 +0800 Subject: ... --- include/cru/ui/style/StyleRuleSet.hpp | 40 +++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) (limited to 'include/cru/ui/style') diff --git a/include/cru/ui/style/StyleRuleSet.hpp b/include/cru/ui/style/StyleRuleSet.hpp index 3ec71730..ba3f8b4c 100644 --- a/include/cru/ui/style/StyleRuleSet.hpp +++ b/include/cru/ui/style/StyleRuleSet.hpp @@ -2,13 +2,14 @@ #include "StyleRule.hpp" #include "cru/common/Base.hpp" #include "cru/common/Event.hpp" -#include "gsl/gsl_assert" + +#include namespace cru::ui::style { class StyleRuleSet : public Object { public: - StyleRuleSet() : control_(nullptr) {} - explicit StyleRuleSet(controls::Control* control) : control_(control) {} + StyleRuleSet() = default; + explicit StyleRuleSet(StyleRuleSet* parent); CRU_DELETE_COPY(StyleRuleSet) CRU_DELETE_MOVE(StyleRuleSet) @@ -16,6 +17,9 @@ class StyleRuleSet : public Object { ~StyleRuleSet() override = default; public: + StyleRuleSet* GetParent() const { return parent_; } + void SetParent(StyleRuleSet* parent); + gsl::index GetSize() const { return static_cast(rules_.size()); } const std::vector& GetRules() const { return rules_; } @@ -41,14 +45,42 @@ class StyleRuleSet : public Object { const StyleRule& operator[](gsl::index index) const { return rules_[index]; } + // Triggered whenever a change happened to this (rule add or remove, parent + // change ...). Subscribe to this and update style change listeners and style. + IEvent* ChangeEvent() { return &change_event_; } + + private: + void RaiseChangeEvent() { change_event_.Raise(nullptr); } + + private: + Event change_event_; + + StyleRuleSet* parent_ = nullptr; + EventRevokerGuard parent_change_event_guard_; + + std::vector rules_; +}; + +class StyleRuleSetBind { + public: + StyleRuleSetBind(controls::Control* control, StyleRuleSet* ruleset); + + CRU_DELETE_COPY(StyleRuleSetBind) + CRU_DELETE_MOVE(StyleRuleSetBind) + + ~StyleRuleSetBind() = default; + private: + void UpdateRuleSetChainCache(); void UpdateChangeListener(); void UpdateStyle(); private: controls::Control* control_; + StyleRuleSet* ruleset_; - std::vector rules_; + // child first, parent last. + std::vector ruleset_chain_cache_; EventRevokerListGuard guard_; }; -- cgit v1.2.3