aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2022-03-04 21:26:48 +0800
committercrupest <crupest@outlook.com>2022-03-04 21:26:48 +0800
commit221f9cd7e453f2968c12a14a46588ea50ca2119d (patch)
tree278a2ade6817b1656d89051aaae5b26658112a4c
parenta0732c3aa32d200bf154d486df3c9f506161954f (diff)
downloadcru-221f9cd7e453f2968c12a14a46588ea50ca2119d.tar.gz
cru-221f9cd7e453f2968c12a14a46588ea50ca2119d.tar.bz2
cru-221f9cd7e453f2968c12a14a46588ea50ca2119d.zip
...
-rw-r--r--include/cru/ui/style/Styler.h45
-rw-r--r--src/ui/style/Styler.cpp15
2 files changed, 60 insertions, 0 deletions
diff --git a/include/cru/ui/style/Styler.h b/include/cru/ui/style/Styler.h
index e2e05c5b..f4f66ea0 100644
--- a/include/cru/ui/style/Styler.h
+++ b/include/cru/ui/style/Styler.h
@@ -2,6 +2,7 @@
#include "../Base.h"
#include "ApplyBorderStyleInfo.h"
#include "cru/common/ClonablePtr.h"
+#include "cru/platform/graphics/Brush.h"
#include "cru/platform/gui/Cursor.h"
#include "cru/ui/render/MeasureRequirement.h"
@@ -149,4 +150,48 @@ class CRU_UI_API PaddingStyler : public Styler {
Thickness padding_;
};
+class CRU_UI_API ContentBrushStyler : public Styler {
+ public:
+ static ClonablePtr<ContentBrushStyler> Create(
+ std::shared_ptr<platform::graphics::IBrush> brush) {
+ return ClonablePtr<ContentBrushStyler>(
+ new ContentBrushStyler(std::move(brush)));
+ }
+
+ explicit ContentBrushStyler(std::shared_ptr<platform::graphics::IBrush> brush)
+ : brush_(std::move(brush)) {}
+
+ void Apply(controls::Control* control) const override;
+
+ ContentBrushStyler* Clone() const override {
+ return new ContentBrushStyler(brush_);
+ }
+
+ std::shared_ptr<platform::graphics::IBrush> GetBrush() const {
+ return brush_;
+ }
+
+ private:
+ std::shared_ptr<platform::graphics::IBrush> brush_;
+};
+
+class CRU_UI_API FontStyler : public Styler {
+ public:
+ static ClonablePtr<FontStyler> Create(
+ std::shared_ptr<platform::graphics::IFont> font) {
+ return ClonablePtr<FontStyler>(new FontStyler(std::move(font)));
+ }
+
+ explicit FontStyler(std::shared_ptr<platform::graphics::IFont> font)
+ : font_(std::move(font)) {}
+
+ void Apply(controls::Control* control) const override;
+
+ FontStyler* Clone() const override { return new FontStyler(font_); }
+
+ std::shared_ptr<platform::graphics::IFont> GetFont() const { return font_; }
+
+ private:
+ std::shared_ptr<platform::graphics::IFont> font_;
+};
} // namespace cru::ui::style
diff --git a/src/ui/style/Styler.cpp b/src/ui/style/Styler.cpp
index 44a24462..3d7ff1f9 100644
--- a/src/ui/style/Styler.cpp
+++ b/src/ui/style/Styler.cpp
@@ -6,6 +6,8 @@
#include "cru/platform/gui/UiApplication.h"
#include "cru/ui/controls/Control.h"
#include "cru/ui/controls/IBorderControl.h"
+#include "cru/ui/controls/IContentBrushControl.h"
+#include "cru/ui/controls/IFontControl.h"
#include "cru/ui/style/ApplyBorderStyleInfo.h"
namespace cru::ui::style {
@@ -38,4 +40,17 @@ void MarginStyler::Apply(controls::Control *control) const {
void PaddingStyler::Apply(controls::Control *control) const {
control->SetPadding(padding_);
}
+
+void ContentBrushStyler::Apply(controls::Control *control) const {
+ if (auto content_brush_control =
+ dynamic_cast<controls::IContentBrushControl *>(control)) {
+ content_brush_control->SetContentBrush(brush_);
+ }
+}
+
+void FontStyler::Apply(controls::Control *control) const {
+ if (auto font_control = dynamic_cast<controls::IFontControl *>(control)) {
+ font_control->SetFont(font_);
+ }
+}
} // namespace cru::ui::style