diff options
author | crupest <crupest@outlook.com> | 2020-12-02 19:38:25 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-12-02 19:38:25 +0800 |
commit | d7dca1be0dd0814e30fa63924a20af3d924e974c (patch) | |
tree | 0a5ea0b637dc8392eee67ec625a51cef09ec8731 | |
parent | 145cfd5b82d76e0c937eceda707aa22427899943 (diff) | |
download | cru-d7dca1be0dd0814e30fa63924a20af3d924e974c.tar.gz cru-d7dca1be0dd0814e30fa63924a20af3d924e974c.tar.bz2 cru-d7dca1be0dd0814e30fa63924a20af3d924e974c.zip |
...
-rw-r--r-- | include/cru/ui/controls/Button.hpp | 8 | ||||
-rw-r--r-- | include/cru/ui/controls/IBorderControl.hpp | 10 | ||||
-rw-r--r-- | include/cru/ui/render/BorderRenderObject.hpp | 4 | ||||
-rw-r--r-- | include/cru/ui/style/ApplyBorderStyleInfo.hpp | 12 | ||||
-rw-r--r-- | include/cru/ui/style/Condition.hpp | 4 | ||||
-rw-r--r-- | include/cru/ui/style/Styler.hpp | 13 | ||||
-rw-r--r-- | src/ui/CMakeLists.txt | 5 | ||||
-rw-r--r-- | src/ui/controls/Button.cpp | 4 | ||||
-rw-r--r-- | src/ui/render/BorderRenderObject.cpp | 18 |
9 files changed, 71 insertions, 7 deletions
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<platform::graphics::IBrush> border_brush; + std::optional<Thickness> border_thickness; + std::optional<CornerRadius> border_radius; + std::shared_ptr<platform::graphics::IBrush> foreground_brush; + std::shared_ptr<platform::graphics::IBrush> 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 <vector> namespace cru::ui::style { -class Condition { +class Condition : public Object { public: - virtual ~Condition() = default; - virtual std::vector<IBaseEvent*> 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 <optional> + +namespace cru::ui::style { +class Styler : public Object { + public: + virtual void Apply(controls::Control* control) const; +}; + +} // namespace cru::ui::style diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt index 85c87f5e..03297988 100644 --- a/src/ui/CMakeLists.txt +++ b/src/ui/CMakeLists.txt @@ -35,6 +35,7 @@ add_library(cru_ui STATIC render/StackLayoutRenderObject.cpp render/TextRenderObject.cpp style/Condition.cpp + style/Styler.cpp ) target_sources(cru_ui PUBLIC ${CRU_UI_INCLUDE_DIR}/Base.hpp @@ -46,6 +47,8 @@ target_sources(cru_ui PUBLIC ${CRU_UI_INCLUDE_DIR}/controls/ContentControl.hpp ${CRU_UI_INCLUDE_DIR}/controls/Control.hpp ${CRU_UI_INCLUDE_DIR}/controls/FlexLayout.hpp + ${CRU_UI_INCLUDE_DIR}/controls/IBorderControl.hpp + ${CRU_UI_INCLUDE_DIR}/controls/IClickableControl.hpp ${CRU_UI_INCLUDE_DIR}/controls/LayoutControl.hpp ${CRU_UI_INCLUDE_DIR}/controls/NoChildControl.hpp ${CRU_UI_INCLUDE_DIR}/controls/Popup.hpp @@ -71,6 +74,8 @@ target_sources(cru_ui PUBLIC ${CRU_UI_INCLUDE_DIR}/render/ScrollRenderObject.hpp ${CRU_UI_INCLUDE_DIR}/render/StackLayoutRenderObject.hpp ${CRU_UI_INCLUDE_DIR}/render/TextRenderObject.hpp + ${CRU_UI_INCLUDE_DIR}/style/ApplyBorderStyleInfo.hpp ${CRU_UI_INCLUDE_DIR}/style/Condition.hpp + ${CRU_UI_INCLUDE_DIR}/style/Styler.hpp ) target_link_libraries(cru_ui PUBLIC cru_platform_gui) diff --git a/src/ui/controls/Button.cpp b/src/ui/controls/Button.cpp index 39c4b961..6f19e6b9 100644 --- a/src/ui/controls/Button.cpp +++ b/src/ui/controls/Button.cpp @@ -64,4 +64,8 @@ Button::~Button() = default; render::RenderObject* Button::GetRenderObject() const { return render_object_.get(); } + +void Button::ApplyBorderStyle(const style::ApplyBorderStyleInfo& style) { + render_object_->ApplyBorderStyle(style); +} } // namespace cru::ui::controls diff --git a/src/ui/render/BorderRenderObject.cpp b/src/ui/render/BorderRenderObject.cpp index 8e16d8cb..5abc7832 100644 --- a/src/ui/render/BorderRenderObject.cpp +++ b/src/ui/render/BorderRenderObject.cpp @@ -5,6 +5,7 @@ #include "cru/platform/graphics/Factory.hpp" #include "cru/platform/graphics/Geometry.hpp" #include "cru/platform/graphics/util/Painter.hpp" +#include "cru/ui/style/ApplyBorderStyleInfo.hpp" #include <algorithm> @@ -25,6 +26,16 @@ void BorderRenderObject::SetBorderStyle(const BorderStyle& style) { InvalidateLayout(); } +void BorderRenderObject::ApplyBorderStyle( + const style::ApplyBorderStyleInfo& style) { + if (style.border_brush != nullptr) border_brush_ = style.border_brush; + if (style.border_thickness) border_thickness_ = *style.border_thickness; + if (style.border_radius) border_radius_ = *style.border_radius; + if (style.foreground_brush) foreground_brush_ = style.foreground_brush; + if (style.background_brush) background_brush_ = style.background_brush; + InvalidateLayout(); +} + RenderObject* BorderRenderObject::HitTest(const Point& point) { if (const auto child = GetSingleChild()) { auto offset = child->GetOffset(); @@ -109,9 +120,10 @@ Size BorderRenderObject::OnMeasureCore(const MeasureRequirement& requirement, if (!requirement.max.height.IsNotSpecified()) { const auto max_height = requirement.max.height.GetLengthOrMax(); if (coerced_space_size.height > max_height) { - log::TagWarn(log_tag, - u"(Measure) Vertical length of padding, border and margin is " - u"bigger than required max length."); + log::TagWarn( + log_tag, + u"(Measure) Vertical length of padding, border and margin is " + u"bigger than required max length."); coerced_space_size.height = max_height; } content_requirement.max.height = max_height - coerced_space_size.height; |