diff options
author | crupest <crupest@outlook.com> | 2021-03-24 19:14:19 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2021-03-24 19:14:19 +0800 |
commit | 7f15a1ff9a2007e119798053083a0a87d042990a (patch) | |
tree | cb35c01a7eaee867376d959b96c9bbd15df939e5 /include/cru/ui/style/Styler.hpp | |
parent | 74956951ee663012df0c3fe4ebe29799cb2f7732 (diff) | |
parent | 7703063a5816b089483e78ccd74bb9902ccfbea8 (diff) | |
download | cru-7f15a1ff9a2007e119798053083a0a87d042990a.tar.gz cru-7f15a1ff9a2007e119798053083a0a87d042990a.tar.bz2 cru-7f15a1ff9a2007e119798053083a0a87d042990a.zip |
Merge branch 'master' of https://github.com/crupest/CruUI
Diffstat (limited to 'include/cru/ui/style/Styler.hpp')
-rw-r--r-- | include/cru/ui/style/Styler.hpp | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/include/cru/ui/style/Styler.hpp b/include/cru/ui/style/Styler.hpp new file mode 100644 index 00000000..865cbbaf --- /dev/null +++ b/include/cru/ui/style/Styler.hpp @@ -0,0 +1,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 |