aboutsummaryrefslogtreecommitdiff
path: root/include/cru/ui/style/StyleRule.hpp
blob: f1283e24deb4b6033ef8fc26e820bc6ac440bff2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#pragma once
#include "Condition.hpp"
#include "Styler.hpp"
#include "cru/common/Base.hpp"
#include "cru/ui/Base.hpp"

#include <memory>
#include <string>
#include <vector>

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;
  }

  CRU_DEFAULT_MOVE(StyleRule)

  ~StyleRule() override = default;

 public:
  const std::u16string& GetName() const { return name_; }
  Condition* GetCondition() const { return condition_.get(); }
  Styler* GetStyler() const { return styler_.get(); }

  StyleRule WithNewCondition(std::unique_ptr<Condition> condition,
                             std::u16string name = {}) const {
    return StyleRule{std::move(condition), styler_->Clone(), std::move(name)};
  }

  StyleRule WithNewStyler(std::unique_ptr<Styler> styler,
                          std::u16string name = {}) const {
    return StyleRule{condition_->Clone(), std::move(styler), std::move(name)};
  }

  bool CheckAndApply(controls::Control* control) const;

 private:
  std::unique_ptr<Condition> condition_;
  std::unique_ptr<Styler> styler_;
  std::u16string name_;
};
}  // namespace cru::ui::style