From d7dca1be0dd0814e30fa63924a20af3d924e974c Mon Sep 17 00:00:00 2001 From: crupest Date: Wed, 2 Dec 2020 19:38:25 +0800 Subject: ... --- include/cru/ui/controls/Button.hpp | 8 +++++++- include/cru/ui/controls/IBorderControl.hpp | 10 ++++++++++ include/cru/ui/render/BorderRenderObject.hpp | 4 ++++ include/cru/ui/style/ApplyBorderStyleInfo.hpp | 12 ++++++++++++ include/cru/ui/style/Condition.hpp | 4 +--- include/cru/ui/style/Styler.hpp | 13 +++++++++++++ 6 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 include/cru/ui/controls/IBorderControl.hpp create mode 100644 include/cru/ui/style/ApplyBorderStyleInfo.hpp (limited to 'include/cru') diff --git a/include/cru/ui/controls/Button.hpp b/include/cru/ui/controls/Button.hpp index 0d2f4898..7299c146 100644 --- a/include/cru/ui/controls/Button.hpp +++ b/include/cru/ui/controls/Button.hpp @@ -2,11 +2,15 @@ #include "ContentControl.hpp" #include "../helper/ClickDetector.hpp" +#include "IBorderControl.hpp" #include "IClickableControl.hpp" #include "cru/common/Event.hpp" +#include "cru/ui/style/ApplyBorderStyleInfo.hpp" namespace cru::ui::controls { -class Button : public ContentControl, public virtual IClickableControl { +class Button : public ContentControl, + public virtual IClickableControl, + public virtual IBorderControl { public: static constexpr std::u16string_view control_type = u"Button"; @@ -35,6 +39,8 @@ class Button : public ContentControl, public virtual IClickableControl { return click_detector_.StateChangeEvent(); } + void ApplyBorderStyle(const style::ApplyBorderStyleInfo& style) override; + const ButtonStyle& GetStyle() const { return style_; } void SetStyle(ButtonStyle style); diff --git a/include/cru/ui/controls/IBorderControl.hpp b/include/cru/ui/controls/IBorderControl.hpp new file mode 100644 index 00000000..817305ef --- /dev/null +++ b/include/cru/ui/controls/IBorderControl.hpp @@ -0,0 +1,10 @@ +#pragma once +#include "../style/ApplyBorderStyleInfo.hpp" +#include "Base.hpp" +#include "cru/common/Base.hpp" + +namespace cru::ui::controls { +struct IBorderControl : virtual Interface { + virtual void ApplyBorderStyle(const style::ApplyBorderStyleInfo& style) = 0; +}; +} // namespace cru::ui::controls diff --git a/include/cru/ui/render/BorderRenderObject.hpp b/include/cru/ui/render/BorderRenderObject.hpp index f1b957cf..ec0bd52b 100644 --- a/include/cru/ui/render/BorderRenderObject.hpp +++ b/include/cru/ui/render/BorderRenderObject.hpp @@ -1,5 +1,7 @@ #pragma once +#include "../style/ApplyBorderStyleInfo.hpp" #include "RenderObject.hpp" +#include "cru/ui/Base.hpp" namespace cru::ui::render { class BorderRenderObject : public RenderObject { @@ -64,6 +66,8 @@ class BorderRenderObject : public RenderObject { void SetBorderStyle(const BorderStyle& style); + void ApplyBorderStyle(const style::ApplyBorderStyleInfo& style); + RenderObject* HitTest(const Point& point) override; protected: diff --git a/include/cru/ui/style/ApplyBorderStyleInfo.hpp b/include/cru/ui/style/ApplyBorderStyleInfo.hpp new file mode 100644 index 00000000..e9c4ca44 --- /dev/null +++ b/include/cru/ui/style/ApplyBorderStyleInfo.hpp @@ -0,0 +1,12 @@ +#pragma once +#include "../Base.hpp" + +namespace cru::ui::style { +struct ApplyBorderStyleInfo { + std::shared_ptr border_brush; + std::optional border_thickness; + std::optional border_radius; + std::shared_ptr foreground_brush; + std::shared_ptr background_brush; +}; +} // namespace cru::ui::style diff --git a/include/cru/ui/style/Condition.hpp b/include/cru/ui/style/Condition.hpp index b88a338f..97d29287 100644 --- a/include/cru/ui/style/Condition.hpp +++ b/include/cru/ui/style/Condition.hpp @@ -10,10 +10,8 @@ #include namespace cru::ui::style { -class Condition { +class Condition : public Object { public: - virtual ~Condition() = default; - virtual std::vector ChangeOn( controls::Control* control) const = 0; virtual bool Judge(controls::Control* control) const = 0; diff --git a/include/cru/ui/style/Styler.hpp b/include/cru/ui/style/Styler.hpp index e69de29b..0b48f1ce 100644 --- a/include/cru/ui/style/Styler.hpp +++ b/include/cru/ui/style/Styler.hpp @@ -0,0 +1,13 @@ +#pragma once +#include "../Base.hpp" +#include "cru/common/Base.hpp" + +#include + +namespace cru::ui::style { +class Styler : public Object { + public: + virtual void Apply(controls::Control* control) const; +}; + +} // namespace cru::ui::style -- cgit v1.2.3