aboutsummaryrefslogtreecommitdiff
path: root/src/ui/controls/border_delegate.h
diff options
context:
space:
mode:
authorYuqian Yang <crupest@outlook.com>2018-10-01 17:11:11 +0000
committerYuqian Yang <crupest@outlook.com>2018-10-01 17:11:11 +0000
commit30ecda8bb354d5982978af97aa90b5f49d9ea195 (patch)
treea271bddb244fa2041f14f8d46d249457cee09e5f /src/ui/controls/border_delegate.h
parent398b8f3ba535bb43c4b8593e3027c14894a7a211 (diff)
parent040a6c18f18100b825a56443a73aa1de64e4518c (diff)
downloadcru-30ecda8bb354d5982978af97aa90b5f49d9ea195.tar.gz
cru-30ecda8bb354d5982978af97aa90b5f49d9ea195.tar.bz2
cru-30ecda8bb354d5982978af97aa90b5f49d9ea195.zip
Merge branch '9-border' into 'master'
Resolve "Abstract out border control of button and border." Closes #9 See merge request crupest/CruUI!11
Diffstat (limited to 'src/ui/controls/border_delegate.h')
-rw-r--r--src/ui/controls/border_delegate.h101
1 files changed, 101 insertions, 0 deletions
diff --git a/src/ui/controls/border_delegate.h b/src/ui/controls/border_delegate.h
new file mode 100644
index 00000000..6d8663e9
--- /dev/null
+++ b/src/ui/controls/border_delegate.h
@@ -0,0 +1,101 @@
+#pragma once
+
+#include "ui/control.h"
+
+namespace cru::ui::controls
+{
+ class BorderProperty : public PropertyChangedNotifyObject
+ {
+ public:
+ using Ptr = std::shared_ptr<BorderProperty>;
+ static Ptr Create();
+
+ constexpr static auto brush_property_name = L"Brush";
+ constexpr static auto width_property_name = L"Width";
+ constexpr static auto stroke_style_property_name = L"StrokeStyle";
+ constexpr static auto radius_x_property_name = L"RadiusX";
+ constexpr static auto radius_y_property_name = L"RadiusY";
+
+ BorderProperty() = default;
+ explicit BorderProperty(Microsoft::WRL::ComPtr<ID2D1Brush> brush);
+ BorderProperty(const BorderProperty& other) = delete;
+ BorderProperty(BorderProperty&& other) = delete;
+ BorderProperty& operator=(const BorderProperty& other) = delete;
+ BorderProperty& operator=(BorderProperty&& other) = delete;
+ ~BorderProperty() override = default;
+
+
+ Microsoft::WRL::ComPtr<ID2D1Brush> GetBrush() const
+ {
+ return brush_;
+ }
+
+ float GetWidth() const
+ {
+ return width_;
+ }
+
+ Microsoft::WRL::ComPtr<ID2D1StrokeStyle> GetStrokeStyle() const
+ {
+ return stroke_style_;
+ }
+
+ float GetRadiusX() const
+ {
+ return radius_x_;
+ }
+
+ float GetRadiusY() const
+ {
+ return radius_y_;
+ }
+
+ void SetBrush(Microsoft::WRL::ComPtr<ID2D1Brush> brush);
+ void SetWidth(float width);
+ void SetStrokeStyle(Microsoft::WRL::ComPtr<ID2D1StrokeStyle> stroke_style);
+ void SetRadiusX(float radius_x);
+ void SetRadiusY(float radius_y);
+
+ private:
+ Microsoft::WRL::ComPtr<ID2D1Brush> brush_ = nullptr;
+ float width_ = 1.0f;
+ Microsoft::WRL::ComPtr<ID2D1StrokeStyle> stroke_style_ = nullptr;
+ float radius_x_ = 0.0f;
+ float radius_y_ = 0.0f;
+ };
+
+
+ // BorderDelegate is a delegate for border painting and layout.
+ // It must bind a control and not change the binding.
+ // But multiple BorderDelegate may share a common BorderProperty.
+ class BorderDelegate : public Object
+ {
+ public:
+ explicit BorderDelegate(Control* control);
+ BorderDelegate(Control* control, std::shared_ptr<BorderProperty> border_property);
+ BorderDelegate(const BorderDelegate& other) = delete;
+ BorderDelegate(BorderDelegate&& other) = delete;
+ BorderDelegate& operator=(const BorderDelegate& other) = delete;
+ BorderDelegate& operator=(BorderDelegate&& other) = delete;
+ ~BorderDelegate() override;
+
+ std::shared_ptr<BorderProperty> GetBorderProperty() const
+ {
+ return border_property_;
+ }
+
+ void SetBorderProperty(std::shared_ptr<BorderProperty> border_property);
+
+ void Draw(ID2D1DeviceContext* device_context, const Size& size) const;
+
+ Thickness GetBorderThickness() const
+ {
+ return Thickness(border_property_->GetWidth());
+ }
+
+ private:
+ Control* control_;
+ std::shared_ptr<BorderProperty> border_property_;
+ FunctionPtr<void(String)> border_property_changed_listener_;
+ };
+}