aboutsummaryrefslogtreecommitdiff
path: root/include/cru/ui/style/Styler.h
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2022-02-08 16:53:51 +0800
committercrupest <crupest@outlook.com>2022-02-08 16:53:51 +0800
commit74bb9cd27242b9320f99ff4d2b50c3051576cc14 (patch)
tree744bac5799c593d1d6f81e7b09581bea626f2cde /include/cru/ui/style/Styler.h
parentb90c398de829d1ba5329651d75bae82f5e4085fe (diff)
downloadcru-74bb9cd27242b9320f99ff4d2b50c3051576cc14.tar.gz
cru-74bb9cd27242b9320f99ff4d2b50c3051576cc14.tar.bz2
cru-74bb9cd27242b9320f99ff4d2b50c3051576cc14.zip
...
Diffstat (limited to 'include/cru/ui/style/Styler.h')
-rw-r--r--include/cru/ui/style/Styler.h90
1 files changed, 90 insertions, 0 deletions
diff --git a/include/cru/ui/style/Styler.h b/include/cru/ui/style/Styler.h
new file mode 100644
index 00000000..9bdec294
--- /dev/null
+++ b/include/cru/ui/style/Styler.h
@@ -0,0 +1,90 @@
+#pragma once
+#include "../Base.h"
+#include "ApplyBorderStyleInfo.h"
+#include "cru/common/Base.h"
+#include "cru/common/ClonablePtr.h"
+#include "cru/platform/gui/Cursor.h"
+#include "cru/ui/controls/Control.h"
+
+#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)...}));
+ }
+
+ static ClonablePtr<CompoundStyler> Create(
+ std::vector<ClonablePtr<Styler>> stylers) {
+ return ClonablePtr<CompoundStyler>(new CompoundStyler(std::move(stylers)));
+ }
+
+ 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() {
+ return ClonablePtr<BorderStyler>(new BorderStyler());
+ }
+
+ static ClonablePtr<BorderStyler> Create(ApplyBorderStyleInfo style) {
+ return ClonablePtr<BorderStyler>(new BorderStyler(std::move(style)));
+ }
+
+ BorderStyler() = default;
+ 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