From 74bb9cd27242b9320f99ff4d2b50c3051576cc14 Mon Sep 17 00:00:00 2001 From: crupest Date: Tue, 8 Feb 2022 16:53:51 +0800 Subject: ... --- include/cru/ui/style/Styler.h | 90 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 include/cru/ui/style/Styler.h (limited to 'include/cru/ui/style/Styler.h') 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 +#include + +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 + static ClonablePtr Create(ClonablePtr... s) { + return ClonablePtr( + new CompoundStyler(std::vector>{std::move(s)...})); + } + + static ClonablePtr Create( + std::vector> stylers) { + return ClonablePtr(new CompoundStyler(std::move(stylers))); + } + + explicit CompoundStyler(std::vector> 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> stylers_; +}; + +class BorderStyler : public Styler { + public: + static ClonablePtr Create() { + return ClonablePtr(new BorderStyler()); + } + + static ClonablePtr Create(ApplyBorderStyleInfo style) { + return ClonablePtr(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 Create( + std::shared_ptr cursor) { + return ClonablePtr(new CursorStyler(std::move(cursor))); + } + + static ClonablePtr Create(platform::gui::SystemCursorType type); + + explicit CursorStyler(std::shared_ptr cursor) + : cursor_(std::move(cursor)) {} + + void Apply(controls::Control* control) const override; + + CursorStyler* Clone() const override { return new CursorStyler(cursor_); } + + private: + std::shared_ptr cursor_; +}; +} // namespace cru::ui::style -- cgit v1.2.3