blob: 865cbbaf12bca48b90aaf8ef6d4bd2bfc2ad1601 (
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
 | #pragma once
#include "../Base.hpp"
#include "ApplyBorderStyleInfo.hpp"
#include "cru/common/Base.hpp"
#include "cru/common/ClonablePtr.hpp"
#include "cru/platform/gui/Cursor.hpp"
#include "cru/ui/controls/Control.hpp"
#include <memory>
#include <vector>
namespace cru::ui::style {
class Styler : public Object {
 public:
  virtual void Apply(controls::Control* control) const = 0;
  virtual Styler* Clone() const = 0;
};
class CompoundStyler : public Styler {
 public:
  template <typename... S>
  static ClonablePtr<CompoundStyler> Create(ClonablePtr<S>... s) {
    return ClonablePtr<CompoundStyler>(
        new CompoundStyler(std::vector<ClonablePtr<Styler>>{std::move(s)...}));
  }
  explicit CompoundStyler(std::vector<ClonablePtr<Styler>> stylers)
      : stylers_(std::move(stylers)) {}
  void Apply(controls::Control* control) const override {
    for (const auto& styler : stylers_) {
      styler->Apply(control);
    }
  }
  virtual CompoundStyler* Clone() const override {
    return new CompoundStyler(stylers_);
  }
 private:
  std::vector<ClonablePtr<Styler>> stylers_;
};
class BorderStyler : public Styler {
 public:
  static ClonablePtr<BorderStyler> Create(ApplyBorderStyleInfo style) {
    return ClonablePtr<BorderStyler>(new BorderStyler(std::move(style)));
  }
  explicit BorderStyler(ApplyBorderStyleInfo style);
  void Apply(controls::Control* control) const override;
  BorderStyler* Clone() const override { return new BorderStyler(style_); }
 private:
  ApplyBorderStyleInfo style_;
};
class CursorStyler : public Styler {
 public:
  static ClonablePtr<CursorStyler> Create(
      std::shared_ptr<platform::gui::ICursor> cursor) {
    return ClonablePtr<CursorStyler>(new CursorStyler(std::move(cursor)));
  }
  static ClonablePtr<CursorStyler> Create(platform::gui::SystemCursorType type);
  explicit CursorStyler(std::shared_ptr<platform::gui::ICursor> cursor)
      : cursor_(std::move(cursor)) {}
  void Apply(controls::Control* control) const override;
  CursorStyler* Clone() const override { return new CursorStyler(cursor_); }
 private:
  std::shared_ptr<platform::gui::ICursor> cursor_;
};
}  // namespace cru::ui::style
 |